001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.control;
020:
021: import org.apache.jmeter.junit.JMeterTestCase;
022: import org.apache.jmeter.junit.stubs.TestSampler;
023: import org.apache.jmeter.testelement.TestElement;
024:
025: public class TestInterleaveControl extends JMeterTestCase {
026: public TestInterleaveControl(String name) {
027: super (name);
028: }
029:
030: public void testProcessing() throws Exception {
031: testLog.debug("Testing Interleave Controller 1");
032: GenericController controller = new GenericController();
033: InterleaveControl sub_1 = new InterleaveControl();
034: sub_1.setStyle(InterleaveControl.IGNORE_SUB_CONTROLLERS);
035: sub_1.addTestElement(new TestSampler("one"));
036: sub_1.addTestElement(new TestSampler("two"));
037: controller.addTestElement(sub_1);
038: controller.addTestElement(new TestSampler("three"));
039: LoopController sub_2 = new LoopController();
040: sub_2.setLoops(3);
041: GenericController sub_3 = new GenericController();
042: sub_2.addTestElement(new TestSampler("four"));
043: sub_3.addTestElement(new TestSampler("five"));
044: sub_3.addTestElement(new TestSampler("six"));
045: sub_2.addTestElement(sub_3);
046: sub_2.addTestElement(new TestSampler("seven"));
047: controller.addTestElement(sub_2);
048: String[] interleaveOrder = new String[] { "one", "two" };
049: String[] order = new String[] { "dummy", "three", "four",
050: "five", "six", "seven", "four", "five", "six", "seven",
051: "four", "five", "six", "seven" };
052: int counter = 14;
053: controller.setRunningVersion(true);
054: sub_1.setRunningVersion(true);
055: sub_2.setRunningVersion(true);
056: sub_3.setRunningVersion(true);
057: controller.initialize();
058: for (int i = 0; i < 4; i++) {
059: assertEquals(14, counter);
060: counter = 0;
061: TestElement sampler = null;
062: while ((sampler = controller.next()) != null) {
063: if (counter == 0) {
064: assertEquals(interleaveOrder[i % 2], sampler
065: .getPropertyAsString(TestElement.NAME));
066: } else {
067: assertEquals(order[counter], sampler
068: .getPropertyAsString(TestElement.NAME));
069: }
070: counter++;
071: }
072: }
073: }
074:
075: public void testProcessing6() throws Exception {
076: testLog.debug("Testing Interleave Controller 6");
077: GenericController controller = new GenericController();
078: InterleaveControl sub_1 = new InterleaveControl();
079: controller.addTestElement(new TestSampler("one"));
080: sub_1.setStyle(InterleaveControl.IGNORE_SUB_CONTROLLERS);
081: controller.addTestElement(sub_1);
082: LoopController sub_2 = new LoopController();
083: sub_1.addTestElement(sub_2);
084: sub_2.setLoops(3);
085: int counter = 1;
086: controller.setRunningVersion(true);
087: sub_1.setRunningVersion(true);
088: sub_2.setRunningVersion(true);
089: controller.initialize();
090: for (int i = 0; i < 4; i++) {
091: assertEquals(1, counter);
092: counter = 0;
093: TestElement sampler = null;
094: while ((sampler = controller.next()) != null) {
095: assertEquals("one", sampler
096: .getPropertyAsString(TestElement.NAME));
097: counter++;
098: }
099: }
100: }
101:
102: public void testProcessing2() throws Exception {
103: testLog.debug("Testing Interleave Controller 2");
104: GenericController controller = new GenericController();
105: InterleaveControl sub_1 = new InterleaveControl();
106: sub_1.setStyle(InterleaveControl.IGNORE_SUB_CONTROLLERS);
107: sub_1.addTestElement(new TestSampler("one"));
108: sub_1.addTestElement(new TestSampler("two"));
109: controller.addTestElement(sub_1);
110: controller.addTestElement(new TestSampler("three"));
111: LoopController sub_2 = new LoopController();
112: sub_2.setLoops(3);
113: GenericController sub_3 = new GenericController();
114: sub_2.addTestElement(new TestSampler("four"));
115: sub_3.addTestElement(new TestSampler("five"));
116: sub_3.addTestElement(new TestSampler("six"));
117: sub_2.addTestElement(sub_3);
118: sub_2.addTestElement(new TestSampler("seven"));
119: sub_1.addTestElement(sub_2);
120: String[] order = new String[] { "one", "three", "two", "three",
121: "four", "three", "one", "three", "two", "three",
122: "five", "three", "one", "three", "two", "three", "six",
123: "three", "one", "three" };
124: int counter = 0;
125: controller.setRunningVersion(true);
126: sub_1.setRunningVersion(true);
127: sub_2.setRunningVersion(true);
128: sub_3.setRunningVersion(true);
129: controller.initialize();
130: while (counter < order.length) {
131: TestElement sampler = null;
132: while ((sampler = controller.next()) != null) {
133: assertEquals("failed on " + counter, order[counter],
134: sampler.getPropertyAsString(TestElement.NAME));
135: counter++;
136: }
137: }
138: }
139:
140: public void testProcessing3() throws Exception {
141: testLog.debug("Testing Interleave Controller 3");
142: GenericController controller = new GenericController();
143: InterleaveControl sub_1 = new InterleaveControl();
144: sub_1.setStyle(InterleaveControl.USE_SUB_CONTROLLERS);
145: sub_1.addTestElement(new TestSampler("one"));
146: sub_1.addTestElement(new TestSampler("two"));
147: controller.addTestElement(sub_1);
148: controller.addTestElement(new TestSampler("three"));
149: LoopController sub_2 = new LoopController();
150: sub_2.setLoops(3);
151: GenericController sub_3 = new GenericController();
152: sub_2.addTestElement(new TestSampler("four"));
153: sub_3.addTestElement(new TestSampler("five"));
154: sub_3.addTestElement(new TestSampler("six"));
155: sub_2.addTestElement(sub_3);
156: sub_2.addTestElement(new TestSampler("seven"));
157: sub_1.addTestElement(sub_2);
158: String[] order = new String[] { "one", "three", "two", "three",
159: "four", "five", "six", "seven", "four", "five", "six",
160: "seven", "four", "five", "six", "seven", "three",
161: "one", "three", "two", "three" };
162: int counter = 0;
163: controller.setRunningVersion(true);
164: sub_1.setRunningVersion(true);
165: sub_2.setRunningVersion(true);
166: sub_3.setRunningVersion(true);
167: controller.initialize();
168: while (counter < order.length) {
169: TestElement sampler = null;
170: while ((sampler = controller.next()) != null) {
171: assertEquals("failed on" + counter, order[counter],
172: sampler.getPropertyAsString(TestElement.NAME));
173: counter++;
174: }
175: }
176: }
177:
178: public void testProcessing4() throws Exception {
179: testLog.debug("Testing Interleave Controller 4");
180: GenericController controller = new GenericController();
181: InterleaveControl sub_1 = new InterleaveControl();
182: sub_1.setStyle(InterleaveControl.IGNORE_SUB_CONTROLLERS);
183: controller.addTestElement(sub_1);
184: GenericController sub_2 = new GenericController();
185: sub_2.addTestElement(new TestSampler("one"));
186: sub_2.addTestElement(new TestSampler("two"));
187: sub_1.addTestElement(sub_2);
188: GenericController sub_3 = new GenericController();
189: sub_3.addTestElement(new TestSampler("three"));
190: sub_3.addTestElement(new TestSampler("four"));
191: sub_1.addTestElement(sub_3);
192: String[] order = new String[] { "one", "three", "two", "four" };
193: int counter = 0;
194: controller.setRunningVersion(true);
195: sub_1.setRunningVersion(true);
196: sub_2.setRunningVersion(true);
197: sub_3.setRunningVersion(true);
198: controller.initialize();
199: while (counter < order.length) {
200: TestElement sampler = null;
201: while ((sampler = controller.next()) != null) {
202: assertEquals("failed on" + counter, order[counter],
203: sampler.getPropertyAsString(TestElement.NAME));
204: counter++;
205: }
206: }
207: }
208:
209: public void testProcessing5() throws Exception {
210: testLog.debug("Testing Interleave Controller 5");
211: GenericController controller = new GenericController();
212: InterleaveControl sub_1 = new InterleaveControl();
213: sub_1.setStyle(InterleaveControl.USE_SUB_CONTROLLERS);
214: controller.addTestElement(sub_1);
215: GenericController sub_2 = new GenericController();
216: sub_2.addTestElement(new TestSampler("one"));
217: sub_2.addTestElement(new TestSampler("two"));
218: sub_1.addTestElement(sub_2);
219: GenericController sub_3 = new GenericController();
220: sub_3.addTestElement(new TestSampler("three"));
221: sub_3.addTestElement(new TestSampler("four"));
222: sub_1.addTestElement(sub_3);
223: String[] order = new String[] { "one", "two", "three", "four" };
224: int counter = 0;
225: controller.setRunningVersion(true);
226: sub_1.setRunningVersion(true);
227: sub_2.setRunningVersion(true);
228: sub_3.setRunningVersion(true);
229: controller.initialize();
230: while (counter < order.length) {
231: TestElement sampler = null;
232: while ((sampler = controller.next()) != null) {
233: assertEquals("failed on" + counter, order[counter],
234: sampler.getPropertyAsString(TestElement.NAME));
235: counter++;
236: }
237: }
238: }
239: }
|