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 2006/01/13 04:10:23 UTC
svn commit: r368564 - in
/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter: config/gui/
control/
Author: sebb
Date: Thu Jan 12 19:10:13 2006
New Revision: 368564
URL: http://svn.apache.org/viewcvs?rev=368564&view=rev
Log:
Move test code to test tree
Added:
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/config/gui/TestArgumentsPanel.java (with props)
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestGenericController.java (with props)
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestIfController.java (with props)
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestInterleaveControl.java (with props)
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestLoopController.java (with props)
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestOnceOnlyController.java (with props)
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRandomOrderController.java (with props)
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRunTime.java (with props)
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestSwitchController.java (with props)
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestThroughputController.java (with props)
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestWhileController.java (with props)
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/config/gui/TestArgumentsPanel.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/config/gui/TestArgumentsPanel.java?rev=368564&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/config/gui/TestArgumentsPanel.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/config/gui/TestArgumentsPanel.java Thu Jan 12 19:10:13 2006
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.config.gui;
+
+import junit.framework.TestCase;
+
+import org.apache.jmeter.config.Argument;
+import org.apache.jmeter.config.Arguments;
+
+/**
+ * A GUI panel allowing the user to enter name-value argument pairs. These
+ * arguments (or parameters) are usually used to provide configuration values
+ * for some other component.
+ *
+ * @version $Revision$ on $Date$
+ */
+public class TestArgumentsPanel extends TestCase {
+ /**
+ * Create a new test.
+ *
+ * @param name
+ * the name of the test
+ */
+ public TestArgumentsPanel(String name) {
+ super(name);
+ }
+
+ /**
+ * Test that adding an argument to the table results in an appropriate
+ * TestElement being created.
+ *
+ * @throws Exception
+ * if an exception occurred during the test
+ */
+ public void testArgumentCreation() throws Exception {
+ ArgumentsPanel gui = new ArgumentsPanel();
+ gui.tableModel.addRow(new Argument());
+ gui.tableModel.setValueAt("howdy", 0, 0);
+ gui.tableModel.addRow(new Argument());
+ gui.tableModel.setValueAt("doody", 0, 1);
+
+ assertEquals("=", ((Argument) ((Arguments) gui.createTestElement()).getArguments().get(0).getObjectValue())
+ .getMetaData());
+ }
+}
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/config/gui/TestArgumentsPanel.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/config/gui/TestArgumentsPanel.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/config/gui/TestArgumentsPanel.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestGenericController.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestGenericController.java?rev=368564&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestGenericController.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestGenericController.java Thu Jan 12 19:10:13 2006
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.control;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.junit.stubs.TestSampler;
+import org.apache.jmeter.testelement.TestElement;
+
+public class TestGenericController extends JMeterTestCase {
+ public TestGenericController(String name) {
+ super(name);
+ }
+
+ public void testProcessing() throws Exception {
+ testLog.debug("Testing Generic Controller");
+ GenericController controller = new GenericController();
+ GenericController sub_1 = new GenericController();
+ sub_1.addTestElement(new TestSampler("one"));
+ sub_1.addTestElement(new TestSampler("two"));
+ controller.addTestElement(sub_1);
+ controller.addTestElement(new TestSampler("three"));
+ GenericController sub_2 = new GenericController();
+ GenericController sub_3 = new GenericController();
+ sub_2.addTestElement(new TestSampler("four"));
+ sub_3.addTestElement(new TestSampler("five"));
+ sub_3.addTestElement(new TestSampler("six"));
+ sub_2.addTestElement(sub_3);
+ sub_2.addTestElement(new TestSampler("seven"));
+ controller.addTestElement(sub_2);
+ String[] order = new String[] { "one", "two", "three", "four", "five", "six", "seven" };
+ int counter = 7;
+ controller.initialize();
+ for (int i = 0; i < 2; i++) {
+ assertEquals(7, counter);
+ counter = 0;
+ TestElement sampler = null;
+ while ((sampler = controller.next()) != null) {
+ assertEquals(order[counter++], sampler.getPropertyAsString(TestElement.NAME));
+ }
+ }
+ }
+}
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestGenericController.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestGenericController.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestGenericController.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestIfController.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestIfController.java?rev=368564&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestIfController.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestIfController.java Thu Jan 12 19:10:13 2006
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2003-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.control;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+//import org.apache.jmeter.testelement.TestElement;
+
+public class TestIfController extends JMeterTestCase {
+ public TestIfController(String name) {
+ super(name);
+ }
+
+ public void testProcessing() throws Exception {
+
+ GenericController controller = new GenericController();
+
+ controller.addTestElement(new IfController("false==false"));
+ controller.addTestElement(new IfController(" \"a\".equals(\"a\")"));
+ controller.addTestElement(new IfController("2<100"));
+
+ //TODO enable some proper tests!!
+
+ /*
+ * GenericController sub_1 = new GenericController();
+ * sub_1.addTestElement(new IfController("3==3"));
+ * controller.addTestElement(sub_1); controller.addTestElement(new
+ * IfController("false==true"));
+ */
+
+ /*
+ * GenericController controller = new GenericController();
+ * GenericController sub_1 = new GenericController();
+ * sub_1.addTestElement(new IfController("10<100"));
+ * sub_1.addTestElement(new IfController("true==false"));
+ * controller.addTestElement(sub_1); controller.addTestElement(new
+ * IfController("false==false"));
+ *
+ * IfController sub_2 = new IfController(); sub_2.setCondition( "10<10000");
+ * GenericController sub_3 = new GenericController();
+ *
+ * sub_2.addTestElement(new IfController( " \"a\".equals(\"a\")" ) );
+ * sub_3.addTestElement(new IfController("2>100"));
+ * sub_3.addTestElement(new IfController("false==true"));
+ * sub_2.addTestElement(sub_3); sub_2.addTestElement(new
+ * IfController("2==3")); controller.addTestElement(sub_2);
+ */
+
+ /*
+ * IfController controller = new IfController("12==12");
+ * controller.initialize();
+ */
+// TestElement sampler = null;
+// while ((sampler = controller.next()) != null) {
+// logger.debug(" ->>> Gonna assertTrue :" + sampler.getClass().getName() + " Property is ---->>>"
+// + sampler.getPropertyAsString(TestElement.NAME));
+// }
+ }
+}
\ No newline at end of file
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestIfController.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestIfController.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestIfController.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestInterleaveControl.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestInterleaveControl.java?rev=368564&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestInterleaveControl.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestInterleaveControl.java Thu Jan 12 19:10:13 2006
@@ -0,0 +1,226 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.control;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.junit.stubs.TestSampler;
+import org.apache.jmeter.testelement.TestElement;
+
+public class TestInterleaveControl extends JMeterTestCase {
+ public TestInterleaveControl(String name) {
+ super(name);
+ }
+
+ public void testProcessing() throws Exception {
+ testLog.debug("Testing Interleave Controller 1");
+ GenericController controller = new GenericController();
+ InterleaveControl sub_1 = new InterleaveControl();
+ sub_1.setStyle(InterleaveControl.IGNORE_SUB_CONTROLLERS);
+ sub_1.addTestElement(new TestSampler("one"));
+ sub_1.addTestElement(new TestSampler("two"));
+ controller.addTestElement(sub_1);
+ controller.addTestElement(new TestSampler("three"));
+ LoopController sub_2 = new LoopController();
+ sub_2.setLoops(3);
+ GenericController sub_3 = new GenericController();
+ sub_2.addTestElement(new TestSampler("four"));
+ sub_3.addTestElement(new TestSampler("five"));
+ sub_3.addTestElement(new TestSampler("six"));
+ sub_2.addTestElement(sub_3);
+ sub_2.addTestElement(new TestSampler("seven"));
+ controller.addTestElement(sub_2);
+ String[] interleaveOrder = new String[] { "one", "two" };
+ String[] order = new String[] { "dummy", "three", "four", "five", "six", "seven", "four", "five", "six",
+ "seven", "four", "five", "six", "seven" };
+ int counter = 14;
+ controller.setRunningVersion(true);
+ sub_1.setRunningVersion(true);
+ sub_2.setRunningVersion(true);
+ sub_3.setRunningVersion(true);
+ controller.initialize();
+ for (int i = 0; i < 4; i++) {
+ assertEquals(14, counter);
+ counter = 0;
+ TestElement sampler = null;
+ while ((sampler = controller.next()) != null) {
+ if (counter == 0) {
+ assertEquals(interleaveOrder[i % 2], sampler.getPropertyAsString(TestElement.NAME));
+ } else {
+ assertEquals(order[counter], sampler.getPropertyAsString(TestElement.NAME));
+ }
+ counter++;
+ }
+ }
+ }
+
+ public void testProcessing6() throws Exception {
+ testLog.debug("Testing Interleave Controller 6");
+ GenericController controller = new GenericController();
+ InterleaveControl sub_1 = new InterleaveControl();
+ controller.addTestElement(new TestSampler("one"));
+ sub_1.setStyle(InterleaveControl.IGNORE_SUB_CONTROLLERS);
+ controller.addTestElement(sub_1);
+ LoopController sub_2 = new LoopController();
+ sub_1.addTestElement(sub_2);
+ sub_2.setLoops(3);
+ int counter = 1;
+ controller.setRunningVersion(true);
+ sub_1.setRunningVersion(true);
+ sub_2.setRunningVersion(true);
+ controller.initialize();
+ for (int i = 0; i < 4; i++) {
+ assertEquals(1, counter);
+ counter = 0;
+ TestElement sampler = null;
+ while ((sampler = controller.next()) != null) {
+ assertEquals("one", sampler.getPropertyAsString(TestElement.NAME));
+ counter++;
+ }
+ }
+ }
+
+ public void testProcessing2() throws Exception {
+ testLog.debug("Testing Interleave Controller 2");
+ GenericController controller = new GenericController();
+ InterleaveControl sub_1 = new InterleaveControl();
+ sub_1.setStyle(InterleaveControl.IGNORE_SUB_CONTROLLERS);
+ sub_1.addTestElement(new TestSampler("one"));
+ sub_1.addTestElement(new TestSampler("two"));
+ controller.addTestElement(sub_1);
+ controller.addTestElement(new TestSampler("three"));
+ LoopController sub_2 = new LoopController();
+ sub_2.setLoops(3);
+ GenericController sub_3 = new GenericController();
+ sub_2.addTestElement(new TestSampler("four"));
+ sub_3.addTestElement(new TestSampler("five"));
+ sub_3.addTestElement(new TestSampler("six"));
+ sub_2.addTestElement(sub_3);
+ sub_2.addTestElement(new TestSampler("seven"));
+ sub_1.addTestElement(sub_2);
+ String[] order = new String[] { "one", "three", "two", "three", "four", "three", "one", "three", "two",
+ "three", "five", "three", "one", "three", "two", "three", "six", "three", "one", "three" };
+ int counter = 0;
+ controller.setRunningVersion(true);
+ sub_1.setRunningVersion(true);
+ sub_2.setRunningVersion(true);
+ sub_3.setRunningVersion(true);
+ controller.initialize();
+ while (counter < order.length) {
+ TestElement sampler = null;
+ while ((sampler = controller.next()) != null) {
+ assertEquals("failed on " + counter, order[counter], sampler.getPropertyAsString(TestElement.NAME));
+ counter++;
+ }
+ }
+ }
+
+ public void testProcessing3() throws Exception {
+ testLog.debug("Testing Interleave Controller 3");
+ GenericController controller = new GenericController();
+ InterleaveControl sub_1 = new InterleaveControl();
+ sub_1.setStyle(InterleaveControl.USE_SUB_CONTROLLERS);
+ sub_1.addTestElement(new TestSampler("one"));
+ sub_1.addTestElement(new TestSampler("two"));
+ controller.addTestElement(sub_1);
+ controller.addTestElement(new TestSampler("three"));
+ LoopController sub_2 = new LoopController();
+ sub_2.setLoops(3);
+ GenericController sub_3 = new GenericController();
+ sub_2.addTestElement(new TestSampler("four"));
+ sub_3.addTestElement(new TestSampler("five"));
+ sub_3.addTestElement(new TestSampler("six"));
+ sub_2.addTestElement(sub_3);
+ sub_2.addTestElement(new TestSampler("seven"));
+ sub_1.addTestElement(sub_2);
+ String[] order = new String[] { "one", "three", "two", "three", "four", "five", "six", "seven", "four",
+ "five", "six", "seven", "four", "five", "six", "seven", "three", "one", "three", "two", "three" };
+ int counter = 0;
+ controller.setRunningVersion(true);
+ sub_1.setRunningVersion(true);
+ sub_2.setRunningVersion(true);
+ sub_3.setRunningVersion(true);
+ controller.initialize();
+ while (counter < order.length) {
+ TestElement sampler = null;
+ while ((sampler = controller.next()) != null) {
+ assertEquals("failed on" + counter, order[counter], sampler.getPropertyAsString(TestElement.NAME));
+ counter++;
+ }
+ }
+ }
+
+ public void testProcessing4() throws Exception {
+ testLog.debug("Testing Interleave Controller 4");
+ GenericController controller = new GenericController();
+ InterleaveControl sub_1 = new InterleaveControl();
+ sub_1.setStyle(InterleaveControl.IGNORE_SUB_CONTROLLERS);
+ controller.addTestElement(sub_1);
+ GenericController sub_2 = new GenericController();
+ sub_2.addTestElement(new TestSampler("one"));
+ sub_2.addTestElement(new TestSampler("two"));
+ sub_1.addTestElement(sub_2);
+ GenericController sub_3 = new GenericController();
+ sub_3.addTestElement(new TestSampler("three"));
+ sub_3.addTestElement(new TestSampler("four"));
+ sub_1.addTestElement(sub_3);
+ String[] order = new String[] { "one", "three", "two", "four" };
+ int counter = 0;
+ controller.setRunningVersion(true);
+ sub_1.setRunningVersion(true);
+ sub_2.setRunningVersion(true);
+ sub_3.setRunningVersion(true);
+ controller.initialize();
+ while (counter < order.length) {
+ TestElement sampler = null;
+ while ((sampler = controller.next()) != null) {
+ assertEquals("failed on" + counter, order[counter], sampler.getPropertyAsString(TestElement.NAME));
+ counter++;
+ }
+ }
+ }
+
+ public void testProcessing5() throws Exception {
+ testLog.debug("Testing Interleave Controller 5");
+ GenericController controller = new GenericController();
+ InterleaveControl sub_1 = new InterleaveControl();
+ sub_1.setStyle(InterleaveControl.USE_SUB_CONTROLLERS);
+ controller.addTestElement(sub_1);
+ GenericController sub_2 = new GenericController();
+ sub_2.addTestElement(new TestSampler("one"));
+ sub_2.addTestElement(new TestSampler("two"));
+ sub_1.addTestElement(sub_2);
+ GenericController sub_3 = new GenericController();
+ sub_3.addTestElement(new TestSampler("three"));
+ sub_3.addTestElement(new TestSampler("four"));
+ sub_1.addTestElement(sub_3);
+ String[] order = new String[] { "one", "two", "three", "four" };
+ int counter = 0;
+ controller.setRunningVersion(true);
+ sub_1.setRunningVersion(true);
+ sub_2.setRunningVersion(true);
+ sub_3.setRunningVersion(true);
+ controller.initialize();
+ while (counter < order.length) {
+ TestElement sampler = null;
+ while ((sampler = controller.next()) != null) {
+ assertEquals("failed on" + counter, order[counter], sampler.getPropertyAsString(TestElement.NAME));
+ counter++;
+ }
+ }
+ }
+}
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestInterleaveControl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestInterleaveControl.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestInterleaveControl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestLoopController.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestLoopController.java?rev=368564&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestLoopController.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestLoopController.java Thu Jan 12 19:10:13 2006
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.control;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.junit.stubs.TestSampler;
+import org.apache.jmeter.testelement.TestElement;
+
+public class TestLoopController extends JMeterTestCase {
+ public TestLoopController(String name) {
+ super(name);
+ }
+
+ public void testProcessing() throws Exception {
+ GenericController controller = new GenericController();
+ GenericController sub_1 = new GenericController();
+ sub_1.addTestElement(new TestSampler("one"));
+ sub_1.addTestElement(new TestSampler("two"));
+ controller.addTestElement(sub_1);
+ controller.addTestElement(new TestSampler("three"));
+ LoopController sub_2 = new LoopController();
+ sub_2.setLoops(3);
+ GenericController sub_3 = new GenericController();
+ sub_2.addTestElement(new TestSampler("four"));
+ sub_3.addTestElement(new TestSampler("five"));
+ sub_3.addTestElement(new TestSampler("six"));
+ sub_2.addTestElement(sub_3);
+ sub_2.addTestElement(new TestSampler("seven"));
+ controller.addTestElement(sub_2);
+ String[] order = new String[] { "one", "two", "three", "four", "five", "six", "seven", "four", "five",
+ "six", "seven", "four", "five", "six", "seven" };
+ int counter = 15;
+ controller.setRunningVersion(true);
+ sub_1.setRunningVersion(true);
+ sub_2.setRunningVersion(true);
+ sub_3.setRunningVersion(true);
+ controller.initialize();
+ for (int i = 0; i < 2; i++) {
+ assertEquals(15, counter);
+ counter = 0;
+ TestElement sampler = null;
+ while ((sampler = controller.next()) != null) {
+ assertEquals(order[counter++], sampler.getPropertyAsString(TestElement.NAME));
+ }
+ }
+ }
+
+ public void testLoopZeroTimes() throws Exception {
+ LoopController loop = new LoopController();
+ loop.setLoops(0);
+ loop.addTestElement(new TestSampler("never run"));
+ loop.initialize();
+ assertNull(loop.next());
+ }
+
+ public void testInfiniteLoop() throws Exception {
+ LoopController loop = new LoopController();
+ loop.setLoops(-1);
+ loop.addTestElement(new TestSampler("never run"));
+ loop.setRunningVersion(true);
+ loop.initialize();
+ for (int i = 0; i < 42; i++) {
+ assertNotNull(loop.next());
+ }
+ }
+}
\ No newline at end of file
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestLoopController.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestLoopController.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestLoopController.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestOnceOnlyController.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestOnceOnlyController.java?rev=368564&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestOnceOnlyController.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestOnceOnlyController.java Thu Jan 12 19:10:13 2006
@@ -0,0 +1,120 @@
+// $Header$
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.control;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.junit.stubs.TestSampler;
+import org.apache.jmeter.testelement.TestElement;
+
+/**
+ * @author Michael Stover Created March 13, 2001
+ * @version $Revision$ Last updated: $Date$
+ */
+public class TestOnceOnlyController extends JMeterTestCase {
+ public TestOnceOnlyController(String name) {
+ super(name);
+ }
+
+ public void testProcessing() throws Exception {
+ GenericController controller = new GenericController();
+ GenericController sub_1 = new OnceOnlyController();
+ sub_1.addTestElement(new TestSampler("one"));
+ sub_1.addTestElement(new TestSampler("two"));
+ controller.addTestElement(sub_1);
+ controller.addTestElement(new TestSampler("three"));
+ LoopController sub_2 = new LoopController();
+ sub_2.setLoops(3);
+ GenericController sub_3 = new GenericController();
+ sub_2.addTestElement(new TestSampler("four"));
+ sub_3.addTestElement(new TestSampler("five"));
+ sub_3.addTestElement(new TestSampler("six"));
+ sub_2.addTestElement(sub_3);
+ sub_2.addTestElement(new TestSampler("seven"));
+ controller.addTestElement(sub_2);
+ String[] interleaveOrder = new String[] { "one", "two" };
+ String[] order = new String[] { "", "", "three", "four", "five", "six", "seven", "four", "five", "six",
+ "seven", "four", "five", "six", "seven" };
+ int counter = 15;
+ controller.setRunningVersion(true);
+ sub_1.setRunningVersion(true);
+ sub_2.setRunningVersion(true);
+ sub_3.setRunningVersion(true);
+ controller.initialize();
+ for (int i = 0; i < 4; i++) {
+ assertEquals(15, counter);
+ counter = 0;
+ if (i > 0) {
+ counter = 2;
+ }
+ TestElement sampler = null;
+ while ((sampler = controller.next()) != null) {
+ if (i == 0 && counter < 2) {
+ assertEquals(interleaveOrder[counter], sampler.getPropertyAsString(TestElement.NAME));
+ } else {
+ assertEquals(order[counter], sampler.getPropertyAsString(TestElement.NAME));
+ }
+ counter++;
+ }
+ }
+ }
+
+ public void testProcessing2() throws Exception {
+ GenericController controller = new GenericController();
+ GenericController sub_1 = new OnceOnlyController();
+ sub_1.addTestElement(new TestSampler("one"));
+ sub_1.addTestElement(new TestSampler("two"));
+ controller.addTestElement(sub_1);
+ controller.addTestElement(new TestSampler("three"));
+ LoopController sub_2 = new LoopController();
+ sub_2.setLoops(3);
+ OnceOnlyController sub_3 = new OnceOnlyController();
+ sub_2.addTestElement(new TestSampler("four"));
+ sub_3.addTestElement(new TestSampler("five"));
+ sub_3.addTestElement(new TestSampler("six"));
+ sub_2.addTestElement(sub_3);
+ sub_2.addIterationListener(sub_3);
+ sub_2.addTestElement(new TestSampler("seven"));
+ controller.addTestElement(sub_2);
+ String[] interleaveOrder = new String[] { "one", "two" };
+ String[] order = new String[] { "", "", "three", "four", "five", "six", "seven", "four", "seven", "four",
+ "seven" };
+ int counter = 11;
+ controller.setRunningVersion(true);
+ sub_1.setRunningVersion(true);
+ sub_2.setRunningVersion(true);
+ sub_3.setRunningVersion(true);
+ controller.initialize();
+ for (int i = 0; i < 4; i++) {
+ assertEquals(11, counter);
+ counter = 0;
+ if (i > 0) {
+ counter = 2;
+ }
+ TestElement sampler = null;
+ while ((sampler = controller.next()) != null) {
+ if (i == 0 && counter < 2) {
+ assertEquals(interleaveOrder[counter], sampler.getPropertyAsString(TestElement.NAME));
+ } else {
+ assertEquals(order[counter], sampler.getPropertyAsString(TestElement.NAME));
+ }
+ counter++;
+ }
+ }
+ }
+}
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestOnceOnlyController.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestOnceOnlyController.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestOnceOnlyController.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRandomOrderController.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRandomOrderController.java?rev=368564&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRandomOrderController.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRandomOrderController.java Thu Jan 12 19:10:13 2006
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jmeter.control;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.junit.stubs.TestSampler;
+import org.apache.jmeter.testelement.TestElement;
+
+/**
+ * A controller that runs its children each at most once, but in a random order.
+ *
+ * @author Mike Verdone
+ * @version $Revision$ updated on $Date$
+ */
+public class TestRandomOrderController extends JMeterTestCase {
+
+ public TestRandomOrderController(String name) {
+ super(name);
+ }
+
+ public void testRandomOrder() {
+ testLog.debug("Testing RandomOrderController");
+ RandomOrderController roc = new RandomOrderController();
+ roc.addTestElement(new TestSampler("zero"));
+ roc.addTestElement(new TestSampler("one"));
+ roc.addTestElement(new TestSampler("two"));
+ roc.addTestElement(new TestSampler("three"));
+ TestElement sampler = null;
+ List usedSamplers = new ArrayList();
+ roc.initialize();
+ while ((sampler = roc.next()) != null) {
+ String samplerName = sampler.getPropertyAsString(TestSampler.NAME);
+ if (usedSamplers.contains(samplerName)) {
+ assertTrue("Duplicate sampler returned from next()", false);
+ }
+ usedSamplers.add(samplerName);
+ }
+ assertTrue("All samplers were returned", usedSamplers.size() == 4);
+ }
+
+ public void testRandomOrderNoElements() {
+ RandomOrderController roc = new RandomOrderController();
+ roc.initialize();
+ assertTrue(roc.next() == null);
+ }
+
+ public void testRandomOrderOneElement() {
+ RandomOrderController roc = new RandomOrderController();
+ roc.addTestElement(new TestSampler("zero"));
+ TestElement sampler = null;
+ List usedSamplers = new ArrayList();
+ roc.initialize();
+ while ((sampler = roc.next()) != null) {
+ String samplerName = sampler.getPropertyAsString(TestSampler.NAME);
+ if (usedSamplers.contains(samplerName)) {
+ assertTrue("Duplicate sampler returned from next()", false);
+ }
+ usedSamplers.add(samplerName);
+ }
+ assertTrue("All samplers were returned", usedSamplers.size() == 1);
+ }
+}
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRandomOrderController.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRandomOrderController.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRandomOrderController.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRunTime.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRunTime.java?rev=368564&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRunTime.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRunTime.java Thu Jan 12 19:10:13 2006
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.control;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.junit.stubs.TestSampler;
+import org.apache.jmeter.samplers.Sampler;
+
+/**
+ * @version $Revision$
+ */
+public class TestRunTime extends JMeterTestCase {
+ public TestRunTime(String name) {
+ super(name);
+ }
+
+ public void testProcessing() throws Exception {
+
+ RunTime controller = new RunTime();
+ controller.setRuntime(10);
+ TestSampler samp1 = new TestSampler("Sample 1", 500);
+ TestSampler samp2 = new TestSampler("Sample 2", 500);
+
+ LoopController sub1 = new LoopController();
+ sub1.setLoops(2);
+ sub1.setContinueForever(false);
+ sub1.addTestElement(samp1);
+
+ LoopController sub2 = new LoopController();
+ sub2.setLoops(40);
+ sub2.setContinueForever(false);
+ sub2.addTestElement(samp2);
+ controller.addTestElement(sub1);
+ controller.addTestElement(sub2);
+ controller.setRunningVersion(true);
+ sub1.setRunningVersion(true);
+ sub2.setRunningVersion(true);
+ controller.initialize();
+ Sampler sampler = null;
+ int loops = 0;
+ long now = System.currentTimeMillis();
+ while ((sampler = controller.next()) != null) {
+ loops++;
+ sampler.sample(null);
+ }
+ long elapsed = System.currentTimeMillis() - now;
+ assertTrue("Should be at least 20 loops", loops >= 20);
+ assertTrue("Should be fewer than 30 loops", loops < 30);
+ assertTrue("Should take at least 10 seconds", elapsed >= 10000);
+ assertTrue("Should take less than 12 seconds", elapsed <= 12000);
+ assertEquals("Sampler 1 should run 2 times", 2, samp1.getSamples());
+ assertTrue("Sampler 2 should run >= 18 times", samp2.getSamples() >= 18);
+ }
+}
\ No newline at end of file
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRunTime.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRunTime.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestRunTime.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestSwitchController.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestSwitchController.java?rev=368564&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestSwitchController.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestSwitchController.java Thu Jan 12 19:10:13 2006
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.control;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.junit.stubs.TestSampler;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.testelement.TestElement;
+
+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;
+ } else {
+ n = s.getPropertyAsString(TestElement.NAME);
+ 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");
+ }
+
+ public void test2() throws Exception {
+ runSimpleTests("2", "two");
+ }
+
+ public void test3() throws Exception {
+ runSimpleTests("3", "three");
+ }
+
+ public void test4() throws Exception {
+ runSimpleTests("4", "zero");
+ }
+
+ public void testX() throws Exception {
+ runSimpleTests("X", "zero");
+ }
+
+ public void runSimpleTests(String cond, String exp) throws Exception {
+ runSimpleTest(cond, exp);
+ runSimpleTest2(cond, exp);
+ }
+
+ // Simple test with single Selection controller
+ public 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));
+ 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
+ public void runSimpleTest2(String cond, String exp) 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"));
+
+ switch_cont.addTestElement(new TestSampler("two"));
+
+ switch_cont.addTestElement(sub_2);
+ sub_2.addTestElement(new TestSampler("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("before", nextName(controller));
+ assertEquals(exp, nextName(controller));
+ assertEquals("after", nextName(controller));
+ assertNull(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
+ */
+ public 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));
+ }
+}
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestSwitchController.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestSwitchController.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestSwitchController.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestThroughputController.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestThroughputController.java?rev=368564&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestThroughputController.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestThroughputController.java Thu Jan 12 19:10:13 2006
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.control;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.junit.stubs.TestSampler;
+import org.apache.jmeter.testelement.TestElement;
+
+/**
+ * This class represents a controller that can controll the number of times that
+ * it is executed, either by the total number of times the user wants the
+ * controller executed (BYNUMBER) or by the percentage of time it is called
+ * (BYPERCENT)
+ *
+ * @author Thad Smith
+ * @version $Revision$
+ */
+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 + ", executions: " + sub_1.getExecutions() + ", iteration: "
+ + sub_1.getIteration(), order[counter], sampler.getPropertyAsString(TestElement.NAME));
+ }
+ 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
+ .getPropertyAsString(TestElement.NAME));
+ 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
+ .getPropertyAsString(TestElement.NAME));
+ 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
+ .getPropertyAsString(TestElement.NAME));
+ 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
+ .getPropertyAsString(TestElement.NAME));
+ counter++;
+ }
+ assertEquals(counter, 150 * order.length);
+ counter = 0;
+ }
+ sub_1.testEnded();
+ }
+}
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestThroughputController.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestThroughputController.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestThroughputController.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestWhileController.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestWhileController.java?rev=368564&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestWhileController.java (added)
+++ jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestWhileController.java Thu Jan 12 19:10:13 2006
@@ -0,0 +1,197 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.control;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.junit.stubs.TestSampler;
+import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.testelement.TestElement;
+
+/**
+ * @version $Revision$
+ */
+public class TestWhileController extends JMeterTestCase {
+ static {
+ // LoggingManager.setPriority("DEBUG","jmeter");
+ // LoggingManager.setTarget(new java.io.PrintWriter(System.out));
+ }
+
+ public TestWhileController(String name) {
+ super(name);
+ }
+
+ // Get next sample and its name
+ private String nextName(GenericController c) {
+ Sampler s = c.next();
+ if (s == null) {
+ return null;
+ } else {
+ return s.getPropertyAsString(TestElement.NAME);
+ }
+ }
+
+ // 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);
+ }
+
+ public void runtestPrevOK(String type) throws Exception {
+ WhileController.testMode = true;
+ WhileController.testModeResult = true;
+ GenericController controller = new GenericController();
+ WhileController while_cont = new WhileController();
+ 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));
+ WhileController.testModeResult = false;// one and two fail
+ if (type.equals(OTHER))
+ while_cont.setCondition("false");
+ assertEquals("two", nextName(controller));
+ assertEquals("three", nextName(controller));
+ WhileController.testModeResult = true;// but three OK, so does not exit
+ if (type.equals(OTHER))
+ while_cont.setCondition(OTHER);
+ assertEquals("one", nextName(controller));
+ assertEquals("two", nextName(controller));
+ assertEquals("three", nextName(controller));
+ WhileController.testModeResult = false;// three fails, so exits while
+ if (type.equals(OTHER))
+ while_cont.setCondition("false");
+ assertEquals("four", nextName(controller));
+ assertNull(nextName(controller));
+ WhileController.testModeResult = 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");
+ WhileController.testMode = true;
+ WhileController.testModeResult = false;
+ GenericController controller = new GenericController();
+ WhileController while_cont = new WhileController();
+ 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));
+ assertEquals("one", nextName(controller));
+ assertEquals("two", nextName(controller));
+ assertEquals("three", nextName(controller));
+ assertNull(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");
+ }
+
+ public void runTestPrevFailed(String s) throws Exception {
+ WhileController.testMode = true;
+ WhileController.testModeResult = false;
+ GenericController controller = new GenericController();
+ WhileController while_cont = new WhileController();
+ 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));
+ }
+
+ // Tests for Stack Overflow (bug 33954)
+ public void testAlwaysFailOK() throws Exception {
+ runTestAlwaysFail(true); // Should be OK
+ }
+
+ // TODO - re-enable when fix found
+ public void disabletestAlwaysFailBAD() throws Exception {
+ runTestAlwaysFail(false); // Currently fails
+ }
+
+ public void runTestAlwaysFail(boolean other) {
+ WhileController.testMode = true;
+ WhileController.testModeResult = false;
+ LoopController controller = new LoopController();
+ controller.setContinueForever(true);
+ controller.setLoops(-1);
+ WhileController while_cont = new WhileController();
+ 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
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestWhileController.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestWhileController.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision
Propchange: jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/control/TestWhileController.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org