use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestIfController method testStackOverflow.
/**
* See Bug 56160
*
* @throws Exception
* if something fails
*/
@Test
public void testStackOverflow() throws Exception {
LoopController controller = new LoopController();
controller.setLoops(1);
controller.setContinueForever(false);
IfController ifCont = new IfController("true==false");
ifCont.setUseExpression(false);
ifCont.setEvaluateAll(false);
WhileController whileController = new WhileController();
whileController.setCondition("${__javaScript(\"true\" != \"false\")}");
whileController.addTestElement(new TestSampler("Sample1"));
controller.addTestElement(ifCont);
ifCont.addTestElement(whileController);
Sampler sampler = null;
int counter = 0;
controller.initialize();
controller.setRunningVersion(true);
ifCont.setRunningVersion(true);
whileController.setRunningVersion(true);
try {
while ((sampler = controller.next()) != null) {
sampler.sample(null);
counter++;
}
assertEquals(0, counter);
} catch (StackOverflowError e) {
fail("Stackoverflow occurred in testStackOverflow");
}
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestIfController method testProcessingTrue.
@Test
public void testProcessingTrue() throws Exception {
LoopController controller = new LoopController();
controller.setLoops(2);
controller.addTestElement(new TestSampler("Sample1"));
IfController ifCont = new IfController("true==true");
ifCont.setEvaluateAll(true);
ifCont.addTestElement(new TestSampler("Sample2"));
TestSampler sample3 = new TestSampler("Sample3");
ifCont.addTestElement(sample3);
controller.addTestElement(ifCont);
String[] order = new String[] { "Sample1", "Sample2", "Sample3", "Sample1", "Sample2", "Sample3" };
int counter = 0;
controller.initialize();
controller.setRunningVersion(true);
ifCont.setRunningVersion(true);
Sampler sampler = null;
while ((sampler = controller.next()) != null) {
sampler.sample(null);
assertEquals(order[counter], sampler.getName());
counter++;
}
assertEquals(counter, 6);
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestInterleaveControl method testProcessing.
@Test
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.getName());
} else {
assertEquals(order[counter], sampler.getName());
}
counter++;
}
}
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestInterleaveControl method testProcessing6.
@Test
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.getName());
counter++;
}
}
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestOnceOnlyController method testProcessing2.
@Test
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.getName());
} else {
assertEquals(order[counter], sampler.getName());
}
counter++;
}
}
}
Aggregations