Search in sources :

Example 31 with TestSampler

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

Example 32 with TestSampler

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

Example 33 with TestSampler

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

Example 34 with TestSampler

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

Example 35 with TestSampler

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

Aggregations

TestSampler (org.apache.jmeter.junit.stubs.TestSampler)43 Test (org.junit.Test)36 TestElement (org.apache.jmeter.testelement.TestElement)21 Sampler (org.apache.jmeter.samplers.Sampler)7 DebugSampler (org.apache.jmeter.sampler.DebugSampler)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 JMeterContext (org.apache.jmeter.threads.JMeterContext)2 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)2