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