Search in sources :

Example 6 with Sampler

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

the class AbstractFunction method execute.

public String execute() throws InvalidVariableException {
    JMeterContext context = JMeterContextService.getContext();
    SampleResult previousResult = context.getPreviousResult();
    Sampler currentSampler = context.getCurrentSampler();
    return execute(previousResult, currentSampler);
}
Also used : JMeterContext(org.apache.jmeter.threads.JMeterContext) Sampler(org.apache.jmeter.samplers.Sampler) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 7 with Sampler

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

the class TestCompiler method subtractNode.

/** {@inheritDoc} */
@Override
public void subtractNode() {
    if (log.isDebugEnabled()) {
        log.debug("Subtracting node, stack size = {}", stack.size());
    }
    TestElement child = stack.getLast();
    trackIterationListeners(stack);
    if (child instanceof Sampler) {
        saveSamplerConfigs((Sampler) child);
    } else if (child instanceof TransactionController) {
        saveTransactionControllerConfigs((TransactionController) child);
    }
    stack.removeLast();
    if (!stack.isEmpty()) {
        TestElement parent = stack.getLast();
        boolean duplicate = false;
        // Bug 53750: this condition used to be in ObjectPair#addTestElements()
        if (parent instanceof Controller && (child instanceof Sampler || child instanceof Controller)) {
            if (parent instanceof TestCompilerHelper) {
                TestCompilerHelper te = (TestCompilerHelper) parent;
                duplicate = !te.addTestElementOnce(child);
            } else {
                // this is only possible for 3rd party controllers by default
                ObjectPair pair = new ObjectPair(child, parent);
                synchronized (PAIRING) {
                    // Called from multiple threads
                    if (!PAIRING.contains(pair)) {
                        parent.addTestElement(child);
                        PAIRING.add(pair);
                    } else {
                        duplicate = true;
                    }
                }
            }
        }
        if (duplicate) {
            if (log.isWarnEnabled()) {
                log.warn("Unexpected duplicate for {} and {}", parent.getClass(), child.getClass());
            }
        }
    }
}
Also used : TransactionSampler(org.apache.jmeter.control.TransactionSampler) Sampler(org.apache.jmeter.samplers.Sampler) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) TransactionController(org.apache.jmeter.control.TransactionController) Controller(org.apache.jmeter.control.Controller) TransactionController(org.apache.jmeter.control.TransactionController)

Example 8 with Sampler

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

the class JMeterThread method triggerEndOfLoopOnParentControllers.

/**
     * Trigger end of loop on parent controllers up to Thread Group
     * @param sam Sampler Base sampler
     * @param threadContext 
     */
private void triggerEndOfLoopOnParentControllers(Sampler sam, JMeterContext threadContext) {
    TransactionSampler transactionSampler = null;
    if (sam instanceof TransactionSampler) {
        transactionSampler = (TransactionSampler) sam;
    }
    Sampler realSampler = findRealSampler(sam);
    if (realSampler == null) {
        throw new IllegalStateException("Got null subSampler calling findRealSampler for:" + (sam != null ? sam.getName() : "null") + ", sam:" + sam);
    }
    // Find parent controllers of current sampler
    FindTestElementsUpToRootTraverser pathToRootTraverser = new FindTestElementsUpToRootTraverser(realSampler);
    testTree.traverse(pathToRootTraverser);
    // Trigger end of loop condition on all parent controllers of current sampler
    List<Controller> controllersToReinit = pathToRootTraverser.getControllersToRoot();
    for (Controller parentController : controllersToReinit) {
        if (parentController instanceof AbstractThreadGroup) {
            AbstractThreadGroup tg = (AbstractThreadGroup) parentController;
            tg.startNextLoop();
        } else {
            parentController.triggerEndOfLoop();
        }
    }
    // then we still need to report the Transaction in error (and create the sample result)
    if (transactionSampler != null) {
        SamplePackage transactionPack = compiler.configureTransactionSampler(transactionSampler);
        doEndTransactionSampler(transactionSampler, null, transactionPack, threadContext);
    }
}
Also used : TransactionSampler(org.apache.jmeter.control.TransactionSampler) Sampler(org.apache.jmeter.samplers.Sampler) Controller(org.apache.jmeter.control.Controller) TransactionSampler(org.apache.jmeter.control.TransactionSampler)

Example 9 with Sampler

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

the class BSFTestElement method initManager.

protected void initManager(BSFManager mgr) throws BSFException {
    final String label = getName();
    final String fileName = getFilename();
    final String scriptParameters = getParameters();
    // Use actual class name for log
    final Logger logger = LoggerFactory.getLogger(getClass());
    // $NON-NLS-1$
    mgr.declareBean("log", logger, Logger.class);
    // $NON-NLS-1$
    mgr.declareBean("Label", label, String.class);
    // $NON-NLS-1$
    mgr.declareBean("FileName", fileName, String.class);
    // $NON-NLS-1$
    mgr.declareBean("Parameters", scriptParameters, String.class);
    //$NON-NLS-1$
    String[] args = JOrphanUtils.split(scriptParameters, " ");
    //$NON-NLS-1$
    mgr.declareBean("args", args, args.getClass());
    // Add variables for access to context and variables
    JMeterContext jmctx = JMeterContextService.getContext();
    JMeterVariables vars = jmctx.getVariables();
    Properties props = JMeterUtils.getJMeterProperties();
    // $NON-NLS-1$
    mgr.declareBean("ctx", jmctx, jmctx.getClass());
    // $NON-NLS-1$
    mgr.declareBean("vars", vars, vars.getClass());
    // $NON-NLS-1$
    mgr.declareBean("props", props, props.getClass());
    // For use in debugging:
    // $NON-NLS-1$
    mgr.declareBean("OUT", System.out, PrintStream.class);
    // Most subclasses will need these:
    Sampler sampler = jmctx.getCurrentSampler();
    mgr.declareBean("sampler", sampler, Sampler.class);
    SampleResult prev = jmctx.getPreviousResult();
    mgr.declareBean("prev", prev, SampleResult.class);
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) Sampler(org.apache.jmeter.samplers.Sampler) SampleResult(org.apache.jmeter.samplers.SampleResult) Logger(org.slf4j.Logger) Properties(java.util.Properties)

Example 10 with Sampler

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

the class JMeterThread method interrupt.

/** {@inheritDoc} */
@Override
public boolean interrupt() {
    try {
        interruptLock.lock();
        // fetch once; must be done under lock
        Sampler samp = currentSampler;
        if (samp instanceof Interruptible) {
            // (also protects against null)
            if (log.isWarnEnabled()) {
                log.warn("Interrupting: {} sampler: {}", threadName, samp.getName());
            }
            try {
                boolean found = ((Interruptible) samp).interrupt();
                if (!found) {
                    log.warn("No operation pending");
                }
                return found;
            } catch (Exception e) {
                // NOSONAR
                if (log.isWarnEnabled()) {
                    log.warn("Caught Exception interrupting sampler: {}", e.toString());
                }
            }
        } else if (samp != null) {
            if (log.isWarnEnabled()) {
                log.warn("Sampler is not Interruptible: {}", samp.getName());
            }
        }
    } finally {
        interruptLock.unlock();
    }
    return false;
}
Also used : Interruptible(org.apache.jmeter.samplers.Interruptible) TransactionSampler(org.apache.jmeter.control.TransactionSampler) Sampler(org.apache.jmeter.samplers.Sampler) JMeterStopTestException(org.apache.jorphan.util.JMeterStopTestException) JMeterStopThreadException(org.apache.jorphan.util.JMeterStopThreadException) JMeterStopTestNowException(org.apache.jorphan.util.JMeterStopTestNowException)

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