View | Details | Raw Unified | Return to bug 56160
Collapse All | Expand All

(-)src/core/org/apache/jmeter/control/IfController.java (-10 / +13 lines)
Lines 170-185 Link Here
170
                    evaluateCondition(getCondition());
170
                    evaluateCondition(getCondition());
171
        }
171
        }
172
172
173
        if (result) {
173
		if (result) {
174
            return super.next();
174
			return super.next();
175
        }
175
		} else if (!isFirst()) { // Bug 56160 - don't do reinitializing on the first "iteration" because we won't bother the items inside the if control
176
        // If-test is false, need to re-initialize indexes
176
			// If-test is false, need to re-initialize indexes
177
        try {
177
			try {
178
            reInitializeSubController(); // Bug 50032 - reinitialize current index element for all sub controller
178
				reInitializeSubController(); // Bug 50032 - reinitialize current index element for all sub controller
179
            return nextIsNull();
179
				return nextIsNull();
180
        } catch (NextIsNullException e1) {
180
			} catch (NextIsNullException e1) {
181
            return null;
181
				return null;
182
        }
182
			}
183
		} else {
184
			return null;
185
		}
183
    }
186
    }
184
    
187
    
185
    /**
188
    /**
(-)test/src/org/apache/jmeter/control/TestIfController.java (+80 lines)
Lines 173-176 Link Here
173
            }
173
            }
174
            assertEquals(counter, 6); 
174
            assertEquals(counter, 6); 
175
        }
175
        }
176
        
177
        /**
178
         * Test for Fix of Bug 56160 (Don't step into IfController children if condition is false)
179
         */
180
		public void testNotStepIntoOnFalse() {
181
	
182
			LoopController controller = new LoopController();
183
			controller.setLoops(2);
184
			IfController ifCont = new IfController("false==true");
185
			ifCont.setFirst(true);
186
			controller.addTestElement(ifCont);
187
	
188
			CountingController whileCont = new CountingController();
189
//			whileCont.setCondition("false");
190
			ifCont.addTestElement(whileCont);
191
	
192
			TestSampler sample = new TestSampler("Placeholder");
193
			whileCont.addTestElement(sample);
194
	
195
			controller.setRunningVersion(true);
196
			ifCont.setRunningVersion(true);
197
			whileCont.setRunningVersion(true);
198
	
199
			Sampler sampler = null;
200
			while ((sampler = controller.next()) != null) {
201
				System.out.println("sampler name" + sampler.getName());
202
			}
203
	
204
			assertEquals(
205
					"WhileController.next has been evaluated though it's contained in a IfController with condition that is false",
206
					0, whileCont.whileNextCalled);
207
		}
208
	
209
		/**
210
		 * Test that fix of Bug 56160 doesn't break existing code if condition is true
211
		 */
212
		public void testStepIntoOnTrue() {
213
	
214
			LoopController controller = new LoopController();
215
			controller.setLoops(2);
216
			IfController ifCont = new IfController("true==true");
217
			ifCont.setFirst(true);
218
			controller.addTestElement(ifCont);
219
	
220
			CountingController whileCont = new CountingController();
221
//			whileCont.setCondition("false");
222
			ifCont.addTestElement(whileCont);
223
	
224
			TestSampler sample = new TestSampler("Placeholder");
225
			whileCont.addTestElement(sample);
226
	
227
			controller.setRunningVersion(true);
228
			ifCont.setRunningVersion(true);
229
			whileCont.setRunningVersion(true);
230
	
231
			Sampler sampler = null;
232
			while ((sampler = controller.next()) != null) {
233
				System.out.println("sampler name" + sampler.getName());
234
			}
235
	
236
			assertTrue("WhileController hasn't been called for ",
237
					whileCont.whileNextCalled > 0);
238
		}
239
	
240
		/**
241
		 * WhileController impl to count the number of invocations of next()
242
		 */
243
		private class CountingController extends GenericController {
244
	
245
			/* generated */
246
			private static final long serialVersionUID = 2752049459477428418L;
247
	
248
			int whileNextCalled = 0;
249
	
250
			@Override
251
			public Sampler next() {
252
				whileNextCalled++;
253
				return super.next();
254
			}
255
		}
176
}
256
}

Return to bug 56160