Search in sources :

Example 51 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class ProxyControl method placeSampler.

private void placeSampler(final HTTPSamplerBase sampler, final TestElement[] testElements, JMeterTreeNode myTarget) {
    try {
        final JMeterTreeModel treeModel = getJmeterTreeModel();
        boolean firstInBatch = false;
        long now = System.currentTimeMillis();
        long deltaT = now - lastTime;
        int cachedGroupingMode = groupingMode;
        if (deltaT > SAMPLE_GAP) {
            if (!myTarget.isLeaf() && cachedGroupingMode == GROUPING_ADD_SEPARATORS) {
                addDivider(treeModel, myTarget);
            }
            if (cachedGroupingMode == GROUPING_IN_SIMPLE_CONTROLLERS) {
                addSimpleController(treeModel, myTarget, sampler.getName());
            }
            if (cachedGroupingMode == GROUPING_IN_TRANSACTION_CONTROLLERS) {
                addTransactionController(treeModel, myTarget, sampler.getName());
            }
            // Remember this was first in its batch
            firstInBatch = true;
        }
        if (lastTime == 0) {
            // Decent value for timers
            deltaT = 0;
        }
        lastTime = now;
        if (cachedGroupingMode == GROUPING_STORE_FIRST_ONLY) {
            if (!firstInBatch) {
                // Huh! don't store this one!
                return;
            }
            // If we're not storing subsequent samplers, we'll need the
            // first sampler to do all the work...:
            sampler.setFollowRedirects(true);
            sampler.setImageParser(true);
        }
        if (cachedGroupingMode == GROUPING_IN_SIMPLE_CONTROLLERS || cachedGroupingMode == GROUPING_IN_TRANSACTION_CONTROLLERS) {
            // sampler there:
            for (int i = myTarget.getChildCount() - 1; i >= 0; i--) {
                JMeterTreeNode c = (JMeterTreeNode) myTarget.getChildAt(i);
                if (c.getTestElement() instanceof GenericController) {
                    myTarget = c;
                    break;
                }
            }
        }
        final long deltaTFinal = deltaT;
        final boolean firstInBatchFinal = firstInBatch;
        final JMeterTreeNode myTargetFinal = myTarget;
        JMeterUtils.runSafe(true, () -> {
            try {
                final JMeterTreeNode newNode = treeModel.addComponent(sampler, myTargetFinal);
                if (firstInBatchFinal) {
                    if (addAssertions) {
                        addAssertion(treeModel, newNode);
                    }
                    addTimers(treeModel, newNode, deltaTFinal);
                }
                if (testElements != null) {
                    for (TestElement testElement : testElements) {
                        if (isAddableTestElement(testElement)) {
                            treeModel.addComponent(testElement, newNode);
                        }
                    }
                }
            } catch (IllegalUserActionException e) {
                log.error("Error placing sampler", e);
                JMeterUtils.reportErrorToUser(e.getMessage());
            }
        });
    } catch (Exception e) {
        log.error("Error placing sampler", e);
        JMeterUtils.reportErrorToUser(e.getMessage());
    }
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) GenericController(org.apache.jmeter.control.GenericController) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) CertificateExpiredException(java.security.cert.CertificateExpiredException) GeneralSecurityException(java.security.GeneralSecurityException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedCachePatternException(org.apache.oro.text.MalformedCachePatternException) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) InvalidVariableException(org.apache.jmeter.functions.InvalidVariableException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException)

Example 52 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class TestLoopController method testProcessing.

@Test
public void testProcessing() throws Exception {
    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"));
    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[] order = new String[] { "one", "two", "three", "four", "five", "six", "seven", "four", "five", "six", "seven", "four", "five", "six", "seven" };
    int counter = 15;
    controller.setRunningVersion(true);
    sub_1.setRunningVersion(true);
    sub_2.setRunningVersion(true);
    sub_3.setRunningVersion(true);
    controller.initialize();
    for (int i = 0; i < 2; i++) {
        assertEquals(15, counter);
        counter = 0;
        TestElement sampler = null;
        while ((sampler = controller.next()) != null) {
            assertEquals(order[counter++], sampler.getName());
        }
    }
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Example 53 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class TestOnceOnlyController method testInsideInnerLoop.

@Test
public void testInsideInnerLoop() throws Exception {
    // Test plan with OnlyOnceController inside inner loop
    // Set up the test plan
    LoopController controller = new LoopController();
    final int outerLoopCount = 4;
    controller.setLoops(outerLoopCount);
    // OnlyOnce samples
    OnceOnlyController sub_1 = new OnceOnlyController();
    sub_1.addTestElement(new TestSampler("one"));
    sub_1.addTestElement(new TestSampler("two"));
    controller.addTestElement(sub_1);
    controller.addIterationListener(sub_1);
    // Outer sample
    controller.addTestElement(new TestSampler("three"));
    // Inner loop
    LoopController sub_2 = new LoopController();
    final int innerLoopCount = 3;
    sub_2.setLoops(innerLoopCount);
    // Sample in inner loop
    sub_2.addTestElement(new TestSampler("four"));
    // OnlyOnce inside inner loop
    OnceOnlyController sub_3 = new OnceOnlyController();
    sub_3.addTestElement(new TestSampler("five"));
    sub_3.addTestElement(new TestSampler("six"));
    sub_2.addTestElement(sub_3);
    sub_2.addIterationListener(sub_3);
    // Sample in inner loop
    sub_2.addTestElement(new TestSampler("seven"));
    controller.addTestElement(sub_2);
    // Compute the expected sample names
    String[] onlyOnceOrder = new String[] { "one", "two" };
    String[] order = new String[] { "three", "four", "five", "six", "seven", "four", "seven", "four", "seven" };
    // Outer only once + ("three" + "only once five and six" + ("four" + "seven") * innerLoopCount) * outerLoopCount;  
    int expectedNoSamples = 2 + (1 + 2 + (1 + 1) * innerLoopCount) * outerLoopCount;
    String[] expectedSamples = new String[expectedNoSamples];
    // The only once samples
    System.arraycopy(onlyOnceOrder, 0, expectedSamples, 0, onlyOnceOrder.length);
    // The outer sample and the inner loop samples
    final int onceOnlySamples = onlyOnceOrder.length;
    for (int i = 0; i < order.length * outerLoopCount; i++) {
        expectedSamples[onceOnlySamples + i] = order[i % order.length];
    }
    // Execute the test pan
    controller.setRunningVersion(true);
    sub_1.setRunningVersion(true);
    sub_2.setRunningVersion(true);
    sub_3.setRunningVersion(true);
    controller.initialize();
    int counter = 0;
    TestElement sampler = null;
    while ((sampler = controller.next()) != null) {
        assertEquals(expectedSamples[counter], sampler.getPropertyAsString(TestElement.NAME));
        counter++;
    }
    assertEquals(expectedNoSamples, counter);
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Example 54 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class TestOnceOnlyController method testInOuterLoop.

@Test
public void testInOuterLoop() throws Exception {
    // Set up the test plan
    LoopController controller = new LoopController();
    final int outerLoopCount = 4;
    controller.setLoops(outerLoopCount);
    // OnlyOnce samples
    OnceOnlyController sub_1 = new OnceOnlyController();
    sub_1.addTestElement(new TestSampler("one"));
    sub_1.addTestElement(new TestSampler("two"));
    controller.addTestElement(sub_1);
    controller.addIterationListener(sub_1);
    // Outer sample
    controller.addTestElement(new TestSampler("three"));
    // Inner loop
    LoopController sub_2 = new LoopController();
    final int innerLoopCount = 3;
    sub_2.setLoops(innerLoopCount);
    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);
    // Sample in inner loop
    sub_2.addTestElement(new TestSampler("seven"));
    controller.addTestElement(sub_2);
    // Compute the expected sample names
    String[] onlyOnceOrder = new String[] { "one", "two" };
    String[] order = new String[] { "three", "four", "five", "six", "seven", "four", "five", "six", "seven", "four", "five", "six", "seven" };
    // Outer only once + ("three" + ("four" + "five" + "six" + "seven") * innerLoopCount) * outerLoopCount;  
    int expectedNoSamples = 2 + (1 + (3 + 1) * innerLoopCount) * outerLoopCount;
    String[] expectedSamples = new String[expectedNoSamples];
    // The only once samples
    System.arraycopy(onlyOnceOrder, 0, expectedSamples, 0, onlyOnceOrder.length);
    // The outer sample and the inner loop samples
    final int onceOnlySamples = onlyOnceOrder.length;
    for (int i = 0; i < order.length * outerLoopCount; i++) {
        expectedSamples[onceOnlySamples + i] = order[i % order.length];
    }
    // Execute the test pan
    controller.setRunningVersion(true);
    sub_1.setRunningVersion(true);
    sub_2.setRunningVersion(true);
    sub_3.setRunningVersion(true);
    controller.initialize();
    int counter = 0;
    TestElement sampler = null;
    while ((sampler = controller.next()) != null) {
        assertEquals(expectedSamples[counter], sampler.getPropertyAsString(TestElement.NAME));
        counter++;
    }
    assertEquals(expectedNoSamples, counter);
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Example 55 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class TestRandomController method testRandomOneElement.

@Test
public void testRandomOneElement() {
    RandomController roc = new RandomController();
    roc.addTestElement(new TestSampler("zero"));
    TestElement sampler = null;
    List<String> usedSamplers = new ArrayList<>();
    roc.initialize();
    while ((sampler = roc.next()) != null) {
        String samplerName = sampler.getName();
        if (usedSamplers.contains(samplerName)) {
            assertTrue("Duplicate sampler returned from next()", false);
        }
        usedSamplers.add(samplerName);
    }
    assertEquals(1, usedSamplers.size());
}
Also used : ArrayList(java.util.ArrayList) TestSampler(org.apache.jmeter.junit.stubs.TestSampler) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Aggregations

TestElement (org.apache.jmeter.testelement.TestElement)83 Test (org.junit.Test)27 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)26 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)21 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)18 TestPlan (org.apache.jmeter.testelement.TestPlan)12 ArrayList (java.util.ArrayList)9 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)9 StringProperty (org.apache.jmeter.testelement.property.StringProperty)7 Controller (org.apache.jmeter.control.Controller)6 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)6 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)6 TreePath (javax.swing.tree.TreePath)5 GuiPackage (org.apache.jmeter.gui.GuiPackage)5 ActionEvent (java.awt.event.ActionEvent)4 IOException (java.io.IOException)4 LinkedList (java.util.LinkedList)4 Arguments (org.apache.jmeter.config.Arguments)4 WorkBench (org.apache.jmeter.testelement.WorkBench)4 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)4