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();
}
}
}
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;
}
}
}
}
Aggregations