Search in sources :

Example 1 with JMeterStopTestNowException

use of org.apache.jorphan.util.JMeterStopTestNowException in project jmeter by apache.

the class JMeterThread method run.

@Override
public void run() {
    // threadContext is not thread-safe, so keep within thread
    JMeterContext threadContext = JMeterContextService.getContext();
    LoopIterationListener iterationListener = null;
    try {
        iterationListener = initRun(threadContext);
        while (running) {
            Sampler sam = threadGroupLoopController.next();
            while (running && sam != null) {
                processSampler(sam, null, threadContext);
                threadContext.cleanAfterSample();
                // - or the last sample failed AND the onErrorStartNextLoop option is enabled
                if (threadContext.isRestartNextLoop() || (onErrorStartNextLoop && !TRUE.equals(threadContext.getVariables().get(LAST_SAMPLE_OK)))) {
                    if (log.isDebugEnabled() && onErrorStartNextLoop && !threadContext.isRestartNextLoop()) {
                        log.debug("StartNextLoop option is on, Last sample failed, starting next loop");
                    }
                    triggerEndOfLoopOnParentControllers(sam, threadContext);
                    sam = null;
                    threadContext.getVariables().put(LAST_SAMPLE_OK, TRUE);
                    threadContext.setRestartNextLoop(false);
                } else {
                    sam = threadGroupLoopController.next();
                }
            }
            if (threadGroupLoopController.isDone()) {
                running = false;
                log.info("Thread is done: {}", threadName);
            }
        }
    }// Might be found by controller.next()
     catch (JMeterStopTestException e) {
        // NOSONAR
        if (log.isInfoEnabled()) {
            log.info("Stopping Test: {}", e.toString());
        }
        shutdownTest();
    } catch (JMeterStopTestNowException e) {
        // NOSONAR
        if (log.isInfoEnabled()) {
            log.info("Stopping Test Now: {}", e.toString());
        }
        stopTestNow();
    } catch (JMeterStopThreadException e) {
        // NOSONAR
        if (log.isInfoEnabled()) {
            log.info("Stop Thread seen for thread {}, reason: {}", getThreadName(), e.toString());
        }
    } catch (Exception | JMeterError e) {
        log.error("Test failed!", e);
    } catch (ThreadDeath e) {
        // Must not ignore this one
        throw e;
    } finally {
        // prevent any further interrupts
        currentSampler = null;
        try {
            // make sure current interrupt is finished, prevent another starting yet
            interruptLock.lock();
            threadContext.clear();
            log.info("Thread finished: {}", threadName);
            threadFinished(iterationListener);
            // Tell the monitor we are done
            monitor.threadFinished(this);
            // Remove the ThreadLocal entry
            JMeterContextService.removeContext();
        } finally {
            // Allow any pending interrupt to complete (OK because currentSampler == null)
            interruptLock.unlock();
        }
    }
}
Also used : JMeterStopTestNowException(org.apache.jorphan.util.JMeterStopTestNowException) JMeterStopThreadException(org.apache.jorphan.util.JMeterStopThreadException) JMeterStopTestException(org.apache.jorphan.util.JMeterStopTestException) LoopIterationListener(org.apache.jmeter.engine.event.LoopIterationListener) JMeterError(org.apache.jorphan.util.JMeterError) 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)

Example 2 with JMeterStopTestNowException

use of org.apache.jorphan.util.JMeterStopTestNowException in project jmeter by apache.

the class JMeterThread method processSampler.

/**
     * Process the current sampler, handling transaction samplers.
     *
     * @param current sampler
     * @param parent sampler
     * @param threadContext
     * @return SampleResult if a transaction was processed
     */
private SampleResult processSampler(Sampler current, Sampler parent, JMeterContext threadContext) {
    SampleResult transactionResult = null;
    try {
        // Check if we are running a transaction
        TransactionSampler transactionSampler = null;
        if (current instanceof TransactionSampler) {
            transactionSampler = (TransactionSampler) current;
        }
        // Find the package for the transaction
        SamplePackage transactionPack = null;
        if (transactionSampler != null) {
            transactionPack = compiler.configureTransactionSampler(transactionSampler);
            // Check if the transaction is done
            if (transactionSampler.isTransactionDone()) {
                transactionResult = doEndTransactionSampler(transactionSampler, parent, transactionPack, threadContext);
                // Transaction is done, we do not have a sampler to sample
                current = null;
            } else {
                Sampler prev = current;
                // It is the sub sampler of the transaction that will be sampled
                current = transactionSampler.getSubSampler();
                if (current instanceof TransactionSampler) {
                    // recursive call
                    SampleResult res = processSampler(current, prev, threadContext);
                    threadContext.setCurrentSampler(prev);
                    current = null;
                    if (res != null) {
                        transactionSampler.addSubSamplerResult(res);
                    }
                }
            }
        }
        // Check if we have a sampler to sample
        if (current != null) {
            executeSamplePackage(current, transactionSampler, transactionPack, threadContext);
        }
        if (scheduler) {
            // checks the scheduler to stop the iteration
            stopSchedulerIfNeeded();
        }
    } catch (JMeterStopTestException e) {
        // NOSONAR
        if (log.isInfoEnabled()) {
            log.info("Stopping Test: {}", e.toString());
        }
        if (current != null && current instanceof TransactionSampler) {
            doEndTransactionSampler((TransactionSampler) current, parent, compiler.configureTransactionSampler((TransactionSampler) current), threadContext);
        }
        shutdownTest();
    } catch (JMeterStopTestNowException e) {
        // NOSONAR
        if (log.isInfoEnabled()) {
            log.info("Stopping Test with interruption of current samplers: {}", e.toString());
        }
        if (current != null && current instanceof TransactionSampler) {
            doEndTransactionSampler((TransactionSampler) current, parent, compiler.configureTransactionSampler((TransactionSampler) current), threadContext);
        }
        stopTestNow();
    } catch (JMeterStopThreadException e) {
        // NOSONAR
        if (log.isInfoEnabled()) {
            log.info("Stopping Thread: {}", e.toString());
        }
        if (current != null && current instanceof TransactionSampler) {
            doEndTransactionSampler((TransactionSampler) current, parent, compiler.configureTransactionSampler((TransactionSampler) current), threadContext);
        }
        stopThread();
    } catch (Exception e) {
        if (current != null) {
            log.error("Error while processing sampler: '{}'.", current.getName(), e);
        } else {
            log.error("Error while processing sampler.", e);
        }
    }
    return transactionResult;
}
Also used : JMeterStopTestNowException(org.apache.jorphan.util.JMeterStopTestNowException) JMeterStopThreadException(org.apache.jorphan.util.JMeterStopThreadException) JMeterStopTestException(org.apache.jorphan.util.JMeterStopTestException) TransactionSampler(org.apache.jmeter.control.TransactionSampler) Sampler(org.apache.jmeter.samplers.Sampler) SampleResult(org.apache.jmeter.samplers.SampleResult) TransactionSampler(org.apache.jmeter.control.TransactionSampler) JMeterStopTestException(org.apache.jorphan.util.JMeterStopTestException) JMeterStopThreadException(org.apache.jorphan.util.JMeterStopThreadException) JMeterStopTestNowException(org.apache.jorphan.util.JMeterStopTestNowException)

Aggregations

TransactionSampler (org.apache.jmeter.control.TransactionSampler)2 Sampler (org.apache.jmeter.samplers.Sampler)2 JMeterStopTestException (org.apache.jorphan.util.JMeterStopTestException)2 JMeterStopTestNowException (org.apache.jorphan.util.JMeterStopTestNowException)2 JMeterStopThreadException (org.apache.jorphan.util.JMeterStopThreadException)2 LoopIterationListener (org.apache.jmeter.engine.event.LoopIterationListener)1 SampleResult (org.apache.jmeter.samplers.SampleResult)1 JMeterError (org.apache.jorphan.util.JMeterError)1