Search in sources :

Example 1 with Sampler

use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.

the class GenericController method nextIsAController.

/**
     * Called by {@link #next()} if the element is a Controller, and returns the
     * next sampler from the controller. If this is <code>null</code>, then
     * updates the current pointer and makes recursive call to {@link #next()}.
     * 
     * @param controller the current <em>next</em> element
     * @return the next sampler
     * @throws NextIsNullException when the end of the list has already been reached
     */
protected Sampler nextIsAController(Controller controller) throws NextIsNullException {
    Sampler sampler = controller.next();
    if (sampler == null) {
        currentReturnedNull(controller);
        sampler = next();
    }
    return sampler;
}
Also used : Sampler(org.apache.jmeter.samplers.Sampler)

Example 2 with Sampler

use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.

the class GenericController method next.

/**
     * <p>
     * Determines the next sampler to be processed.
     * </p>
     *
     * <p>
     * If {@link #isDone()} is <code>true</code>, returns null.
     * </p>
     *
     * <p>
     * Gets the list element using current pointer.
     * If this is <code>null</code>, calls {@link #nextIsNull()}.
     * </p>
     *
     * <p>
     * If the list element is a {@link Sampler}, calls {@link #nextIsASampler(Sampler)},
     * otherwise calls {@link #nextIsAController(Controller)}
     * </p>
     *
     * <p>
     * If any of the called methods throws {@link NextIsNullException}, returns <code>null</code>,
     * otherwise the value obtained above is returned.
     * </p>
     *
     * @return the next sampler or <code>null</code>
     */
@Override
public Sampler next() {
    fireIterEvents();
    log.debug("Calling next on: {}", GenericController.class);
    if (isDone()) {
        return null;
    }
    Sampler returnValue = null;
    try {
        TestElement currentElement = getCurrentElement();
        setCurrentElement(currentElement);
        if (currentElement == null) {
            returnValue = nextIsNull();
        } else {
            if (currentElement instanceof Sampler) {
                returnValue = nextIsASampler((Sampler) currentElement);
            } else {
                // must be a controller
                returnValue = nextIsAController((Controller) currentElement);
            }
        }
    } catch (NextIsNullException e) {
    // NOOP
    }
    return returnValue;
}
Also used : Sampler(org.apache.jmeter.samplers.Sampler) AbstractTestElement(org.apache.jmeter.testelement.AbstractTestElement) TestElement(org.apache.jmeter.testelement.TestElement)

Example 3 with Sampler

use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.

the class TransactionController method triggerEndOfLoop.

/**
     * @see org.apache.jmeter.control.GenericController#triggerEndOfLoop()
     */
@Override
public void triggerEndOfLoop() {
    if (!isGenerateParentSample()) {
        if (res != null) {
            res.setIdleTime(pauseTime + res.getIdleTime());
            res.sampleEnd();
            res.setSuccessful(TRUE.equals(JMeterContextService.getContext().getVariables().get(JMeterThread.LAST_SAMPLE_OK)));
            res.setResponseMessage(TransactionController.NUMBER_OF_SAMPLES_IN_TRANSACTION_PREFIX + calls + ", number of failing samples : " + noFailingSamples);
            notifyListeners();
        }
    } else {
        Sampler subSampler = transactionSampler.getSubSampler();
        // update them with SubSamplerResult
        if (subSampler instanceof TransactionSampler) {
            TransactionSampler tc = (TransactionSampler) subSampler;
            transactionSampler.addSubSamplerResult(tc.getTransactionResult());
        }
        transactionSampler.setTransactionDone();
        // This transaction is done
        transactionSampler = null;
    }
    super.triggerEndOfLoop();
}
Also used : Sampler(org.apache.jmeter.samplers.Sampler)

Example 4 with Sampler

use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.

the class CompoundVariable method execute.

public String execute() {
    if (isDynamic || permanentResults == null) {
        JMeterContext context = JMeterContextService.getContext();
        SampleResult previousResult = context.getPreviousResult();
        Sampler currentSampler = context.getCurrentSampler();
        return execute(previousResult, currentSampler);
    }
    // $NON-NLS-1$
    return permanentResults;
}
Also used : JMeterContext(org.apache.jmeter.threads.JMeterContext) Sampler(org.apache.jmeter.samplers.Sampler) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 5 with Sampler

use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.

the class AddThinkTimeBetweenEachStep method addThinkTimeToChildren.

/**
     * Add Think Time to children of parentNode
     * @param guiPackage {@link GuiPackage}
     * @param parentNode Parent node of elements on which we add think times
     * @throws IllegalUserActionException 
     */
private void addThinkTimeToChildren(GuiPackage guiPackage, JMeterTreeNode parentNode) throws IllegalUserActionException {
    guiPackage.updateCurrentNode();
    boolean insertThinkTime = false;
    try {
        int index = 0;
        while (true) {
            if (index == parentNode.getChildCount()) {
                index++;
                break;
            }
            JMeterTreeNode childNode = (JMeterTreeNode) parentNode.getChildAt(index);
            Object userObject = childNode.getUserObject();
            if (userObject instanceof Sampler || userObject instanceof Controller) {
                insertThinkTime = true;
            }
            if (insertThinkTime) {
                JMeterTreeNode[] nodes = createThinkTime(guiPackage, parentNode);
                if (nodes.length != 2) {
                    throw new IllegalArgumentException("Invalid Think Time, expected 2 nodes, got:" + nodes.length);
                }
                index++;
                addNodesToTreeHierachically(guiPackage, parentNode, nodes, index);
                insertThinkTime = false;
            }
            index++;
        }
    } catch (Exception ex) {
        throw new IllegalUserActionException("Cannot add think times", ex);
    }
}
Also used : Sampler(org.apache.jmeter.samplers.Sampler) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) Controller(org.apache.jmeter.control.Controller) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException)

Aggregations

Sampler (org.apache.jmeter.samplers.Sampler)33 SampleResult (org.apache.jmeter.samplers.SampleResult)11 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)9 JMeterContext (org.apache.jmeter.threads.JMeterContext)9 Test (org.junit.Test)9 TransactionSampler (org.apache.jmeter.control.TransactionSampler)6 DebugSampler (org.apache.jmeter.sampler.DebugSampler)6 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)5 Controller (org.apache.jmeter.control.Controller)3 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)3 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)3 JMeterStopTestException (org.apache.jorphan.util.JMeterStopTestException)3 JMeterStopTestNowException (org.apache.jorphan.util.JMeterStopTestNowException)3 JMeterStopThreadException (org.apache.jorphan.util.JMeterStopThreadException)3 Logger (org.slf4j.Logger)3 Properties (java.util.Properties)2 Argument (org.apache.jmeter.config.Argument)2 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)2 TestElement (org.apache.jmeter.testelement.TestElement)2 Cache (com.github.benmanes.caffeine.cache.Cache)1