use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestThroughputController method testByPercent100.
@Test
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.getName());
counter++;
}
assertEquals(counter, 150 * order.length);
counter = 0;
}
sub_1.testEnded();
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestThroughputController method testByPercentZero.
@Test
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.getName());
counter++;
}
assertEquals(counter, 150 * order.length);
counter = 0;
}
sub_1.testEnded();
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestWhileController method runTestLastFailed.
// Should behave the same for blank and LAST because success on input
private void runTestLastFailed(String s) throws Exception {
GenericController controller = new GenericController();
controller.addTestElement(new TestSampler("1"));
WhileController while_cont = new WhileController();
controller.addTestElement(while_cont);
while_cont.setCondition(s);
GenericController sub = new GenericController();
while_cont.addTestElement(sub);
sub.addTestElement(new TestSampler("2"));
sub.addTestElement(new TestSampler("3"));
controller.addTestElement(new TestSampler("4"));
setLastSampleStatus(true);
controller.initialize();
assertEquals("1", nextName(controller));
assertEquals("2", nextName(controller));
setLastSampleStatus(false);
assertEquals("3", nextName(controller));
assertEquals("4", nextName(controller));
assertNull(nextName(controller));
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestWhileController method runTestPrevFailed.
private void runTestPrevFailed(String s) throws Exception {
GenericController controller = new GenericController();
WhileController while_cont = new WhileController();
setLastSampleStatus(false);
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));
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestWhileController method testVariable1.
/*
* Generic Controller
* - before
* - While Controller ${VAR}
* - - one
* - - two
* - - Simple Controller
* - - - three
* - - - four
* - after
*/
@Test
public void testVariable1() throws Exception {
GenericController controller = new GenericController();
WhileController while_cont = new WhileController();
setLastSampleStatus(false);
while_cont.setCondition("${VAR}");
jmvars.put("VAR", "");
ValueReplacer vr = new ValueReplacer();
vr.replaceValues(while_cont);
setRunning(while_cont);
controller.addTestElement(new TestSampler("before"));
controller.addTestElement(while_cont);
while_cont.addTestElement(new TestSampler("one"));
while_cont.addTestElement(new TestSampler("two"));
GenericController simple = new GenericController();
while_cont.addTestElement(simple);
simple.addTestElement(new TestSampler("three"));
simple.addTestElement(new TestSampler("four"));
controller.addTestElement(new TestSampler("after"));
controller.initialize();
for (int i = 1; i <= 3; i++) {
assertEquals("Loop: " + i, "before", nextName(controller));
assertEquals("Loop: " + i, "one", nextName(controller));
assertEquals("Loop: " + i, "two", nextName(controller));
assertEquals("Loop: " + i, "three", nextName(controller));
assertEquals("Loop: " + i, "four", nextName(controller));
assertEquals("Loop: " + i, "after", nextName(controller));
assertNull("Loop: " + i, nextName(controller));
}
// Should not enter the loop
jmvars.put("VAR", "LAST");
for (int i = 1; i <= 3; i++) {
assertEquals("Loop: " + i, "before", nextName(controller));
assertEquals("Loop: " + i, "after", nextName(controller));
assertNull("Loop: " + i, nextName(controller));
}
jmvars.put("VAR", "");
for (int i = 1; i <= 3; i++) {
assertEquals("Loop: " + i, "before", nextName(controller));
if (i == 1) {
assertEquals("Loop: " + i, "one", nextName(controller));
assertEquals("Loop: " + i, "two", nextName(controller));
assertEquals("Loop: " + i, "three", nextName(controller));
// Should not enter the loop next time
jmvars.put("VAR", "LAST");
assertEquals("Loop: " + i, "four", nextName(controller));
}
assertEquals("Loop: " + i, "after", nextName(controller));
assertNull("Loop: " + i, nextName(controller));
}
}
Aggregations