1 18 19 package org.apache.jmeter.control; 20 21 import java.io.Serializable ; 22 23 import org.apache.jmeter.engine.event.LoopIterationEvent; 24 import org.apache.jmeter.engine.event.LoopIterationListener; 25 import org.apache.jmeter.junit.JMeterTestCase; 26 import org.apache.jmeter.junit.stubs.TestSampler; 27 import org.apache.jmeter.samplers.Sampler; 28 import org.apache.jmeter.testelement.TestElement; 29 30 35 public class OnceOnlyController 36 extends GenericController 37 implements Serializable , LoopIterationListener 38 { 39 40 43 public OnceOnlyController() 44 { 45 } 46 47 50 public void iterationStart(LoopIterationEvent event) 51 { 52 if (event.getIteration() == 1) 53 { 54 reInitialize(); 55 } 56 } 57 58 protected Sampler nextIsNull() throws NextIsNullException 59 { 60 return null; 61 } 62 63 65 public static class Test extends JMeterTestCase 66 { 67 public Test(String name) 68 { 69 super(name); 70 } 71 72 public void testProcessing() throws Exception 73 { 74 GenericController controller = new GenericController(); 75 GenericController sub_1 = new OnceOnlyController(); 76 sub_1.addTestElement(new TestSampler("one")); 77 sub_1.addTestElement(new TestSampler("two")); 78 controller.addTestElement(sub_1); 79 controller.addTestElement(new TestSampler("three")); 80 LoopController sub_2 = new LoopController(); 81 sub_2.setLoops(3); 82 GenericController sub_3 = new GenericController(); 83 sub_2.addTestElement(new TestSampler("four")); 84 sub_3.addTestElement(new TestSampler("five")); 85 sub_3.addTestElement(new TestSampler("six")); 86 sub_2.addTestElement(sub_3); 87 sub_2.addTestElement(new TestSampler("seven")); 88 controller.addTestElement(sub_2); 89 String [] interleaveOrder = new String [] { "one", "two" }; 90 String [] order = 91 new String [] { 92 "", 93 "", 94 "three", 95 "four", 96 "five", 97 "six", 98 "seven", 99 "four", 100 "five", 101 "six", 102 "seven", 103 "four", 104 "five", 105 "six", 106 "seven" }; 107 int counter = 15; 108 controller.initialize(); 109 for (int i = 0; i < 4; i++) 110 { 111 assertEquals(15, counter); 112 counter = 0; 113 if (i > 0) 114 { 115 counter = 2; 116 } 117 TestElement sampler = null; 118 while ((sampler = controller.next()) != null) 119 { 120 if (i == 0 && counter < 2) 121 { 122 assertEquals( 123 interleaveOrder[counter], 124 sampler.getPropertyAsString(TestElement.NAME)); 125 } 126 else 127 { 128 assertEquals( 129 order[counter], 130 sampler.getPropertyAsString(TestElement.NAME)); 131 } 132 counter++; 133 } 134 } 135 } 136 137 public void testProcessing2() throws Exception 138 { 139 GenericController controller = new GenericController(); 140 GenericController sub_1 = new OnceOnlyController(); 141 sub_1.addTestElement(new TestSampler("one")); 142 sub_1.addTestElement(new TestSampler("two")); 143 controller.addTestElement(sub_1); 144 controller.addTestElement(new TestSampler("three")); 145 LoopController sub_2 = new LoopController(); 146 sub_2.setLoops(3); 147 OnceOnlyController sub_3 = new OnceOnlyController(); 148 sub_2.addTestElement(new TestSampler("four")); 149 sub_3.addTestElement(new TestSampler("five")); 150 sub_3.addTestElement(new TestSampler("six")); 151 sub_2.addTestElement(sub_3); 152 sub_2.addIterationListener(sub_3); 153 sub_2.addTestElement(new TestSampler("seven")); 154 controller.addTestElement(sub_2); 155 String [] interleaveOrder = new String [] { "one", "two" }; 156 String [] order = 157 new String [] { 158 "", 159 "", 160 "three", 161 "four", 162 "five", 163 "six", 164 "seven", 165 "four", 166 "seven", 167 "four", 168 "seven" }; 169 int counter = 11; 170 controller.initialize(); 171 for (int i = 0; i < 4; i++) 172 { 173 assertEquals(11, counter); 174 counter = 0; 175 if (i > 0) 176 { 177 counter = 2; 178 } 179 TestElement sampler = null; 180 while ((sampler = controller.next()) != null) 181 { 182 if (i == 0 && counter < 2) 183 { 184 assertEquals( 185 interleaveOrder[counter], 186 sampler.getPropertyAsString(TestElement.NAME)); 187 } 188 else 189 { 190 assertEquals( 191 order[counter], 192 sampler.getPropertyAsString(TestElement.NAME)); 193 } 194 counter++; 195 } 196 } 197 } 198 } 199 } 200
| Popular Tags
|