You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2009/05/10 20:17:01 UTC

svn commit: r773380 [2/2] - in /jakarta/jmeter/trunk/test/src/org/apache/jmeter: assertions/ config/ config/gui/ control/

Modified: jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestSwitchController.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestSwitchController.java?rev=773380&r1=773379&r2=773380&view=diff
==============================================================================
--- jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestSwitchController.java (original)
+++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestSwitchController.java Sun May 10 18:17:01 2009
@@ -33,266 +33,266 @@
 import org.apache.jmeter.threads.JMeterVariables;
 
 public class TestSwitchController extends JMeterTestCase {
-//		static {
-//			 LoggingManager.setPriority("DEBUG","jmeter");
-//			 LoggingManager.setTarget(new java.io.PrintWriter(System.out));
-//		}
-
-		public TestSwitchController(String name) {
-			super(name);
-		}
-
-		// Get next sample and its name
-		private String nextName(GenericController c) {
-			Sampler s = c.next();
-			String n;
-			if (s == null) {
-				return null;
-			}
-			n = s.getName();
-			return n;
-		}
-
-		public void test() throws Exception {
-			runSimpleTests("", "zero");
-		}
-
-		public void test0() throws Exception {
-			runSimpleTests("0", "zero");
-		}
-
-		public void test1() throws Exception {
-			runSimpleTests("1", "one");
-			runSimpleTests("one", "one"); // Match by name
-		}
-
-		public void test2() throws Exception {
-			runSimpleTests("2", "two");
-			runSimpleTests("two", "two"); // Match by name
-		}
-
-		public void test3() throws Exception {
-			runSimpleTests("3", "three");
-			runSimpleTests("three", "three"); // Match by name
-		}
-
-		public void test4() throws Exception {
-			runSimpleTests("4", "zero");
-		}
-
-		public void testX() throws Exception {
-			runSimpleTests("X", null); // should not run any children
-			runSimpleTest2("X", "one", "Default"); // should match the default entry
-		}
-
-		private void runSimpleTests(String cond, String exp) throws Exception {
-			runSimpleTest(cond, exp);
-			runSimpleTest2(cond, exp, "one");
-		}
-
-		/*
-		 *  Simple test with single Selection controller
-		 *  Generic Controller
-		 *  + Sampler "before"
-		 *  + Switch Controller
-		 *  + + Sampler "zero"
-		 *  + + Sampler "one"
-		 *  + + Sampler "two"
-		 *  + + Sampler "three"
-		 *  + Sampler "after"
-		 */
-		private void runSimpleTest(String cond, String exp) throws Exception {
-			GenericController controller = new GenericController();
-
-			SwitchController switch_cont = new SwitchController();
-			switch_cont.setSelection(cond);
-
-			controller.addTestElement(new TestSampler("before"));
-			controller.addTestElement(switch_cont);
-
-			switch_cont.addTestElement(new TestSampler("zero"));
-			switch_cont.addTestElement(new TestSampler("one"));
-			switch_cont.addTestElement(new TestSampler("two"));
-			switch_cont.addTestElement(new TestSampler("three"));
-
-			controller.addTestElement(new TestSampler("after"));
-
-			controller.initialize();
-
-			for (int i = 1; i <= 3; i++) {
-				assertEquals("Loop " + i, "before", nextName(controller));
-				if (exp!=null){
-					assertEquals("Loop " + i, exp, nextName(controller));
-				}
-				assertEquals("Loop " + i, "after", nextName(controller));
-				assertNull(nextName(controller));
-			}
-		}
-
-		// Selection controller with two sub-controllers, but each has only 1
-		// child
-		/*
-		 * Controller
-		 * + Before
-		 * + Switch (cond)
-		 * + + zero
-		 * + + Controller sub_1
-		 * + + + one
-		 * + + two
-		 * + + Controller sub_2
-		 * + + + three
-		 * + After
-		 */
-		private void runSimpleTest2(String cond, String exp, String sub1Name) throws Exception {
-			GenericController controller = new GenericController();
-			GenericController sub_1 = new GenericController();
-			GenericController sub_2 = new GenericController();
-
-			SwitchController switch_cont = new SwitchController();
-			switch_cont.setSelection(cond);
-
-			switch_cont.addTestElement(new TestSampler("zero"));
-			switch_cont.addTestElement(sub_1);
-			sub_1.addTestElement(new TestSampler("one"));
-			sub_1.setName(sub1Name);
-
-			switch_cont.addTestElement(new TestSampler("two"));
-
-			switch_cont.addTestElement(sub_2);
-			sub_2.addTestElement(new TestSampler("three"));
-			sub_2.setName("three");
-
-			controller.addTestElement(new TestSampler("before"));
-			controller.addTestElement(switch_cont);
-			controller.addTestElement(new TestSampler("after"));
-			controller.initialize();
-			for (int i = 1; i <= 3; i++) {
-				assertEquals("Loop="+i,"before", nextName(controller));
-				if (exp!=null){
-					assertEquals("Loop="+i,exp, nextName(controller));
-				}
-				assertEquals("Loop="+i,"after", nextName(controller));
-				assertNull("Loop="+i,nextName(controller));
-			}
-		}
-
-		public void testTest2() throws Exception {
-			runTest2("", new String[] { "zero" });
-			runTest2("0", new String[] { "zero" });
-			runTest2("7", new String[] { "zero" });
-			runTest2("5", new String[] { "zero" });
-			runTest2("4", new String[] { "six" });
-			runTest2("3", new String[] { "five" });
-			runTest2("1", new String[] { "one", "two" });
-			runTest2("2", new String[] { "three", "four" });
-		}
-
-		/*
-		 * Test: 
-		 * Before 
-		 * Selection Controller
-		 *  - zero (default)
-		 *  - simple controller 1
-		 *  - - one
-		 *  - - two
-		 *  - simple controller 2
-		 *  - - three
-		 *  - - four
-		 *  - five
-		 *  - six
-		 * After
-		 * 
-		 * cond  = Switch condition 
-		 * exp[] = expected results
-		 */
-		private void runTest2(String cond, String exp[]) throws Exception {
-			int loops = 3;
-			LoopController controller = new LoopController();
-			controller.setLoops(loops);
-			controller.setContinueForever(false);
-			GenericController sub_1 = new GenericController();
-			GenericController sub_2 = new GenericController();
-
-			SwitchController switch_cont = new SwitchController();
-			switch_cont.setSelection(cond);
-
-			switch_cont.addTestElement(new TestSampler("zero"));
-			switch_cont.addTestElement(sub_1);
-			sub_1.addTestElement(new TestSampler("one"));
-			sub_1.addTestElement(new TestSampler("two"));
-
-			switch_cont.addTestElement(sub_2);
-			sub_2.addTestElement(new TestSampler("three"));
-			sub_2.addTestElement(new TestSampler("four"));
-
-			switch_cont.addTestElement(new TestSampler("five"));
-			switch_cont.addTestElement(new TestSampler("six"));
-
-			controller.addTestElement(new TestSampler("before"));
-			controller.addTestElement(switch_cont);
-			controller.addTestElement(new TestSampler("after"));
-			controller.setRunningVersion(true);
-			sub_1.setRunningVersion(true);
-			sub_2.setRunningVersion(true);
-			switch_cont.setRunningVersion(true);
-			controller.initialize();
-			for (int i = 1; i <= 3; i++) {
-				assertEquals("Loop:" + i, "before", nextName(controller));
-				for (int j = 0; j < exp.length; j++) {
-					assertEquals("Loop:" + i, exp[j], nextName(controller));
-				}
-				assertEquals("Loop:" + i, "after", nextName(controller));
-			}
-			assertNull("Loops:" + loops, nextName(controller));
-		}
-		
-		/*
-		 * N.B. Requires ApacheJMeter_functions.jar to be on the classpath,
-		 * otherwise the function cannot be resolved.
-		*/
-		public void testFunction() throws Exception {
-			JMeterContext jmctx = JMeterContextService.getContext();
-			Map variables = new HashMap();
-			ReplaceStringWithFunctions transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables);
-			jmctx.setVariables(new JMeterVariables());
-			JMeterVariables jmvars = jmctx.getVariables();
-			jmvars.put("VAR", "100");
-			StringProperty prop = new StringProperty(SwitchController.SWITCH_VALUE,"${__counter(TRUE,VAR)}");
-			JMeterProperty newProp = transformer.transformValue(prop);
-			newProp.setRunningVersion(true);
-			
-			GenericController controller = new GenericController();
-
-			SwitchController switch_cont = new SwitchController();
-			switch_cont.setProperty(newProp);
-
-			controller.addTestElement(new TestSampler("before"));
-			controller.addTestElement(switch_cont);
-
-			switch_cont.addTestElement(new TestSampler("0"));
-			switch_cont.addTestElement(new TestSampler("1"));
-			switch_cont.addTestElement(new TestSampler("2"));
-			switch_cont.addTestElement(new TestSampler("3"));
-
-			controller.addTestElement(new TestSampler("after"));
-
-			controller.initialize();
-
-			assertEquals("100",jmvars.get("VAR"));
-			
-			for (int i = 1; i <= 3; i++) {
-				assertEquals("Loop " + i, "before", nextName(controller));
-				assertEquals("Loop " + i, ""+i, nextName(controller));
-				assertEquals("Loop " + i, ""+i, jmvars.get("VAR"));
-				assertEquals("Loop " + i, "after", nextName(controller));
-				assertNull(nextName(controller));
-			}
-			int i = 4;
-			assertEquals("Loop " + i, "before", nextName(controller));
-			assertEquals("Loop " + i, "0", nextName(controller));
-			assertEquals("Loop " + i, ""+i, jmvars.get("VAR"));
-			assertEquals("Loop " + i, "after", nextName(controller));
-			assertNull(nextName(controller));
-			assertEquals("4",jmvars.get("VAR"));
-		}
+//      static {
+//           LoggingManager.setPriority("DEBUG","jmeter");
+//           LoggingManager.setTarget(new java.io.PrintWriter(System.out));
+//      }
+
+        public TestSwitchController(String name) {
+            super(name);
+        }
+
+        // Get next sample and its name
+        private String nextName(GenericController c) {
+            Sampler s = c.next();
+            String n;
+            if (s == null) {
+                return null;
+            }
+            n = s.getName();
+            return n;
+        }
+
+        public void test() throws Exception {
+            runSimpleTests("", "zero");
+        }
+
+        public void test0() throws Exception {
+            runSimpleTests("0", "zero");
+        }
+
+        public void test1() throws Exception {
+            runSimpleTests("1", "one");
+            runSimpleTests("one", "one"); // Match by name
+        }
+
+        public void test2() throws Exception {
+            runSimpleTests("2", "two");
+            runSimpleTests("two", "two"); // Match by name
+        }
+
+        public void test3() throws Exception {
+            runSimpleTests("3", "three");
+            runSimpleTests("three", "three"); // Match by name
+        }
+
+        public void test4() throws Exception {
+            runSimpleTests("4", "zero");
+        }
+
+        public void testX() throws Exception {
+            runSimpleTests("X", null); // should not run any children
+            runSimpleTest2("X", "one", "Default"); // should match the default entry
+        }
+
+        private void runSimpleTests(String cond, String exp) throws Exception {
+            runSimpleTest(cond, exp);
+            runSimpleTest2(cond, exp, "one");
+        }
+
+        /*
+         *  Simple test with single Selection controller
+         *  Generic Controller
+         *  + Sampler "before"
+         *  + Switch Controller
+         *  + + Sampler "zero"
+         *  + + Sampler "one"
+         *  + + Sampler "two"
+         *  + + Sampler "three"
+         *  + Sampler "after"
+         */
+        private void runSimpleTest(String cond, String exp) throws Exception {
+            GenericController controller = new GenericController();
+
+            SwitchController switch_cont = new SwitchController();
+            switch_cont.setSelection(cond);
+
+            controller.addTestElement(new TestSampler("before"));
+            controller.addTestElement(switch_cont);
+
+            switch_cont.addTestElement(new TestSampler("zero"));
+            switch_cont.addTestElement(new TestSampler("one"));
+            switch_cont.addTestElement(new TestSampler("two"));
+            switch_cont.addTestElement(new TestSampler("three"));
+
+            controller.addTestElement(new TestSampler("after"));
+
+            controller.initialize();
+
+            for (int i = 1; i <= 3; i++) {
+                assertEquals("Loop " + i, "before", nextName(controller));
+                if (exp!=null){
+                    assertEquals("Loop " + i, exp, nextName(controller));
+                }
+                assertEquals("Loop " + i, "after", nextName(controller));
+                assertNull(nextName(controller));
+            }
+        }
+
+        // Selection controller with two sub-controllers, but each has only 1
+        // child
+        /*
+         * Controller
+         * + Before
+         * + Switch (cond)
+         * + + zero
+         * + + Controller sub_1
+         * + + + one
+         * + + two
+         * + + Controller sub_2
+         * + + + three
+         * + After
+         */
+        private void runSimpleTest2(String cond, String exp, String sub1Name) throws Exception {
+            GenericController controller = new GenericController();
+            GenericController sub_1 = new GenericController();
+            GenericController sub_2 = new GenericController();
+
+            SwitchController switch_cont = new SwitchController();
+            switch_cont.setSelection(cond);
+
+            switch_cont.addTestElement(new TestSampler("zero"));
+            switch_cont.addTestElement(sub_1);
+            sub_1.addTestElement(new TestSampler("one"));
+            sub_1.setName(sub1Name);
+
+            switch_cont.addTestElement(new TestSampler("two"));
+
+            switch_cont.addTestElement(sub_2);
+            sub_2.addTestElement(new TestSampler("three"));
+            sub_2.setName("three");
+
+            controller.addTestElement(new TestSampler("before"));
+            controller.addTestElement(switch_cont);
+            controller.addTestElement(new TestSampler("after"));
+            controller.initialize();
+            for (int i = 1; i <= 3; i++) {
+                assertEquals("Loop="+i,"before", nextName(controller));
+                if (exp!=null){
+                    assertEquals("Loop="+i,exp, nextName(controller));
+                }
+                assertEquals("Loop="+i,"after", nextName(controller));
+                assertNull("Loop="+i,nextName(controller));
+            }
+        }
+
+        public void testTest2() throws Exception {
+            runTest2("", new String[] { "zero" });
+            runTest2("0", new String[] { "zero" });
+            runTest2("7", new String[] { "zero" });
+            runTest2("5", new String[] { "zero" });
+            runTest2("4", new String[] { "six" });
+            runTest2("3", new String[] { "five" });
+            runTest2("1", new String[] { "one", "two" });
+            runTest2("2", new String[] { "three", "four" });
+        }
+
+        /*
+         * Test: 
+         * Before 
+         * Selection Controller
+         *  - zero (default)
+         *  - simple controller 1
+         *  - - one
+         *  - - two
+         *  - simple controller 2
+         *  - - three
+         *  - - four
+         *  - five
+         *  - six
+         * After
+         * 
+         * cond  = Switch condition 
+         * exp[] = expected results
+         */
+        private void runTest2(String cond, String exp[]) throws Exception {
+            int loops = 3;
+            LoopController controller = new LoopController();
+            controller.setLoops(loops);
+            controller.setContinueForever(false);
+            GenericController sub_1 = new GenericController();
+            GenericController sub_2 = new GenericController();
+
+            SwitchController switch_cont = new SwitchController();
+            switch_cont.setSelection(cond);
+
+            switch_cont.addTestElement(new TestSampler("zero"));
+            switch_cont.addTestElement(sub_1);
+            sub_1.addTestElement(new TestSampler("one"));
+            sub_1.addTestElement(new TestSampler("two"));
+
+            switch_cont.addTestElement(sub_2);
+            sub_2.addTestElement(new TestSampler("three"));
+            sub_2.addTestElement(new TestSampler("four"));
+
+            switch_cont.addTestElement(new TestSampler("five"));
+            switch_cont.addTestElement(new TestSampler("six"));
+
+            controller.addTestElement(new TestSampler("before"));
+            controller.addTestElement(switch_cont);
+            controller.addTestElement(new TestSampler("after"));
+            controller.setRunningVersion(true);
+            sub_1.setRunningVersion(true);
+            sub_2.setRunningVersion(true);
+            switch_cont.setRunningVersion(true);
+            controller.initialize();
+            for (int i = 1; i <= 3; i++) {
+                assertEquals("Loop:" + i, "before", nextName(controller));
+                for (int j = 0; j < exp.length; j++) {
+                    assertEquals("Loop:" + i, exp[j], nextName(controller));
+                }
+                assertEquals("Loop:" + i, "after", nextName(controller));
+            }
+            assertNull("Loops:" + loops, nextName(controller));
+        }
+        
+        /*
+         * N.B. Requires ApacheJMeter_functions.jar to be on the classpath,
+         * otherwise the function cannot be resolved.
+        */
+        public void testFunction() throws Exception {
+            JMeterContext jmctx = JMeterContextService.getContext();
+            Map variables = new HashMap();
+            ReplaceStringWithFunctions transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables);
+            jmctx.setVariables(new JMeterVariables());
+            JMeterVariables jmvars = jmctx.getVariables();
+            jmvars.put("VAR", "100");
+            StringProperty prop = new StringProperty(SwitchController.SWITCH_VALUE,"${__counter(TRUE,VAR)}");
+            JMeterProperty newProp = transformer.transformValue(prop);
+            newProp.setRunningVersion(true);
+            
+            GenericController controller = new GenericController();
+
+            SwitchController switch_cont = new SwitchController();
+            switch_cont.setProperty(newProp);
+
+            controller.addTestElement(new TestSampler("before"));
+            controller.addTestElement(switch_cont);
+
+            switch_cont.addTestElement(new TestSampler("0"));
+            switch_cont.addTestElement(new TestSampler("1"));
+            switch_cont.addTestElement(new TestSampler("2"));
+            switch_cont.addTestElement(new TestSampler("3"));
+
+            controller.addTestElement(new TestSampler("after"));
+
+            controller.initialize();
+
+            assertEquals("100",jmvars.get("VAR"));
+            
+            for (int i = 1; i <= 3; i++) {
+                assertEquals("Loop " + i, "before", nextName(controller));
+                assertEquals("Loop " + i, ""+i, nextName(controller));
+                assertEquals("Loop " + i, ""+i, jmvars.get("VAR"));
+                assertEquals("Loop " + i, "after", nextName(controller));
+                assertNull(nextName(controller));
+            }
+            int i = 4;
+            assertEquals("Loop " + i, "before", nextName(controller));
+            assertEquals("Loop " + i, "0", nextName(controller));
+            assertEquals("Loop " + i, ""+i, jmvars.get("VAR"));
+            assertEquals("Loop " + i, "after", nextName(controller));
+            assertNull(nextName(controller));
+            assertEquals("4",jmvars.get("VAR"));
+        }
 }

Modified: jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestThroughputController.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestThroughputController.java?rev=773380&r1=773379&r2=773380&view=diff
==============================================================================
--- jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestThroughputController.java (original)
+++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestThroughputController.java Sun May 10 18:17:01 2009
@@ -30,187 +30,187 @@
  * 
  */
 public class TestThroughputController extends JMeterTestCase {
-		public TestThroughputController(String name) {
-			super(name);
-		}
-
-		public void testByNumber() throws Exception {
-			ThroughputController sub_1 = new ThroughputController();
-			sub_1.setStyle(ThroughputController.BYNUMBER);
-			sub_1.setMaxThroughput(2);
-			sub_1.addTestElement(new TestSampler("one"));
-			sub_1.addTestElement(new TestSampler("two"));
-
-			LoopController loop = new LoopController();
-			loop.setLoops(5);
-			loop.addTestElement(new TestSampler("zero"));
-			loop.addTestElement(sub_1);
-			loop.addIterationListener(sub_1);
-			loop.addTestElement(new TestSampler("three"));
-
-			LoopController test = new LoopController();
-			test.setLoops(2);
-			test.addTestElement(loop);
-
-			String[] order = new String[] { "zero", "one", "two", "three", "zero", "one", "two", "three", "zero",
-					"three", "zero", "three", "zero", "three", "zero", "three", "zero", "three", "zero", "three",
-					"zero", "three", "zero", "three", };
-			sub_1.testStarted();
-			test.setRunningVersion(true);
-			sub_1.setRunningVersion(true);
-			loop.setRunningVersion(true);
-			test.initialize();
-			for (int counter = 0; counter < order.length; counter++) {
-				TestElement sampler = test.next();
-				assertNotNull(sampler);
-				assertEquals("Counter: " + counter, order[counter], sampler.getName());
-			}
-			assertNull(test.next());
-			sub_1.testEnded();
-		}
-
-		public void testByNumberZero() throws Exception {
-			ThroughputController sub_1 = new ThroughputController();
-			sub_1.setStyle(ThroughputController.BYNUMBER);
-			sub_1.setMaxThroughput(0);
-			sub_1.addTestElement(new TestSampler("one"));
-			sub_1.addTestElement(new TestSampler("two"));
-
-			LoopController controller = new LoopController();
-			controller.setLoops(5);
-			controller.addTestElement(new TestSampler("zero"));
-			controller.addTestElement(sub_1);
-			controller.addIterationListener(sub_1);
-			controller.addTestElement(new TestSampler("three"));
-
-			String[] order = new String[] { "zero", "three", "zero", "three", "zero", "three", "zero", "three", "zero",
-					"three", };
-			int counter = 0;
-			controller.setRunningVersion(true);
-			sub_1.setRunningVersion(true);
-			sub_1.testStarted();
-			controller.initialize();
-			for (int i = 0; i < 3; i++) {
-				TestElement sampler = null;
-				while ((sampler = controller.next()) != null) {
-					assertEquals("Counter: " + counter + ", i: " + i, order[counter], sampler.getName());
-					counter++;
-				}
-				assertEquals(counter, order.length);
-				counter = 0;
-			}
-			sub_1.testEnded();
-		}
-
-		public void testByPercent33() throws Exception {
-			ThroughputController sub_1 = new ThroughputController();
-			sub_1.setStyle(ThroughputController.BYPERCENT);
-			sub_1.setPercentThroughput(33.33f);
-			sub_1.addTestElement(new TestSampler("one"));
-			sub_1.addTestElement(new TestSampler("two"));
-
-			LoopController controller = new LoopController();
-			controller.setLoops(6);
-			controller.addTestElement(new TestSampler("zero"));
-			controller.addTestElement(sub_1);
-			controller.addIterationListener(sub_1);
-			controller.addTestElement(new TestSampler("three"));
-			// Expected results established using the DDA
-			// algorithm (see
-			// http://www.siggraph.org/education/materials/HyperGraph/scanline/outprims/drawline.htm):
-			String[] order = new String[] { "zero", // 0/1 vs. 1/1 -> 0 is
-													// closer to 33.33
-					"three", "zero", // 0/2 vs. 1/2 -> 50.0 is closer to
-										// 33.33
-					"one", "two", "three", "zero", // 1/3 vs. 2/3 -> 33.33 is
-													// closer to 33.33
-					"three", "zero", // 1/4 vs. 2/4 -> 25.0 is closer to
-										// 33.33
-					"three", "zero", // 1/5 vs. 2/5 -> 40.0 is closer to
-										// 33.33
-					"one", "two", "three", "zero", // 2/6 vs. 3/6 -> 33.33 is
-													// closer to 33.33
-					"three",
-			// etc...
-			};
-			int counter = 0;
-			controller.setRunningVersion(true);
-			sub_1.setRunningVersion(true);
-			sub_1.testStarted();
-			controller.initialize();
-			for (int i = 0; i < 3; i++) {
-				TestElement sampler = null;
-				while ((sampler = controller.next()) != null) {
-					assertEquals("Counter: " + counter + ", i: " + i, order[counter], sampler.getName());
-					counter++;
-				}
-				assertEquals(counter, order.length);
-				counter = 0;
-			}
-			sub_1.testEnded();
-		}
-
-		public void testByPercentZero() throws Exception {
-			ThroughputController sub_1 = new ThroughputController();
-			sub_1.setStyle(ThroughputController.BYPERCENT);
-			sub_1.setPercentThroughput(0.0f);
-			sub_1.addTestElement(new TestSampler("one"));
-			sub_1.addTestElement(new TestSampler("two"));
-
-			LoopController controller = new LoopController();
-			controller.setLoops(150);
-			controller.addTestElement(new TestSampler("zero"));
-			controller.addTestElement(sub_1);
-			controller.addIterationListener(sub_1);
-			controller.addTestElement(new TestSampler("three"));
-
-			String[] order = new String[] { "zero", "three", };
-			int counter = 0;
-			controller.setRunningVersion(true);
-			sub_1.setRunningVersion(true);
-			sub_1.testStarted();
-			controller.initialize();
-			for (int i = 0; i < 3; i++) {
-				TestElement sampler = null;
-				while ((sampler = controller.next()) != null) {
-					assertEquals("Counter: " + counter + ", i: " + i, order[counter % order.length], sampler.getName());
-					counter++;
-				}
-				assertEquals(counter, 150 * order.length);
-				counter = 0;
-			}
-			sub_1.testEnded();
-		}
-
-		public void testByPercent100() throws Exception {
-			ThroughputController sub_1 = new ThroughputController();
-			sub_1.setStyle(ThroughputController.BYPERCENT);
-			sub_1.setPercentThroughput(100.0f);
-			sub_1.addTestElement(new TestSampler("one"));
-			sub_1.addTestElement(new TestSampler("two"));
-
-			LoopController controller = new LoopController();
-			controller.setLoops(150);
-			controller.addTestElement(new TestSampler("zero"));
-			controller.addTestElement(sub_1);
-			controller.addIterationListener(sub_1);
-			controller.addTestElement(new TestSampler("three"));
-
-			String[] order = new String[] { "zero", "one", "two", "three", };
-			int counter = 0;
-			controller.setRunningVersion(true);
-			sub_1.setRunningVersion(true);
-			sub_1.testStarted();
-			controller.initialize();
-			for (int i = 0; i < 3; i++) {
-				TestElement sampler = null;
-				while ((sampler = controller.next()) != null) {
-					assertEquals("Counter: " + counter + ", i: " + i, order[counter % order.length], sampler.getName());
-					counter++;
-				}
-				assertEquals(counter, 150 * order.length);
-				counter = 0;
-			}
-			sub_1.testEnded();
-		}
+        public TestThroughputController(String name) {
+            super(name);
+        }
+
+        public void testByNumber() throws Exception {
+            ThroughputController sub_1 = new ThroughputController();
+            sub_1.setStyle(ThroughputController.BYNUMBER);
+            sub_1.setMaxThroughput(2);
+            sub_1.addTestElement(new TestSampler("one"));
+            sub_1.addTestElement(new TestSampler("two"));
+
+            LoopController loop = new LoopController();
+            loop.setLoops(5);
+            loop.addTestElement(new TestSampler("zero"));
+            loop.addTestElement(sub_1);
+            loop.addIterationListener(sub_1);
+            loop.addTestElement(new TestSampler("three"));
+
+            LoopController test = new LoopController();
+            test.setLoops(2);
+            test.addTestElement(loop);
+
+            String[] order = new String[] { "zero", "one", "two", "three", "zero", "one", "two", "three", "zero",
+                    "three", "zero", "three", "zero", "three", "zero", "three", "zero", "three", "zero", "three",
+                    "zero", "three", "zero", "three", };
+            sub_1.testStarted();
+            test.setRunningVersion(true);
+            sub_1.setRunningVersion(true);
+            loop.setRunningVersion(true);
+            test.initialize();
+            for (int counter = 0; counter < order.length; counter++) {
+                TestElement sampler = test.next();
+                assertNotNull(sampler);
+                assertEquals("Counter: " + counter, order[counter], sampler.getName());
+            }
+            assertNull(test.next());
+            sub_1.testEnded();
+        }
+
+        public void testByNumberZero() throws Exception {
+            ThroughputController sub_1 = new ThroughputController();
+            sub_1.setStyle(ThroughputController.BYNUMBER);
+            sub_1.setMaxThroughput(0);
+            sub_1.addTestElement(new TestSampler("one"));
+            sub_1.addTestElement(new TestSampler("two"));
+
+            LoopController controller = new LoopController();
+            controller.setLoops(5);
+            controller.addTestElement(new TestSampler("zero"));
+            controller.addTestElement(sub_1);
+            controller.addIterationListener(sub_1);
+            controller.addTestElement(new TestSampler("three"));
+
+            String[] order = new String[] { "zero", "three", "zero", "three", "zero", "three", "zero", "three", "zero",
+                    "three", };
+            int counter = 0;
+            controller.setRunningVersion(true);
+            sub_1.setRunningVersion(true);
+            sub_1.testStarted();
+            controller.initialize();
+            for (int i = 0; i < 3; i++) {
+                TestElement sampler = null;
+                while ((sampler = controller.next()) != null) {
+                    assertEquals("Counter: " + counter + ", i: " + i, order[counter], sampler.getName());
+                    counter++;
+                }
+                assertEquals(counter, order.length);
+                counter = 0;
+            }
+            sub_1.testEnded();
+        }
+
+        public void testByPercent33() throws Exception {
+            ThroughputController sub_1 = new ThroughputController();
+            sub_1.setStyle(ThroughputController.BYPERCENT);
+            sub_1.setPercentThroughput(33.33f);
+            sub_1.addTestElement(new TestSampler("one"));
+            sub_1.addTestElement(new TestSampler("two"));
+
+            LoopController controller = new LoopController();
+            controller.setLoops(6);
+            controller.addTestElement(new TestSampler("zero"));
+            controller.addTestElement(sub_1);
+            controller.addIterationListener(sub_1);
+            controller.addTestElement(new TestSampler("three"));
+            // Expected results established using the DDA
+            // algorithm (see
+            // http://www.siggraph.org/education/materials/HyperGraph/scanline/outprims/drawline.htm):
+            String[] order = new String[] { "zero", // 0/1 vs. 1/1 -> 0 is
+                                                    // closer to 33.33
+                    "three", "zero", // 0/2 vs. 1/2 -> 50.0 is closer to
+                                        // 33.33
+                    "one", "two", "three", "zero", // 1/3 vs. 2/3 -> 33.33 is
+                                                    // closer to 33.33
+                    "three", "zero", // 1/4 vs. 2/4 -> 25.0 is closer to
+                                        // 33.33
+                    "three", "zero", // 1/5 vs. 2/5 -> 40.0 is closer to
+                                        // 33.33
+                    "one", "two", "three", "zero", // 2/6 vs. 3/6 -> 33.33 is
+                                                    // closer to 33.33
+                    "three",
+            // etc...
+            };
+            int counter = 0;
+            controller.setRunningVersion(true);
+            sub_1.setRunningVersion(true);
+            sub_1.testStarted();
+            controller.initialize();
+            for (int i = 0; i < 3; i++) {
+                TestElement sampler = null;
+                while ((sampler = controller.next()) != null) {
+                    assertEquals("Counter: " + counter + ", i: " + i, order[counter], sampler.getName());
+                    counter++;
+                }
+                assertEquals(counter, order.length);
+                counter = 0;
+            }
+            sub_1.testEnded();
+        }
+
+        public void testByPercentZero() throws Exception {
+            ThroughputController sub_1 = new ThroughputController();
+            sub_1.setStyle(ThroughputController.BYPERCENT);
+            sub_1.setPercentThroughput(0.0f);
+            sub_1.addTestElement(new TestSampler("one"));
+            sub_1.addTestElement(new TestSampler("two"));
+
+            LoopController controller = new LoopController();
+            controller.setLoops(150);
+            controller.addTestElement(new TestSampler("zero"));
+            controller.addTestElement(sub_1);
+            controller.addIterationListener(sub_1);
+            controller.addTestElement(new TestSampler("three"));
+
+            String[] order = new String[] { "zero", "three", };
+            int counter = 0;
+            controller.setRunningVersion(true);
+            sub_1.setRunningVersion(true);
+            sub_1.testStarted();
+            controller.initialize();
+            for (int i = 0; i < 3; i++) {
+                TestElement sampler = null;
+                while ((sampler = controller.next()) != null) {
+                    assertEquals("Counter: " + counter + ", i: " + i, order[counter % order.length], sampler.getName());
+                    counter++;
+                }
+                assertEquals(counter, 150 * order.length);
+                counter = 0;
+            }
+            sub_1.testEnded();
+        }
+
+        public void testByPercent100() throws Exception {
+            ThroughputController sub_1 = new ThroughputController();
+            sub_1.setStyle(ThroughputController.BYPERCENT);
+            sub_1.setPercentThroughput(100.0f);
+            sub_1.addTestElement(new TestSampler("one"));
+            sub_1.addTestElement(new TestSampler("two"));
+
+            LoopController controller = new LoopController();
+            controller.setLoops(150);
+            controller.addTestElement(new TestSampler("zero"));
+            controller.addTestElement(sub_1);
+            controller.addIterationListener(sub_1);
+            controller.addTestElement(new TestSampler("three"));
+
+            String[] order = new String[] { "zero", "one", "two", "three", };
+            int counter = 0;
+            controller.setRunningVersion(true);
+            sub_1.setRunningVersion(true);
+            sub_1.testStarted();
+            controller.initialize();
+            for (int i = 0; i < 3; i++) {
+                TestElement sampler = null;
+                while ((sampler = controller.next()) != null) {
+                    assertEquals("Counter: " + counter + ", i: " + i, order[counter % order.length], sampler.getName());
+                    counter++;
+                }
+                assertEquals(counter, 150 * order.length);
+                counter = 0;
+            }
+            sub_1.testEnded();
+        }
 }

Modified: jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestWhileController.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestWhileController.java?rev=773380&r1=773379&r2=773380&view=diff
==============================================================================
--- jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestWhileController.java (original)
+++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestWhileController.java Sun May 10 18:17:01 2009
@@ -30,335 +30,335 @@
 import org.apache.jmeter.threads.JMeterVariables;
 
 public class TestWhileController extends JMeterTestCase {
-//		static {
-//			 LoggingManager.setPriority("DEBUG","jmeter");
-//			 LoggingManager.setTarget(new java.io.PrintWriter(System.out));
-//		}
-
-		public TestWhileController(String name) {
-			super(name);
-		}
-
-		private JMeterContext jmctx;
-		private JMeterVariables jmvars;
-		
-		public void setUp() {
-			jmctx = JMeterContextService.getContext();
-			jmctx.setVariables(new JMeterVariables());
-			jmvars = jmctx.getVariables();
-		}
-
-		private void setLastSampleStatus(boolean status){
-			jmvars.put(JMeterThread.LAST_SAMPLE_OK,Boolean.toString(status));
-		}
-
-		private void setRunning(TestElement el){
-			PropertyIterator pi = el.propertyIterator();
-			while(pi.hasNext()){
-				pi.next().setRunningVersion(true);
-			}
-		}
-
-		// Get next sample and its name
-		private String nextName(GenericController c) {
-			Sampler s = c.next();
-			if (s == null) {
-				return null;
-			}
-			return s.getName();
-		}
-
-		// While (blank), previous sample OK - should loop until false
-		public void testBlankPrevOK() throws Exception {
-//			log.info("testBlankPrevOK");
-			runtestPrevOK("");
-		}
-
-		// While (LAST), previous sample OK - should loop until false
-		public void testLastPrevOK() throws Exception {
-//			log.info("testLASTPrevOK");
-			runtestPrevOK("LAST");
-		}
-
-		private static final String OTHER = "X"; // Dummy for testing functions
-
-		// While (LAST), previous sample OK - should loop until false
-		public void testOtherPrevOK() throws Exception {
-//			log.info("testOtherPrevOK");
-			runtestPrevOK(OTHER);
-		}
-
-		private void runtestPrevOK(String type) throws Exception {
-			GenericController controller = new GenericController();
-			WhileController while_cont = new WhileController();
-			setLastSampleStatus(true);
-			while_cont.setCondition(type);
-			while_cont.addTestElement(new TestSampler("one"));
-			while_cont.addTestElement(new TestSampler("two"));
-			while_cont.addTestElement(new TestSampler("three"));
-			controller.addTestElement(while_cont);
-			controller.addTestElement(new TestSampler("four"));
-			controller.initialize();
-			assertEquals("one", nextName(controller));
-			assertEquals("two", nextName(controller));
-			assertEquals("three", nextName(controller));
-			assertEquals("one", nextName(controller));
-			assertEquals("two", nextName(controller));
-			assertEquals("three", nextName(controller));
-			assertEquals("one", nextName(controller));
-			setLastSampleStatus(false);
-			if (type.equals(OTHER)){
-				while_cont.setCondition("false");
-			}
-			assertEquals("two", nextName(controller));
-			assertEquals("three", nextName(controller));
-			setLastSampleStatus(true);
-			if (type.equals(OTHER)) {
-				while_cont.setCondition(OTHER);
-			}
-			assertEquals("one", nextName(controller));
-			assertEquals("two", nextName(controller));
-			assertEquals("three", nextName(controller));
-			setLastSampleStatus(false);
-			if (type.equals(OTHER)) {
-				while_cont.setCondition("false");
-			}
-			assertEquals("four", nextName(controller));
-			assertNull(nextName(controller));
-			setLastSampleStatus(true);
-			if (type.equals(OTHER)) {
-				while_cont.setCondition(OTHER);
-			}
-			assertEquals("one", nextName(controller));
-		}
-
-		// While (blank), previous sample failed - should run once
-		public void testBlankPrevFailed() throws Exception {
-//			log.info("testBlankPrevFailed");
-			GenericController controller = new GenericController();
-			controller.setRunningVersion(true);
-			WhileController while_cont = new WhileController();
-			setLastSampleStatus(false);
-			while_cont.setCondition("");
-			while_cont.addTestElement(new TestSampler("one"));
-			while_cont.addTestElement(new TestSampler("two"));
-			controller.addTestElement(while_cont);
-			controller.addTestElement(new TestSampler("three"));
-			controller.initialize();
-			assertEquals("one", nextName(controller));
-			assertEquals("two", nextName(controller));
-			assertEquals("three", nextName(controller));
-			assertNull(nextName(controller));
-			// Run entire test again
-			assertEquals("one", nextName(controller));
-			assertEquals("two", nextName(controller));
-			assertEquals("three", nextName(controller));
-			assertNull(nextName(controller));
-		}
-
-		/*
-		 * Generic Controller
-		 * - before
-		 * - While Controller ${VAR}
-		 * - - one
-		 * - - two
-		 * - - Simple Controller
-		 * - - - three
-		 * - - - four
-		 * - after
-		 */
-		public void testVariable1() throws Exception {
-			GenericController controller = new GenericController();
-			WhileController while_cont = new WhileController();
-			setLastSampleStatus(false);
-			while_cont.setCondition("${VAR}");
-			jmvars.put("VAR", "");
-			ValueReplacer vr = new ValueReplacer();
-			vr.replaceValues(while_cont);
-			setRunning(while_cont);
-			controller.addTestElement(new TestSampler("before"));
-			controller.addTestElement(while_cont);
-			while_cont.addTestElement(new TestSampler("one"));
-			while_cont.addTestElement(new TestSampler("two"));
-			GenericController simple = new GenericController();
-			while_cont.addTestElement(simple);
-			simple.addTestElement(new TestSampler("three"));
-			simple.addTestElement(new TestSampler("four"));
-			controller.addTestElement(new TestSampler("after"));
-			controller.initialize();
-			for (int i = 1; i <= 3; i++) {
-				assertEquals("Loop: "+i,"before", nextName(controller));
-				assertEquals("Loop: "+i,"one", nextName(controller));
-				assertEquals("Loop: "+i,"two", nextName(controller));
-				assertEquals("Loop: "+i,"three", nextName(controller));
-				assertEquals("Loop: "+i,"four", nextName(controller));
-				assertEquals("Loop: "+i,"after", nextName(controller));
-				assertNull("Loop: "+i,nextName(controller));
-			}
-			jmvars.put("VAR", "LAST"); // Should not enter the loop
-			for (int i = 1; i <= 3; i++) {
-				assertEquals("Loop: "+i,"before", nextName(controller));
-				assertEquals("Loop: "+i,"after", nextName(controller));
-				assertNull("Loop: "+i,nextName(controller));
-			}
-			jmvars.put("VAR", "");
-			for (int i = 1; i <= 3; i++) {
-				assertEquals("Loop: "+i,"before", nextName(controller));
-				if (i==1) {
-					assertEquals("Loop: "+i,"one", nextName(controller));
-					assertEquals("Loop: "+i,"two", nextName(controller));
-					assertEquals("Loop: "+i,"three", nextName(controller));
-					jmvars.put("VAR", "LAST"); // Should not enter the loop next time
-					assertEquals("Loop: "+i,"four", nextName(controller));
-				}
-				assertEquals("Loop: "+i,"after", nextName(controller));
-				assertNull("Loop: "+i,nextName(controller));
-			}
-		}
-
-		// Test with SimpleController as first item
-		public void testVariable2() throws Exception {
-			GenericController controller = new GenericController();
-			WhileController while_cont = new WhileController();
-			setLastSampleStatus(false);
-			while_cont.setCondition("${VAR}");
-			jmvars.put("VAR", "");
-			ValueReplacer vr = new ValueReplacer();
-			vr.replaceValues(while_cont);
-			setRunning(while_cont);
-			controller.addTestElement(new TestSampler("before"));
-			controller.addTestElement(while_cont);
-			GenericController simple = new GenericController();
-			while_cont.addTestElement(simple);
-			simple.addTestElement(new TestSampler("one"));
-			simple.addTestElement(new TestSampler("two"));
-			while_cont.addTestElement(new TestSampler("three"));
-			while_cont.addTestElement(new TestSampler("four"));
-			controller.addTestElement(new TestSampler("after"));
-			controller.initialize();
-			for (int i = 1; i <= 3; i++) {
-				assertEquals("Loop: "+i,"before", nextName(controller));
-				assertEquals("Loop: "+i,"one", nextName(controller));
-				assertEquals("Loop: "+i,"two", nextName(controller));
-				assertEquals("Loop: "+i,"three", nextName(controller));
-				assertEquals("Loop: "+i,"four", nextName(controller));
-				assertEquals("Loop: "+i,"after", nextName(controller));
-				assertNull("Loop: "+i,nextName(controller));
-			}
-			jmvars.put("VAR", "LAST"); // Should not enter the loop
-			for (int i = 1; i <= 3; i++) {
-				assertEquals("Loop: "+i,"before", nextName(controller));
-				assertEquals("Loop: "+i,"after", nextName(controller));
-				assertNull("Loop: "+i,nextName(controller));
-			}
-			jmvars.put("VAR", "");
-			for (int i = 1; i <= 3; i++) {
-				assertEquals("Loop: "+i,"before", nextName(controller));
-				if (i==1){
-					assertEquals("Loop: "+i,"one", nextName(controller));
-					assertEquals("Loop: "+i,"two", nextName(controller));
-					jmvars.put("VAR", "LAST"); // Should not enter the loop next time
-					// But should continue to the end of the loop
-					assertEquals("Loop: "+i,"three", nextName(controller));
-					assertEquals("Loop: "+i,"four", nextName(controller));
-				}
-				assertEquals("Loop: "+i,"after", nextName(controller));
-				assertNull("Loop: "+i,nextName(controller));
-			}
-		}
-
-		// While LAST, previous sample failed - should not run
-		public void testLASTPrevFailed() throws Exception {
-//			log.info("testLastPrevFailed");
-			runTestPrevFailed("LAST");
-		}
-
-		// While False, previous sample failed - should not run
-		public void testfalsePrevFailed() throws Exception {
-//			log.info("testFalsePrevFailed");
-			runTestPrevFailed("False");
-		}
-
-		private void runTestPrevFailed(String s) throws Exception {
-			GenericController controller = new GenericController();
-			WhileController while_cont = new WhileController();
-			setLastSampleStatus(false);
-			while_cont.setCondition(s);
-			while_cont.addTestElement(new TestSampler("one"));
-			while_cont.addTestElement(new TestSampler("two"));
-			controller.addTestElement(while_cont);
-			controller.addTestElement(new TestSampler("three"));
-			controller.initialize();
-			assertEquals("three", nextName(controller));
-			assertNull(nextName(controller));
-			assertEquals("three", nextName(controller));
-			assertNull(nextName(controller));
-		}
-
-		public void testLastFailedBlank() throws Exception{
-			runTestLastFailed("");
-		}
-
-		public void testLastFailedLast() throws Exception{
-			runTestLastFailed("LAST");
-		}
-
-		// Should behave the same for blank and LAST because success on input
-		private void runTestLastFailed(String s) throws Exception {
-			GenericController controller = new GenericController();
-			controller.addTestElement(new TestSampler("1"));
-			WhileController while_cont = new WhileController();
-			controller.addTestElement(while_cont);
-			while_cont.setCondition(s);
-			GenericController sub = new GenericController();
-			while_cont.addTestElement(sub);
-			sub.addTestElement(new TestSampler("2"));
-			sub.addTestElement(new TestSampler("3"));
-			
-			controller.addTestElement(new TestSampler("4"));
-
-			setLastSampleStatus(true);
-			controller.initialize();
-			assertEquals("1", nextName(controller));
-			assertEquals("2", nextName(controller));
-			setLastSampleStatus(false);
-			assertEquals("3", nextName(controller));
-			assertEquals("4", nextName(controller));
-			assertNull(nextName(controller));
-		}
-
-		// Tests for Stack Overflow (bug 33954)
-		public void testAlwaysFailOK() throws Exception {
-			runTestAlwaysFail(true); // Should be OK
-		}
-
-		public void testAlwaysFailBAD() throws Exception {
-			runTestAlwaysFail(false);
-		}
-
-		private void runTestAlwaysFail(boolean other) {
-			LoopController controller = new LoopController();
-			controller.setContinueForever(true);
-			controller.setLoops(-1);
-			WhileController while_cont = new WhileController();
-			setLastSampleStatus(false);
-			while_cont.setCondition("false");
-			while_cont.addTestElement(new TestSampler("one"));
-			while_cont.addTestElement(new TestSampler("two"));
-			controller.addTestElement(while_cont);
-			if (other) {
-				controller.addTestElement(new TestSampler("three"));
-			}
-			controller.initialize();
-			try {
-				if (other) {
-					assertEquals("three", nextName(controller));
-				} else {
-					assertNull(nextName(controller));
-				}
-			} catch (StackOverflowError e) {
-				// e.printStackTrace();
-				fail(e.toString());
-			}
-		}
+//      static {
+//           LoggingManager.setPriority("DEBUG","jmeter");
+//           LoggingManager.setTarget(new java.io.PrintWriter(System.out));
+//      }
+
+        public TestWhileController(String name) {
+            super(name);
+        }
+
+        private JMeterContext jmctx;
+        private JMeterVariables jmvars;
+        
+        public void setUp() {
+            jmctx = JMeterContextService.getContext();
+            jmctx.setVariables(new JMeterVariables());
+            jmvars = jmctx.getVariables();
+        }
+
+        private void setLastSampleStatus(boolean status){
+            jmvars.put(JMeterThread.LAST_SAMPLE_OK,Boolean.toString(status));
+        }
+
+        private void setRunning(TestElement el){
+            PropertyIterator pi = el.propertyIterator();
+            while(pi.hasNext()){
+                pi.next().setRunningVersion(true);
+            }
+        }
+
+        // Get next sample and its name
+        private String nextName(GenericController c) {
+            Sampler s = c.next();
+            if (s == null) {
+                return null;
+            }
+            return s.getName();
+        }
+
+        // While (blank), previous sample OK - should loop until false
+        public void testBlankPrevOK() throws Exception {
+//          log.info("testBlankPrevOK");
+            runtestPrevOK("");
+        }
+
+        // While (LAST), previous sample OK - should loop until false
+        public void testLastPrevOK() throws Exception {
+//          log.info("testLASTPrevOK");
+            runtestPrevOK("LAST");
+        }
+
+        private static final String OTHER = "X"; // Dummy for testing functions
+
+        // While (LAST), previous sample OK - should loop until false
+        public void testOtherPrevOK() throws Exception {
+//          log.info("testOtherPrevOK");
+            runtestPrevOK(OTHER);
+        }
+
+        private void runtestPrevOK(String type) throws Exception {
+            GenericController controller = new GenericController();
+            WhileController while_cont = new WhileController();
+            setLastSampleStatus(true);
+            while_cont.setCondition(type);
+            while_cont.addTestElement(new TestSampler("one"));
+            while_cont.addTestElement(new TestSampler("two"));
+            while_cont.addTestElement(new TestSampler("three"));
+            controller.addTestElement(while_cont);
+            controller.addTestElement(new TestSampler("four"));
+            controller.initialize();
+            assertEquals("one", nextName(controller));
+            assertEquals("two", nextName(controller));
+            assertEquals("three", nextName(controller));
+            assertEquals("one", nextName(controller));
+            assertEquals("two", nextName(controller));
+            assertEquals("three", nextName(controller));
+            assertEquals("one", nextName(controller));
+            setLastSampleStatus(false);
+            if (type.equals(OTHER)){
+                while_cont.setCondition("false");
+            }
+            assertEquals("two", nextName(controller));
+            assertEquals("three", nextName(controller));
+            setLastSampleStatus(true);
+            if (type.equals(OTHER)) {
+                while_cont.setCondition(OTHER);
+            }
+            assertEquals("one", nextName(controller));
+            assertEquals("two", nextName(controller));
+            assertEquals("three", nextName(controller));
+            setLastSampleStatus(false);
+            if (type.equals(OTHER)) {
+                while_cont.setCondition("false");
+            }
+            assertEquals("four", nextName(controller));
+            assertNull(nextName(controller));
+            setLastSampleStatus(true);
+            if (type.equals(OTHER)) {
+                while_cont.setCondition(OTHER);
+            }
+            assertEquals("one", nextName(controller));
+        }
+
+        // While (blank), previous sample failed - should run once
+        public void testBlankPrevFailed() throws Exception {
+//          log.info("testBlankPrevFailed");
+            GenericController controller = new GenericController();
+            controller.setRunningVersion(true);
+            WhileController while_cont = new WhileController();
+            setLastSampleStatus(false);
+            while_cont.setCondition("");
+            while_cont.addTestElement(new TestSampler("one"));
+            while_cont.addTestElement(new TestSampler("two"));
+            controller.addTestElement(while_cont);
+            controller.addTestElement(new TestSampler("three"));
+            controller.initialize();
+            assertEquals("one", nextName(controller));
+            assertEquals("two", nextName(controller));
+            assertEquals("three", nextName(controller));
+            assertNull(nextName(controller));
+            // Run entire test again
+            assertEquals("one", nextName(controller));
+            assertEquals("two", nextName(controller));
+            assertEquals("three", nextName(controller));
+            assertNull(nextName(controller));
+        }
+
+        /*
+         * Generic Controller
+         * - before
+         * - While Controller ${VAR}
+         * - - one
+         * - - two
+         * - - Simple Controller
+         * - - - three
+         * - - - four
+         * - after
+         */
+        public void testVariable1() throws Exception {
+            GenericController controller = new GenericController();
+            WhileController while_cont = new WhileController();
+            setLastSampleStatus(false);
+            while_cont.setCondition("${VAR}");
+            jmvars.put("VAR", "");
+            ValueReplacer vr = new ValueReplacer();
+            vr.replaceValues(while_cont);
+            setRunning(while_cont);
+            controller.addTestElement(new TestSampler("before"));
+            controller.addTestElement(while_cont);
+            while_cont.addTestElement(new TestSampler("one"));
+            while_cont.addTestElement(new TestSampler("two"));
+            GenericController simple = new GenericController();
+            while_cont.addTestElement(simple);
+            simple.addTestElement(new TestSampler("three"));
+            simple.addTestElement(new TestSampler("four"));
+            controller.addTestElement(new TestSampler("after"));
+            controller.initialize();
+            for (int i = 1; i <= 3; i++) {
+                assertEquals("Loop: "+i,"before", nextName(controller));
+                assertEquals("Loop: "+i,"one", nextName(controller));
+                assertEquals("Loop: "+i,"two", nextName(controller));
+                assertEquals("Loop: "+i,"three", nextName(controller));
+                assertEquals("Loop: "+i,"four", nextName(controller));
+                assertEquals("Loop: "+i,"after", nextName(controller));
+                assertNull("Loop: "+i,nextName(controller));
+            }
+            jmvars.put("VAR", "LAST"); // Should not enter the loop
+            for (int i = 1; i <= 3; i++) {
+                assertEquals("Loop: "+i,"before", nextName(controller));
+                assertEquals("Loop: "+i,"after", nextName(controller));
+                assertNull("Loop: "+i,nextName(controller));
+            }
+            jmvars.put("VAR", "");
+            for (int i = 1; i <= 3; i++) {
+                assertEquals("Loop: "+i,"before", nextName(controller));
+                if (i==1) {
+                    assertEquals("Loop: "+i,"one", nextName(controller));
+                    assertEquals("Loop: "+i,"two", nextName(controller));
+                    assertEquals("Loop: "+i,"three", nextName(controller));
+                    jmvars.put("VAR", "LAST"); // Should not enter the loop next time
+                    assertEquals("Loop: "+i,"four", nextName(controller));
+                }
+                assertEquals("Loop: "+i,"after", nextName(controller));
+                assertNull("Loop: "+i,nextName(controller));
+            }
+        }
+
+        // Test with SimpleController as first item
+        public void testVariable2() throws Exception {
+            GenericController controller = new GenericController();
+            WhileController while_cont = new WhileController();
+            setLastSampleStatus(false);
+            while_cont.setCondition("${VAR}");
+            jmvars.put("VAR", "");
+            ValueReplacer vr = new ValueReplacer();
+            vr.replaceValues(while_cont);
+            setRunning(while_cont);
+            controller.addTestElement(new TestSampler("before"));
+            controller.addTestElement(while_cont);
+            GenericController simple = new GenericController();
+            while_cont.addTestElement(simple);
+            simple.addTestElement(new TestSampler("one"));
+            simple.addTestElement(new TestSampler("two"));
+            while_cont.addTestElement(new TestSampler("three"));
+            while_cont.addTestElement(new TestSampler("four"));
+            controller.addTestElement(new TestSampler("after"));
+            controller.initialize();
+            for (int i = 1; i <= 3; i++) {
+                assertEquals("Loop: "+i,"before", nextName(controller));
+                assertEquals("Loop: "+i,"one", nextName(controller));
+                assertEquals("Loop: "+i,"two", nextName(controller));
+                assertEquals("Loop: "+i,"three", nextName(controller));
+                assertEquals("Loop: "+i,"four", nextName(controller));
+                assertEquals("Loop: "+i,"after", nextName(controller));
+                assertNull("Loop: "+i,nextName(controller));
+            }
+            jmvars.put("VAR", "LAST"); // Should not enter the loop
+            for (int i = 1; i <= 3; i++) {
+                assertEquals("Loop: "+i,"before", nextName(controller));
+                assertEquals("Loop: "+i,"after", nextName(controller));
+                assertNull("Loop: "+i,nextName(controller));
+            }
+            jmvars.put("VAR", "");
+            for (int i = 1; i <= 3; i++) {
+                assertEquals("Loop: "+i,"before", nextName(controller));
+                if (i==1){
+                    assertEquals("Loop: "+i,"one", nextName(controller));
+                    assertEquals("Loop: "+i,"two", nextName(controller));
+                    jmvars.put("VAR", "LAST"); // Should not enter the loop next time
+                    // But should continue to the end of the loop
+                    assertEquals("Loop: "+i,"three", nextName(controller));
+                    assertEquals("Loop: "+i,"four", nextName(controller));
+                }
+                assertEquals("Loop: "+i,"after", nextName(controller));
+                assertNull("Loop: "+i,nextName(controller));
+            }
+        }
+
+        // While LAST, previous sample failed - should not run
+        public void testLASTPrevFailed() throws Exception {
+//          log.info("testLastPrevFailed");
+            runTestPrevFailed("LAST");
+        }
+
+        // While False, previous sample failed - should not run
+        public void testfalsePrevFailed() throws Exception {
+//          log.info("testFalsePrevFailed");
+            runTestPrevFailed("False");
+        }
+
+        private void runTestPrevFailed(String s) throws Exception {
+            GenericController controller = new GenericController();
+            WhileController while_cont = new WhileController();
+            setLastSampleStatus(false);
+            while_cont.setCondition(s);
+            while_cont.addTestElement(new TestSampler("one"));
+            while_cont.addTestElement(new TestSampler("two"));
+            controller.addTestElement(while_cont);
+            controller.addTestElement(new TestSampler("three"));
+            controller.initialize();
+            assertEquals("three", nextName(controller));
+            assertNull(nextName(controller));
+            assertEquals("three", nextName(controller));
+            assertNull(nextName(controller));
+        }
+
+        public void testLastFailedBlank() throws Exception{
+            runTestLastFailed("");
+        }
+
+        public void testLastFailedLast() throws Exception{
+            runTestLastFailed("LAST");
+        }
+
+        // Should behave the same for blank and LAST because success on input
+        private void runTestLastFailed(String s) throws Exception {
+            GenericController controller = new GenericController();
+            controller.addTestElement(new TestSampler("1"));
+            WhileController while_cont = new WhileController();
+            controller.addTestElement(while_cont);
+            while_cont.setCondition(s);
+            GenericController sub = new GenericController();
+            while_cont.addTestElement(sub);
+            sub.addTestElement(new TestSampler("2"));
+            sub.addTestElement(new TestSampler("3"));
+            
+            controller.addTestElement(new TestSampler("4"));
+
+            setLastSampleStatus(true);
+            controller.initialize();
+            assertEquals("1", nextName(controller));
+            assertEquals("2", nextName(controller));
+            setLastSampleStatus(false);
+            assertEquals("3", nextName(controller));
+            assertEquals("4", nextName(controller));
+            assertNull(nextName(controller));
+        }
+
+        // Tests for Stack Overflow (bug 33954)
+        public void testAlwaysFailOK() throws Exception {
+            runTestAlwaysFail(true); // Should be OK
+        }
+
+        public void testAlwaysFailBAD() throws Exception {
+            runTestAlwaysFail(false);
+        }
+
+        private void runTestAlwaysFail(boolean other) {
+            LoopController controller = new LoopController();
+            controller.setContinueForever(true);
+            controller.setLoops(-1);
+            WhileController while_cont = new WhileController();
+            setLastSampleStatus(false);
+            while_cont.setCondition("false");
+            while_cont.addTestElement(new TestSampler("one"));
+            while_cont.addTestElement(new TestSampler("two"));
+            controller.addTestElement(while_cont);
+            if (other) {
+                controller.addTestElement(new TestSampler("three"));
+            }
+            controller.initialize();
+            try {
+                if (other) {
+                    assertEquals("three", nextName(controller));
+                } else {
+                    assertNull(nextName(controller));
+                }
+            } catch (StackOverflowError e) {
+                // e.printStackTrace();
+                fail(e.toString());
+            }
+        }
 }
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org