use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class AbstractFunction method execute.
public String execute() throws InvalidVariableException {
JMeterContext context = JMeterContextService.getContext();
SampleResult previousResult = context.getPreviousResult();
Sampler currentSampler = context.getCurrentSampler();
return execute(previousResult, currentSampler);
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class TestCompiler method subtractNode.
/** {@inheritDoc} */
@Override
public void subtractNode() {
if (log.isDebugEnabled()) {
log.debug("Subtracting node, stack size = {}", stack.size());
}
TestElement child = stack.getLast();
trackIterationListeners(stack);
if (child instanceof Sampler) {
saveSamplerConfigs((Sampler) child);
} else if (child instanceof TransactionController) {
saveTransactionControllerConfigs((TransactionController) child);
}
stack.removeLast();
if (!stack.isEmpty()) {
TestElement parent = stack.getLast();
boolean duplicate = false;
// Bug 53750: this condition used to be in ObjectPair#addTestElements()
if (parent instanceof Controller && (child instanceof Sampler || child instanceof Controller)) {
if (parent instanceof TestCompilerHelper) {
TestCompilerHelper te = (TestCompilerHelper) parent;
duplicate = !te.addTestElementOnce(child);
} else {
// this is only possible for 3rd party controllers by default
ObjectPair pair = new ObjectPair(child, parent);
synchronized (PAIRING) {
// Called from multiple threads
if (!PAIRING.contains(pair)) {
parent.addTestElement(child);
PAIRING.add(pair);
} else {
duplicate = true;
}
}
}
}
if (duplicate) {
if (log.isWarnEnabled()) {
log.warn("Unexpected duplicate for {} and {}", parent.getClass(), child.getClass());
}
}
}
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class JMeterThread method triggerEndOfLoopOnParentControllers.
/**
* Trigger end of loop on parent controllers up to Thread Group
* @param sam Sampler Base sampler
* @param threadContext
*/
private void triggerEndOfLoopOnParentControllers(Sampler sam, JMeterContext threadContext) {
TransactionSampler transactionSampler = null;
if (sam instanceof TransactionSampler) {
transactionSampler = (TransactionSampler) sam;
}
Sampler realSampler = findRealSampler(sam);
if (realSampler == null) {
throw new IllegalStateException("Got null subSampler calling findRealSampler for:" + (sam != null ? sam.getName() : "null") + ", sam:" + sam);
}
// Find parent controllers of current sampler
FindTestElementsUpToRootTraverser pathToRootTraverser = new FindTestElementsUpToRootTraverser(realSampler);
testTree.traverse(pathToRootTraverser);
// Trigger end of loop condition on all parent controllers of current sampler
List<Controller> controllersToReinit = pathToRootTraverser.getControllersToRoot();
for (Controller parentController : controllersToReinit) {
if (parentController instanceof AbstractThreadGroup) {
AbstractThreadGroup tg = (AbstractThreadGroup) parentController;
tg.startNextLoop();
} else {
parentController.triggerEndOfLoop();
}
}
// then we still need to report the Transaction in error (and create the sample result)
if (transactionSampler != null) {
SamplePackage transactionPack = compiler.configureTransactionSampler(transactionSampler);
doEndTransactionSampler(transactionSampler, null, transactionPack, threadContext);
}
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class BSFTestElement method initManager.
protected void initManager(BSFManager mgr) throws BSFException {
final String label = getName();
final String fileName = getFilename();
final String scriptParameters = getParameters();
// Use actual class name for log
final Logger logger = LoggerFactory.getLogger(getClass());
// $NON-NLS-1$
mgr.declareBean("log", logger, Logger.class);
// $NON-NLS-1$
mgr.declareBean("Label", label, String.class);
// $NON-NLS-1$
mgr.declareBean("FileName", fileName, String.class);
// $NON-NLS-1$
mgr.declareBean("Parameters", scriptParameters, String.class);
//$NON-NLS-1$
String[] args = JOrphanUtils.split(scriptParameters, " ");
//$NON-NLS-1$
mgr.declareBean("args", args, args.getClass());
// Add variables for access to context and variables
JMeterContext jmctx = JMeterContextService.getContext();
JMeterVariables vars = jmctx.getVariables();
Properties props = JMeterUtils.getJMeterProperties();
// $NON-NLS-1$
mgr.declareBean("ctx", jmctx, jmctx.getClass());
// $NON-NLS-1$
mgr.declareBean("vars", vars, vars.getClass());
// $NON-NLS-1$
mgr.declareBean("props", props, props.getClass());
// For use in debugging:
// $NON-NLS-1$
mgr.declareBean("OUT", System.out, PrintStream.class);
// Most subclasses will need these:
Sampler sampler = jmctx.getCurrentSampler();
mgr.declareBean("sampler", sampler, Sampler.class);
SampleResult prev = jmctx.getPreviousResult();
mgr.declareBean("prev", prev, SampleResult.class);
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class JMeterThread method interrupt.
/** {@inheritDoc} */
@Override
public boolean interrupt() {
try {
interruptLock.lock();
// fetch once; must be done under lock
Sampler samp = currentSampler;
if (samp instanceof Interruptible) {
// (also protects against null)
if (log.isWarnEnabled()) {
log.warn("Interrupting: {} sampler: {}", threadName, samp.getName());
}
try {
boolean found = ((Interruptible) samp).interrupt();
if (!found) {
log.warn("No operation pending");
}
return found;
} catch (Exception e) {
// NOSONAR
if (log.isWarnEnabled()) {
log.warn("Caught Exception interrupting sampler: {}", e.toString());
}
}
} else if (samp != null) {
if (log.isWarnEnabled()) {
log.warn("Sampler is not Interruptible: {}", samp.getName());
}
}
} finally {
interruptLock.unlock();
}
return false;
}
Aggregations