Search in sources :

Example 1 with TestSampler

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();
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Example 2 with TestSampler

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();
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Example 3 with TestSampler

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();
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Example 4 with TestSampler

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++;
        }
    }
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.jupiter.api.Test)

Example 5 with TestSampler

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++;
        }
    }
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.jupiter.api.Test)

Aggregations

TestSampler (org.apache.jmeter.junit.stubs.TestSampler)46 Test (org.junit.jupiter.api.Test)31 TestElement (org.apache.jmeter.testelement.TestElement)21 Sampler (org.apache.jmeter.samplers.Sampler)8 Test (org.junit.Test)8 JMeterContext (org.apache.jmeter.threads.JMeterContext)7 DebugSampler (org.apache.jmeter.sampler.DebugSampler)6 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)2 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)2 ReplaceStringWithFunctions (org.apache.jmeter.engine.util.ReplaceStringWithFunctions)2 ValueReplacer (org.apache.jmeter.engine.util.ValueReplacer)2 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)2 StringProperty (org.apache.jmeter.testelement.property.StringProperty)2 JMeterSerialTest (org.apache.jorphan.test.JMeterSerialTest)2 BugId (org.apache.jmeter.testkit.BugId)1 ThreadGroup (org.apache.jmeter.threads.ThreadGroup)1