use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestThroughputController method testByNumberZero.
@Test
public void testByNumberZero() throws Exception {
ThroughputController sub_1 = new ThroughputController();
sub_1.setStyle(ThroughputController.BYNUMBER);
sub_1.setMaxThroughput(0);
sub_1.addTestElement(new TestSampler("one"));
sub_1.addTestElement(new TestSampler("two"));
LoopController controller = new LoopController();
controller.setLoops(5);
controller.addTestElement(new TestSampler("zero"));
controller.addTestElement(sub_1);
controller.addIterationListener(sub_1);
controller.addTestElement(new TestSampler("three"));
String[] order = new String[] { "zero", "three", "zero", "three", "zero", "three", "zero", "three", "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], sampler.getName());
counter++;
}
assertEquals(counter, order.length);
counter = 0;
}
sub_1.testEnded();
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestThroughputController method testByPercent33.
@Test
public void testByPercent33() throws Exception {
ThroughputController sub_1 = new ThroughputController();
sub_1.setStyle(ThroughputController.BYPERCENT);
sub_1.setPercentThroughput(33.33f);
sub_1.addTestElement(new TestSampler("one"));
sub_1.addTestElement(new TestSampler("two"));
LoopController controller = new LoopController();
controller.setLoops(6);
controller.addTestElement(new TestSampler("zero"));
controller.addTestElement(sub_1);
controller.addIterationListener(sub_1);
controller.addTestElement(new TestSampler("three"));
// Expected results established using the DDA
// algorithm (see
// http://www.siggraph.org/education/materials/HyperGraph/scanline/outprims/drawline.htm):
String[] order = new String[] { // 0/1 vs. 1/1 -> 0 is
"zero", // 0/2 vs. 1/2 -> 50.0 is closer to
"three", // 0/2 vs. 1/2 -> 50.0 is closer to
"zero", // 1/3 vs. 2/3 -> 33.33 is
"one", // 1/3 vs. 2/3 -> 33.33 is
"two", // 1/3 vs. 2/3 -> 33.33 is
"three", // 1/3 vs. 2/3 -> 33.33 is
"zero", // 1/4 vs. 2/4 -> 25.0 is closer to
"three", // 1/4 vs. 2/4 -> 25.0 is closer to
"zero", // 1/5 vs. 2/5 -> 40.0 is closer to
"three", // 1/5 vs. 2/5 -> 40.0 is closer to
"zero", // 2/6 vs. 3/6 -> 33.33 is
"one", // 2/6 vs. 3/6 -> 33.33 is
"two", // 2/6 vs. 3/6 -> 33.33 is
"three", // 2/6 vs. 3/6 -> 33.33 is
"zero", // closer to 33.33
"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], sampler.getName());
counter++;
}
assertEquals(counter, order.length);
counter = 0;
}
sub_1.testEnded();
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestThroughputController method testByNumber.
@Test
public void testByNumber() throws Exception {
ThroughputController sub_1 = new ThroughputController();
sub_1.setStyle(ThroughputController.BYNUMBER);
sub_1.setMaxThroughput(2);
sub_1.addTestElement(new TestSampler("one"));
sub_1.addTestElement(new TestSampler("two"));
LoopController loop = new LoopController();
loop.setLoops(5);
loop.addTestElement(new TestSampler("zero"));
loop.addTestElement(sub_1);
loop.addIterationListener(sub_1);
loop.addTestElement(new TestSampler("three"));
LoopController test = new LoopController();
test.setLoops(2);
test.addTestElement(loop);
String[] order = new String[] { "zero", "one", "two", "three", "zero", "one", "two", "three", "zero", "three", "zero", "three", "zero", "three", "zero", "three", "zero", "three", "zero", "three", "zero", "three", "zero", "three" };
sub_1.testStarted();
test.setRunningVersion(true);
sub_1.setRunningVersion(true);
loop.setRunningVersion(true);
test.initialize();
for (int counter = 0; counter < order.length; counter++) {
TestElement sampler = test.next();
assertNotNull(sampler);
assertEquals("Counter: " + counter, order[counter], sampler.getName());
}
assertNull(test.next());
sub_1.testEnded();
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestGenericController method testProcessing.
@Test
public void testProcessing() throws Exception {
testLog.debug("Testing Generic Controller");
GenericController controller = new GenericController();
GenericController sub_1 = new GenericController();
sub_1.addTestElement(new TestSampler("one"));
sub_1.addTestElement(new TestSampler("two"));
controller.addTestElement(sub_1);
controller.addTestElement(new TestSampler("three"));
GenericController sub_2 = new GenericController();
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[] order = new String[] { "one", "two", "three", "four", "five", "six", "seven" };
int counter = 7;
controller.initialize();
for (int i = 0; i < 2; i++) {
assertEquals(7, counter);
counter = 0;
TestElement sampler = null;
while ((sampler = controller.next()) != null) {
assertEquals(order[counter++], sampler.getName());
}
}
}
use of org.apache.jmeter.junit.stubs.TestSampler in project jmeter by apache.
the class TestIfController method testEvaluateAllChildrenWithoutSubController.
/**
* Test false return on sample3 (sample4 doesn't execute)
*
* @throws Exception
* if something fails
*/
@Test
public void testEvaluateAllChildrenWithoutSubController() throws Exception {
LoopController controller = new LoopController();
controller.setLoops(2);
controller.addTestElement(new TestSampler("Sample1"));
IfController ifCont = new IfController("true==true");
ifCont.setEvaluateAll(true);
controller.addTestElement(ifCont);
ifCont.addTestElement(new TestSampler("Sample2"));
TestSampler sample3 = new TestSampler("Sample3");
ifCont.addTestElement(sample3);
TestSampler sample4 = new TestSampler("Sample4");
ifCont.addTestElement(sample4);
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);
if (sampler.getName().equals("Sample3")) {
ifCont.setCondition("true==false");
}
assertEquals(order[counter], sampler.getName());
counter++;
}
assertEquals(counter, 6);
}
Aggregations