Search in sources :

Example 1 with LoopIterationListener

use of org.apache.jmeter.engine.event.LoopIterationListener 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 LoopIterationListener

use of org.apache.jmeter.engine.event.LoopIterationListener in project jmeter by apache.

the class TestCompiler method trackIterationListeners.

private void trackIterationListeners(LinkedList<TestElement> pStack) {
    TestElement child = pStack.getLast();
    if (child instanceof LoopIterationListener) {
        ListIterator<TestElement> iter = pStack.listIterator(pStack.size());
        while (iter.hasPrevious()) {
            TestElement item = iter.previous();
            if (item == child) {
                continue;
            }
            if (item instanceof Controller) {
                TestBeanHelper.prepare(child);
                ((Controller) item).addIterationListener((LoopIterationListener) child);
                break;
            }
        }
    }
}
Also used : LoopIterationListener(org.apache.jmeter.engine.event.LoopIterationListener) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) Controller(org.apache.jmeter.control.Controller) TransactionController(org.apache.jmeter.control.TransactionController)

Aggregations

LoopIterationListener (org.apache.jmeter.engine.event.LoopIterationListener)2 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)1 Controller (org.apache.jmeter.control.Controller)1 TransactionController (org.apache.jmeter.control.TransactionController)1 TransactionSampler (org.apache.jmeter.control.TransactionSampler)1 Sampler (org.apache.jmeter.samplers.Sampler)1 TestElement (org.apache.jmeter.testelement.TestElement)1 JMeterError (org.apache.jorphan.util.JMeterError)1 JMeterStopTestException (org.apache.jorphan.util.JMeterStopTestException)1 JMeterStopTestNowException (org.apache.jorphan.util.JMeterStopTestNowException)1 JMeterStopThreadException (org.apache.jorphan.util.JMeterStopThreadException)1