Search in sources :

Example 6 with SampleListener

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

the class JMeterThread method executeSamplePackage.

/*
     * Execute the sampler with its pre/post processors, timers, assertions
     * Broadcast the result to the sample listeners
     */
private void executeSamplePackage(Sampler current, TransactionSampler transactionSampler, SamplePackage transactionPack, JMeterContext threadContext) {
    threadContext.setCurrentSampler(current);
    // Get the sampler ready to sample
    SamplePackage pack = compiler.configureSampler(current);
    runPreProcessors(pack.getPreProcessors());
    // Hack: save the package for any transaction controllers
    threadVars.putObject(PACKAGE_OBJECT, pack);
    delay(pack.getTimers());
    Sampler sampler = pack.getSampler();
    sampler.setThreadContext(threadContext);
    // TODO should this set the thread names for all the subsamples?
    // might be more efficient than fetching the name elsewhere
    sampler.setThreadName(threadName);
    TestBeanHelper.prepare(sampler);
    // Perform the actual sample
    currentSampler = sampler;
    if (!sampleMonitors.isEmpty()) {
        for (SampleMonitor sampleMonitor : sampleMonitors) {
            sampleMonitor.sampleStarting(sampler);
        }
    }
    SampleResult result = null;
    try {
        result = sampler.sample(null);
    } finally {
        if (!sampleMonitors.isEmpty()) {
            for (SampleMonitor sampleMonitor : sampleMonitors) {
                sampleMonitor.sampleEnded(sampler);
            }
        }
    }
    currentSampler = null;
    // If we got any results, then perform processing on the result
    if (result != null) {
        int nbActiveThreadsInThreadGroup = threadGroup.getNumberOfThreads();
        int nbTotalActiveThreads = JMeterContextService.getNumberOfThreads();
        result.setGroupThreads(nbActiveThreadsInThreadGroup);
        result.setAllThreads(nbTotalActiveThreads);
        result.setThreadName(threadName);
        SampleResult[] subResults = result.getSubResults();
        if (subResults != null) {
            for (SampleResult subResult : subResults) {
                subResult.setGroupThreads(nbActiveThreadsInThreadGroup);
                subResult.setAllThreads(nbTotalActiveThreads);
                subResult.setThreadName(threadName);
            }
        }
        threadContext.setPreviousResult(result);
        runPostProcessors(pack.getPostProcessors());
        checkAssertions(pack.getAssertions(), result, threadContext);
        // Do not send subsamples to listeners which receive the transaction sample
        List<SampleListener> sampleListeners = getSampleListeners(pack, transactionPack, transactionSampler);
        notifyListeners(sampleListeners, result);
        compiler.done(pack);
        // Add the result as subsample of transaction if we are in a transaction
        if (transactionSampler != null) {
            transactionSampler.addSubSamplerResult(result);
        }
        // Check if thread or test should be stopped
        if (result.isStopThread() || (!result.isSuccessful() && onErrorStopThread)) {
            if (transactionSampler != null) {
                doEndTransactionSampler(transactionSampler, current, transactionPack, threadContext);
            }
            stopThread();
        }
        if (result.isStopTest() || (!result.isSuccessful() && onErrorStopTest)) {
            if (transactionSampler != null) {
                doEndTransactionSampler(transactionSampler, current, transactionPack, threadContext);
            }
            shutdownTest();
        }
        if (result.isStopTestNow() || (!result.isSuccessful() && onErrorStopTestNow)) {
            if (transactionSampler != null) {
                doEndTransactionSampler(transactionSampler, current, transactionPack, threadContext);
            }
            stopTestNow();
        }
        if (result.isStartNextThreadLoop()) {
            threadContext.setRestartNextLoop(true);
        }
    } else {
        // Finish up
        compiler.done(pack);
    }
}
Also used : TransactionSampler(org.apache.jmeter.control.TransactionSampler) Sampler(org.apache.jmeter.samplers.Sampler) SampleResult(org.apache.jmeter.samplers.SampleResult) SampleMonitor(org.apache.jmeter.samplers.SampleMonitor) SampleListener(org.apache.jmeter.samplers.SampleListener)

Aggregations

SampleListener (org.apache.jmeter.samplers.SampleListener)6 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)2 TransactionSampler (org.apache.jmeter.control.TransactionSampler)2 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Assertion (org.apache.jmeter.assertions.Assertion)1 Controller (org.apache.jmeter.control.Controller)1 TransactionController (org.apache.jmeter.control.TransactionController)1 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)1 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)1 PostProcessor (org.apache.jmeter.processor.PostProcessor)1 PreProcessor (org.apache.jmeter.processor.PreProcessor)1 RemoteListenerWrapper (org.apache.jmeter.samplers.RemoteListenerWrapper)1 RemoteSampleListener (org.apache.jmeter.samplers.RemoteSampleListener)1 RemoteSampleListenerImpl (org.apache.jmeter.samplers.RemoteSampleListenerImpl)1 RemoteSampleListenerWrapper (org.apache.jmeter.samplers.RemoteSampleListenerWrapper)1 RemoteTestListenerWrapper (org.apache.jmeter.samplers.RemoteTestListenerWrapper)1 Remoteable (org.apache.jmeter.samplers.Remoteable)1 SampleMonitor (org.apache.jmeter.samplers.SampleMonitor)1