use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class IntSum method execute.
/** {@inheritDoc} */
@Override
public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
JMeterVariables vars = getVariables();
int sum = 0;
// trim() see bug 55871
String varName = ((CompoundVariable) values[values.length - 1]).execute().trim();
for (int i = 0; i < values.length - 1; i++) {
sum += Integer.parseInt(((CompoundVariable) values[i]).execute());
}
try {
// Has chances to be a var
sum += Integer.parseInt(varName);
// there is no variable name
varName = null;
} catch (NumberFormatException ignored) {
// varName keeps its value and sum has not taken
// into account non numeric or overflowing number
}
String totalString = Integer.toString(sum);
if (vars != null && varName != null) {
// vars will be null on TestPlan
vars.put(varName.trim(), totalString);
}
return totalString;
}
use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class IterationCounter method execute.
/** {@inheritDoc} */
@Override
public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
JMeterVariables vars = getVariables();
boolean perThread = Boolean.parseBoolean(((CompoundVariable) variables[0]).execute());
//$NON-NLS-1$
String varName = "";
if (variables.length >= 2) {
// Ensure variable has been provided
varName = ((CompoundVariable) variables[1]).execute().trim();
}
//$NON-NLS-1$
String counterString = "";
if (perThread) {
int threadCounter;
threadCounter = perThreadInt.get().intValue() + 1;
perThreadInt.set(Integer.valueOf(threadCounter));
counterString = String.valueOf(threadCounter);
} else {
synchronized (this) {
globalCounter++;
counterString = String.valueOf(globalCounter);
}
}
// vars will be null on Test Plan
if (vars != null && varName.length() > 0) {
vars.put(varName, counterString);
}
return counterString;
}
use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class JavaScript method execute.
/** {@inheritDoc} */
@Override
public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
JMeterContext jmctx = JMeterContextService.getContext();
JMeterVariables vars = jmctx.getVariables();
String script = ((CompoundVariable) values[0]).execute();
// Allow variable to be omitted
String varName = values.length < 2 ? null : ((CompoundVariable) values[1]).execute().trim();
String resultStr = "";
if (useRhinoEngine) {
resultStr = executeWithRhino(previousResult, currentSampler, jmctx, vars, script, varName);
} else {
resultStr = executeWithNashorn(previousResult, currentSampler, jmctx, vars, script, varName);
}
return resultStr;
}
use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class BeanShell method execute.
/** {@inheritDoc} */
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
if (// did we find BeanShell?
bshInterpreter == null) {
throw new InvalidVariableException("BeanShell not found");
}
JMeterContext jmctx = JMeterContextService.getContext();
JMeterVariables vars = jmctx.getVariables();
String script = ((CompoundVariable) values[0]).execute();
//$NON-NLS-1$
String varName = "";
if (values.length > 1) {
varName = ((CompoundVariable) values[1]).execute().trim();
}
//$NON-NLS-1$
String resultStr = "";
try {
// Pass in some variables
if (currentSampler != null) {
//$NON-NLS-1$
bshInterpreter.set("Sampler", currentSampler);
}
if (previousResult != null) {
//$NON-NLS-1$
bshInterpreter.set("SampleResult", previousResult);
}
// Allow access to context and variables directly
//$NON-NLS-1$
bshInterpreter.set("ctx", jmctx);
//$NON-NLS-1$
bshInterpreter.set("vars", vars);
//$NON-NLS-1$
bshInterpreter.set("props", JMeterUtils.getJMeterProperties());
//$NON-NLS-1$
bshInterpreter.set("threadName", Thread.currentThread().getName());
// Execute the script
Object bshOut = bshInterpreter.eval(script);
if (bshOut != null) {
resultStr = bshOut.toString();
}
if (vars != null && varName.length() > 0) {
// vars will be null on TestPlan
vars.put(varName, resultStr);
}
} catch (// Mainly for bsh.EvalError
Exception ex) {
log.warn("Error running BSH script", ex);
}
if (log.isDebugEnabled()) {
log.debug("__Beanshell(" + script + "," + varName + ")=" + resultStr);
}
return resultStr;
}
use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.
the class TestUrlEncodeDecode method testUrlDecode.
@Test
public void testUrlDecode() throws Exception {
AbstractFunction function = new UrlDecode();
params.add(new CompoundVariable("Veni%2C+vidi%2C+vici+%3F"));
function.setParameters(params);
String returnValue = function.execute(result, null);
assertEquals("Veni, vidi, vici ?", returnValue);
}
Aggregations