Search in sources :

Example 96 with JMeterContext

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 "";
    }
}
Also used : JMeterContext(org.apache.jmeter.threads.JMeterContext) AbstractThreadGroup(org.apache.jmeter.threads.AbstractThreadGroup)

Example 97 with JMeterContext

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));
    }
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) Arguments(org.apache.jmeter.config.Arguments) ThreadGroup(org.apache.jmeter.threads.ThreadGroup) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException)

Example 98 with JMeterContext

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());
}
Also used : JMeterContext(org.apache.jmeter.threads.JMeterContext)

Aggregations

JMeterContext (org.apache.jmeter.threads.JMeterContext)98 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)64 SampleResult (org.apache.jmeter.samplers.SampleResult)47 Test (org.junit.Test)19 Test (org.junit.jupiter.api.Test)18 BeforeEach (org.junit.jupiter.api.BeforeEach)13 JSONPostProcessor (org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)10 Sampler (org.apache.jmeter.samplers.Sampler)9 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)8 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)4 Properties (java.util.Properties)3 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)3 JMeterException (org.apache.jorphan.util.JMeterException)3 HashMap (java.util.HashMap)2 Bindings (javax.script.Bindings)2 Arguments (org.apache.jmeter.config.Arguments)2 ReplaceStringWithFunctions (org.apache.jmeter.engine.util.ReplaceStringWithFunctions)2