use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestOnceOnlyController method testInsideInnerLoop.
@Test
public void testInsideInnerLoop() throws Exception {
// Test plan with OnlyOnceController inside inner loop
// Set up the test plan
LoopController controller = new LoopController();
final int outerLoopCount = 4;
controller.setLoops(outerLoopCount);
// OnlyOnce samples
OnceOnlyController sub_1 = new OnceOnlyController();
sub_1.addTestElement(new TestSampler("one"));
sub_1.addTestElement(new TestSampler("two"));
controller.addTestElement(sub_1);
controller.addIterationListener(sub_1);
// Outer sample
controller.addTestElement(new TestSampler("three"));
// Inner loop
LoopController sub_2 = new LoopController();
final int innerLoopCount = 3;
sub_2.setLoops(innerLoopCount);
// Sample in inner loop
sub_2.addTestElement(new TestSampler("four"));
// OnlyOnce inside inner loop
OnceOnlyController sub_3 = new OnceOnlyController();
sub_3.addTestElement(new TestSampler("five"));
sub_3.addTestElement(new TestSampler("six"));
sub_2.addTestElement(sub_3);
sub_2.addIterationListener(sub_3);
// Sample in inner loop
sub_2.addTestElement(new TestSampler("seven"));
controller.addTestElement(sub_2);
// Compute the expected sample names
String[] onlyOnceOrder = new String[] { "one", "two" };
String[] order = new String[] { "three", "four", "five", "six", "seven", "four", "seven", "four", "seven" };
// Outer only once + ("three" + "only once five and six" + ("four" + "seven") * innerLoopCount) * outerLoopCount;
int expectedNoSamples = 2 + (1 + 2 + (1 + 1) * innerLoopCount) * outerLoopCount;
String[] expectedSamples = new String[expectedNoSamples];
// The only once samples
System.arraycopy(onlyOnceOrder, 0, expectedSamples, 0, onlyOnceOrder.length);
// The outer sample and the inner loop samples
final int onceOnlySamples = onlyOnceOrder.length;
for (int i = 0; i < order.length * outerLoopCount; i++) {
expectedSamples[onceOnlySamples + i] = order[i % order.length];
}
// Execute the test pan
controller.setRunningVersion(true);
sub_1.setRunningVersion(true);
sub_2.setRunningVersion(true);
sub_3.setRunningVersion(true);
controller.initialize();
int counter = 0;
TestElement sampler = null;
while ((sampler = controller.next()) != null) {
assertEquals(expectedSamples[counter], sampler.getPropertyAsString(TestElement.NAME));
counter++;
}
assertEquals(expectedNoSamples, counter);
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestOnceOnlyController method testInOuterLoop.
@Test
public void testInOuterLoop() throws Exception {
// Set up the test plan
LoopController controller = new LoopController();
final int outerLoopCount = 4;
controller.setLoops(outerLoopCount);
// OnlyOnce samples
OnceOnlyController sub_1 = new OnceOnlyController();
sub_1.addTestElement(new TestSampler("one"));
sub_1.addTestElement(new TestSampler("two"));
controller.addTestElement(sub_1);
controller.addIterationListener(sub_1);
// Outer sample
controller.addTestElement(new TestSampler("three"));
// Inner loop
LoopController sub_2 = new LoopController();
final int innerLoopCount = 3;
sub_2.setLoops(innerLoopCount);
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);
// Sample in inner loop
sub_2.addTestElement(new TestSampler("seven"));
controller.addTestElement(sub_2);
// Compute the expected sample names
String[] onlyOnceOrder = new String[] { "one", "two" };
String[] order = new String[] { "three", "four", "five", "six", "seven", "four", "five", "six", "seven", "four", "five", "six", "seven" };
// Outer only once + ("three" + ("four" + "five" + "six" + "seven") * innerLoopCount) * outerLoopCount;
int expectedNoSamples = 2 + (1 + (3 + 1) * innerLoopCount) * outerLoopCount;
String[] expectedSamples = new String[expectedNoSamples];
// The only once samples
System.arraycopy(onlyOnceOrder, 0, expectedSamples, 0, onlyOnceOrder.length);
// The outer sample and the inner loop samples
final int onceOnlySamples = onlyOnceOrder.length;
for (int i = 0; i < order.length * outerLoopCount; i++) {
expectedSamples[onceOnlySamples + i] = order[i % order.length];
}
// Execute the test pan
controller.setRunningVersion(true);
sub_1.setRunningVersion(true);
sub_2.setRunningVersion(true);
sub_3.setRunningVersion(true);
controller.initialize();
int counter = 0;
TestElement sampler = null;
while ((sampler = controller.next()) != null) {
assertEquals(expectedSamples[counter], sampler.getPropertyAsString(TestElement.NAME));
counter++;
}
assertEquals(expectedNoSamples, counter);
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestRandomController method testRandomOneElement.
@Test
public void testRandomOneElement() {
RandomController roc = new RandomController();
roc.addTestElement(new TestSampler("zero"));
TestElement sampler = null;
List<String> usedSamplers = new ArrayList<>();
roc.initialize();
while ((sampler = roc.next()) != null) {
String samplerName = sampler.getName();
if (usedSamplers.contains(samplerName)) {
assertTrue("Duplicate sampler returned from next()", false);
}
usedSamplers.add(samplerName);
}
assertEquals(1, usedSamplers.size());
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestRandomController method testRandomOrder.
@Test
public void testRandomOrder() {
testLog.debug("Testing RandomController");
RandomController roc = new RandomController();
roc.addTestElement(new TestSampler("zero"));
roc.addTestElement(new TestSampler("one"));
roc.addTestElement(new TestSampler("two"));
roc.addTestElement(new TestSampler("three"));
TestElement sampler = null;
List<String> usedSamplers = new ArrayList<>();
roc.initialize();
while ((sampler = roc.next()) != null) {
String samplerName = sampler.getName();
if (usedSamplers.contains(samplerName)) {
assertTrue("Duplicate sampler returned from next()", false);
}
usedSamplers.add(samplerName);
}
assertEquals(1, usedSamplers.size());
assertTrue(Arrays.asList("zero", "one", "two", "three").contains(usedSamplers.get(0)));
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestRandomOrderController method testRandomOrderOneElement.
@Test
public void testRandomOrderOneElement() {
RandomOrderController roc = new RandomOrderController();
roc.addTestElement(new TestSampler("zero"));
TestElement sampler = null;
List<String> usedSamplers = new ArrayList<>();
roc.initialize();
while ((sampler = roc.next()) != null) {
String samplerName = sampler.getName();
if (usedSamplers.contains(samplerName)) {
assertTrue("Duplicate sampler returned from next()", false);
}
usedSamplers.add(samplerName);
}
assertEquals("All samplers were returned", 1, usedSamplers.size());
}
Aggregations