use of org.apache.jmeter.threads.JMeterContext in project jmeter by apache.
the class ThreadGroupName method execute.
@Override
public /**
* Get current thread group using sampler's context
*/
String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
JMeterContext context;
if (currentSampler != null) {
context = currentSampler.getThreadContext();
} else {
context = JMeterContextService.getContext();
}
AbstractThreadGroup threadGroup = context.getThreadGroup();
if (threadGroup != null) {
return threadGroup.getName();
} else {
// Can happen if called from GUI or from non test threads
return "";
}
}
use of org.apache.jmeter.threads.JMeterContext in project jmeter by apache.
the class FunctionHelper method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
if (GENERATE.equals(actionCommand)) {
String functionName = getFunctionName(functionList.getText());
Arguments args = (Arguments) parameterPanel.createTestElement();
String functionCall = buildFunctionCallString(functionName, args);
cutPasteFunction.setText(functionCall);
cutPasteFunction.setEnabled(true);
GuiUtils.copyTextToClipboard(cutPasteFunction.getText());
CompoundVariable function = new CompoundVariable(functionCall);
JMeterContext threadContext = JMeterContextService.getContext();
threadContext.setVariables(jMeterVariables);
threadContext.setThreadNum(1);
threadContext.getVariables().put(JMeterThread.LAST_SAMPLE_OK, "true");
ThreadGroup threadGroup = new ThreadGroup();
threadGroup.setName("FunctionHelper-Dialog-ThreadGroup");
threadContext.setThreadGroup(threadGroup);
try {
resultTextArea.setText(function.execute().trim());
} catch (Exception ex) {
log.error("Error calling function {}", functionCall, ex);
resultTextArea.setText(ex.getMessage() + ", \nstacktrace:\n " + ExceptionUtils.getStackTrace(ex));
resultTextArea.setCaretPosition(0);
}
variablesTextArea.setText(variablesToString(jMeterVariables));
} else {
jMeterVariables = new JMeterVariables();
variablesTextArea.setText(variablesToString(jMeterVariables));
}
}
use of org.apache.jmeter.threads.JMeterContext in project jmeter by apache.
the class JMeterContextExtension method resolveParameter.
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
Class<?> parameterType = parameterContext.getParameter().getType();
JMeterContext jMeterContext = JMeterContextService.getContext();
if (parameterType == JMeterContext.class) {
return jMeterContext;
}
if (parameterType == JMeterVariables.class) {
return jMeterContext.getVariables();
}
throw new IllegalArgumentException(parameterContext.toString());
}
Aggregations