use of org.apache.jmeter.samplers.SampleListener in project jmeter by apache.
the class TestCompiler method saveTransactionControllerConfigs.
private void saveTransactionControllerConfigs(TransactionController tc) {
List<ConfigTestElement> configs = new ArrayList<>();
List<Controller> controllers = new ArrayList<>();
List<SampleListener> listeners = new ArrayList<>();
List<Timer> timers = new ArrayList<>();
List<Assertion> assertions = new ArrayList<>();
List<PostProcessor> posts = new ArrayList<>();
List<PreProcessor> pres = new ArrayList<>();
for (int i = stack.size(); i > 0; i--) {
addDirectParentControllers(controllers, stack.get(i - 1));
for (Object item : testTree.list(stack.subList(0, i))) {
if (item instanceof SampleListener) {
listeners.add((SampleListener) item);
}
if (item instanceof Assertion) {
assertions.add((Assertion) item);
}
}
}
SamplePackage pack = new SamplePackage(configs, listeners, timers, assertions, posts, pres, controllers);
pack.setSampler(new TransactionSampler(tc, tc.getName()));
pack.setRunningVersion(true);
transactionControllerConfigMap.put(tc, pack);
}
use of org.apache.jmeter.samplers.SampleListener in project jmeter by apache.
the class JMeterThread method getSampleListeners.
/**
* Get the SampleListeners for the sampler. Listeners who receive transaction sample
* will not be in this list.
*
* @param samplePack
* @param transactionPack
* @param transactionSampler
* @return the listeners who should receive the sample result
*/
private List<SampleListener> getSampleListeners(SamplePackage samplePack, SamplePackage transactionPack, TransactionSampler transactionSampler) {
List<SampleListener> sampleListeners = samplePack.getSampleListeners();
// Do not send subsamples to listeners which receive the transaction sample
if (transactionSampler != null) {
List<SampleListener> onlySubSamplerListeners = new ArrayList<>();
List<SampleListener> transListeners = transactionPack.getSampleListeners();
for (SampleListener listener : sampleListeners) {
// Check if this instance is present in transaction listener list
boolean found = false;
for (SampleListener trans : transListeners) {
// Check for the same instance
if (trans == listener) {
found = true;
break;
}
}
if (!found) {
onlySubSamplerListeners.add(listener);
}
}
sampleListeners = onlySubSamplerListeners;
}
return sampleListeners;
}
use of org.apache.jmeter.samplers.SampleListener in project jmeter by apache.
the class ListenerNotifier method notifyListeners.
/**
* Notify a list of listeners that a sample has occurred.
*
* @param res
* the sample event that has occurred. Must be non-null.
* @param listeners
* a list of the listeners which should be notified. This list
* must not be null and must contain only SampleListener
* elements.
*/
public void notifyListeners(SampleEvent res, List<SampleListener> listeners) {
for (SampleListener sampleListener : listeners) {
try {
TestBeanHelper.prepare((TestElement) sampleListener);
sampleListener.sampleOccurred(res);
} catch (RuntimeException e) {
log.error("Detected problem in Listener.", e);
log.info("Continuing to process further listeners");
}
}
}
use of org.apache.jmeter.samplers.SampleListener in project jmeter by apache.
the class ConvertListeners method addNode.
/**
* {@inheritDoc}
*/
@Override
public void addNode(Object node, HashTree subTree) {
for (Object item : subTree.list()) {
if (item instanceof AbstractThreadGroup && log.isDebugEnabled()) {
log.debug("num threads = {}", ((AbstractThreadGroup) item).getNumThreads());
}
if (item instanceof Remoteable) {
if (item instanceof RemoteThreadsListenerTestElement) {
// Used for remote notification of threads start/stop,see BUG 54152
try {
RemoteThreadsListenerWrapper wrapper = new RemoteThreadsListenerWrapper(new RemoteThreadsListenerImpl());
subTree.replaceKey(item, wrapper);
} catch (RemoteException e) {
log.error("Error replacing {} by wrapper: {}", RemoteThreadsListenerTestElement.class, RemoteThreadsListenerWrapper.class, e);
}
continue;
}
if (item instanceof ThreadListener) {
// TODO Document the reason for this
log.error("Cannot handle ThreadListener Remotable item: {}", item.getClass());
continue;
}
try {
RemoteSampleListener rtl = new RemoteSampleListenerImpl(item);
if (item instanceof TestStateListener && item instanceof SampleListener) {
// TL - all
RemoteListenerWrapper wrap = new RemoteListenerWrapper(rtl);
subTree.replaceKey(item, wrap);
} else if (item instanceof TestStateListener) {
RemoteTestListenerWrapper wrap = new RemoteTestListenerWrapper(rtl);
subTree.replaceKey(item, wrap);
} else if (item instanceof SampleListener) {
RemoteSampleListenerWrapper wrap = new RemoteSampleListenerWrapper(rtl);
subTree.replaceKey(item, wrap);
} else {
if (log.isWarnEnabled()) {
log.warn("Could not replace Remotable item: {}", item.getClass());
}
}
} catch (RemoteException e) {
// $NON-NLS-1$
log.error("RemoteException occurred while replacing Remotable item.", e);
}
}
}
}
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());
SampleResult result = null;
if (running) {
Sampler sampler = pack.getSampler();
result = doSampling(threadContext, sampler);
}
// If we got any results, then perform processing on the result
if (result != null) {
if (!result.isIgnore()) {
int nbActiveThreadsInThreadGroup = threadGroup.getNumberOfThreads();
int nbTotalActiveThreads = JMeterContextService.getNumberOfThreads();
fillThreadInformation(result, nbActiveThreadsInThreadGroup, nbTotalActiveThreads);
SampleResult[] subResults = result.getSubResults();
if (subResults != null) {
for (SampleResult subResult : subResults) {
fillThreadInformation(subResult, nbActiveThreadsInThreadGroup, nbTotalActiveThreads);
}
}
threadContext.setPreviousResult(result);
runPostProcessors(pack.getPostProcessors());
checkAssertions(pack.getAssertions(), result, threadContext);
// PostProcessors can call setIgnore, so reevaluate here
if (!result.isIgnore()) {
// 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 && !result.isIgnore()) {
transactionSampler.addSubSamplerResult(result);
}
} else {
// This call is done by checkAssertions() , as we don't call it
// for isIgnore, we explictely call it here
setLastSampleOk(threadContext.getVariables(), result.isSuccessful());
compiler.done(pack);
}
// Check if thread or test should be stopped
if (result.isStopThread() || (!result.isSuccessful() && onErrorStopThread)) {
stopThread();
}
if (result.isStopTest() || (!result.isSuccessful() && onErrorStopTest)) {
shutdownTest();
}
if (result.isStopTestNow() || (!result.isSuccessful() && onErrorStopTestNow)) {
stopTestNow();
}
if (result.getTestLogicalAction() != TestLogicalAction.CONTINUE) {
threadContext.setTestLogicalAction(result.getTestLogicalAction());
}
} else {
// Finish up
compiler.done(pack);
}
}
Aggregations