Search in sources :

Example 1 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.

the class HTTPHC4Impl method setupClientContextBeforeSample.

/**
     * Configure the UserToken so that the SSL context is reused
     * See <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=57804">Bug 57804</a>
     * @param localContext {@link HttpContext}
     */
private void setupClientContextBeforeSample(HttpContext localContext) {
    Object userToken = null;
    // During recording JMeterContextService.getContext().getVariables() is null
    JMeterVariables jMeterVariables = JMeterContextService.getContext().getVariables();
    if (jMeterVariables != null) {
        userToken = jMeterVariables.getObject(USER_TOKEN);
    }
    if (userToken != null) {
        log.debug("Found user token:{} as JMeter variable:{}, storing it in HttpContext", userToken, USER_TOKEN);
        localContext.setAttribute(HttpClientContext.USER_TOKEN, userToken);
    } else {
        // It would be better to create a ClientSessionManager that would compute this value
        // for now it can be Thread.currentThread().getName() but must be changed when we would change 
        // the Thread per User model
        String userId = Thread.currentThread().getName();
        log.debug("Storing in HttpContext the user token: {}", userId);
        localContext.setAttribute(HttpClientContext.USER_TOKEN, userId);
    }
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables)

Example 2 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter by apache.

the class HTTPHC4Impl method extractClientContextAfterSample.

/**
     * Store in JMeter Variables the UserToken so that the SSL context is reused
     * See <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=57804">Bug 57804</a>
     * @param localContext {@link HttpContext}
     */
private void extractClientContextAfterSample(HttpContext localContext) {
    Object userToken = localContext.getAttribute(HttpClientContext.USER_TOKEN);
    if (userToken != null) {
        log.debug("Extracted from HttpContext user token:{} storing it as JMeter variable:{}", userToken, USER_TOKEN);
        // During recording JMeterContextService.getContext().getVariables() is null
        JMeterVariables jMeterVariables = JMeterContextService.getContext().getVariables();
        if (jMeterVariables != null) {
            jMeterVariables.putObject(USER_TOKEN, userToken);
        }
    }
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables)

Example 3 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.

the class Base64EncodeTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    TestJMeterUtils.createJmeterEnv();
    JMeterContextService.getContext().setVariables(new JMeterVariables());
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) BeforeClass(org.junit.BeforeClass)

Example 4 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.

the class CaseFormatTest method setUp.

@Before
public void setUp() {
    changeCase = new CaseFormat();
    result = new SampleResult();
    JMeterContext jmctx = JMeterContextService.getContext();
    String data = "dummy data";
    result.setResponseData(data, null);
    JMeterVariables vars = new JMeterVariables();
    jmctx.setVariables(vars);
    jmctx.setPreviousResult(result);
    params = new LinkedList<>();
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 5 with JMeterVariables

use of org.apache.jmeter.threads.JMeterVariables in project jmeter-plugins by undera.

the class Base64Encode method execute.

@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
    String sourceString = values[0].execute();
    String decodedValue = new String(Base64.encodeBase64(sourceString.getBytes()));
    if (values.length > 1) {
        String variableName = values[1].execute();
        if (variableName.length() > 0) {
            // Allow for empty name
            final JMeterVariables variables = getVariables();
            if (variables != null) {
                variables.put(variableName, decodedValue);
            }
        }
    }
    return decodedValue;
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables)

Aggregations

JMeterVariables (org.apache.jmeter.threads.JMeterVariables)193 SampleResult (org.apache.jmeter.samplers.SampleResult)71 JMeterContext (org.apache.jmeter.threads.JMeterContext)64 BeforeEach (org.junit.jupiter.api.BeforeEach)46 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)27 Test (org.junit.jupiter.api.Test)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 Test (org.junit.Test)16 JSONPostProcessor (org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor)11 Before (org.junit.Before)10 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)6 TestPlan (org.apache.jmeter.testelement.TestPlan)6 HashMap (java.util.HashMap)5 ValueReplacer (org.apache.jmeter.engine.util.ValueReplacer)5 URL (java.net.URL)4 Arguments (org.apache.jmeter.config.Arguments)4 DebugSampler (org.apache.jmeter.sampler.DebugSampler)4