Search in sources :

Example 11 with JMeterVariables

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

the class StrReplaceRegex method execute.

@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
    String totalString = getParameter(0).replaceAll(getParameter(1), getParameter(2));
    JMeterVariables vars = getVariables();
    if (values.length > 3) {
        String varName = getParameter(3);
        if (vars != null && varName != null && varName.length() > 0) {
            // vars will be null on TestPlan
            vars.put(varName, totalString);
        }
    }
    return totalString;
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables)

Example 12 with JMeterVariables

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

the class Base64DecodeTest method testExecute.

@Test
public void testExecute() throws Exception {
    JMeterContext context = JMeterContextService.getContext();
    context.setVariables(new JMeterVariables());
    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable("dGVzdCBzdHJpbmc="));
    parameters.add(new CompoundVariable("b64dec_res"));
    Base64Decode instance = new Base64Decode();
    instance.setParameters(parameters);
    String res = instance.execute(null, null);
    Assert.assertEquals("test string", res);
    Assert.assertNotNull(context.getVariables().get("b64dec_res"));
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with JMeterVariables

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

the class ConcurrencyThreadGroupTest method testSetDoneThreadsAfterHold.

// WAP-9261
@Test(timeout = 25000)
public void testSetDoneThreadsAfterHold() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    TestSampleListener listener = new TestSampleListener();
    DebugSampler sampler = new DebugSampler();
    sampler.setName("Sampler");
    ConstantTimer timer = new ConstantTimer();
    timer.setDelay("2000");
    timer.setName("timer");
    LoopController loopController = new LoopController();
    loopController.setContinueForever(true);
    loopController.setLoops(-1);
    loopController.setName("loop c");
    ConcurrencyThreadGroupExt ctg = new ConcurrencyThreadGroupExt();
    ctg.setName("CTG");
    ctg.setRampUp("5");
    ctg.setTargetLevel("3");
    ctg.setSteps("1");
    // TODO: increase this value for debugging
    ctg.setHold("10");
    ctg.setIterationsLimit("");
    ctg.setUnit("S");
    ListedHashTree loopTree = new ListedHashTree();
    loopTree.add(loopController, timer);
    loopTree.add(loopController, sampler);
    loopTree.add(loopController, listener);
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(ctg, loopTree);
    TestCompiler compiler = new TestCompiler(hashTree);
    // this hashTree can be save to *jmx
    hashTree.traverse(compiler);
    ListenerNotifier notifier = new ListenerNotifier();
    long startTime = System.currentTimeMillis();
    ctg.start(1, notifier, hashTree, new StandardJMeterEngine());
    Thread threadStarter = ctg.getThreadStarter();
    threadStarter.join();
    long endTime = System.currentTimeMillis();
    // wait when all thread stopped
    Thread.currentThread().sleep(5000);
    assertTrue((endTime - startTime) < 20000);
    // ALL threads must be stopped
    assertEquals(0, ctg.getNumberOfThreads());
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) ListedHashTree(org.apache.jorphan.collections.ListedHashTree) DebugSampler(org.apache.jmeter.sampler.DebugSampler) TestCompiler(org.apache.jmeter.threads.TestCompiler) StandardJMeterEngine(org.apache.jmeter.engine.StandardJMeterEngine) ConstantTimer(org.apache.jmeter.timers.ConstantTimer) LoopController(org.apache.jmeter.control.LoopController) ListenerNotifier(org.apache.jmeter.threads.ListenerNotifier) ArrivalsThreadGroupTest(com.blazemeter.jmeter.threads.arrivals.ArrivalsThreadGroupTest) Test(org.junit.Test)

Example 14 with JMeterVariables

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

the class FlexibleFileWriterTest method testSampleOccurred_var.

@Test
public void testSampleOccurred_var() throws IOException {
    System.out.println("sampleOccurred-var");
    SampleResult res = new SampleResult();
    res.setResponseData("test".getBytes());
    JMeterVariables vars = new JMeterVariables();
    vars.put("TEST1", "TEST");
    SampleEvent e = new SampleEvent(res, "Test", vars);
    FlexibleFileWriter instance = new FlexibleFileWriter();
    instance.setFilename(File.createTempFile("ffw_test_", ".txt").getAbsolutePath());
    System.out.println("prop: " + JMeterUtils.getProperty("sample_variables"));
    System.out.println("count: " + SampleEvent.getVarCount());
    instance.setColumns("variable#0| |variable#| |variable#4t");
    instance.testStarted();
    for (int n = 0; n < 10; n++) {
        String exp = "TEST variable# variable#4t";
        System.out.println(exp);
        instance.sampleOccurred(e);
    // ByteBuffer written = instance.fileEmul.getWrittenBytes();
    // assertEquals(exp, JMeterPluginsUtils.byteBufferToString(written));
    }
    instance.testEnded();
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) SampleResult(org.apache.jmeter.samplers.SampleResult) SampleEvent(org.apache.jmeter.samplers.SampleEvent) Test(org.junit.Test)

Example 15 with JMeterVariables

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

the class FifoPop method execute.

@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
    String fifoName = ((CompoundVariable) values[0]).execute();
    String value = null;
    try {
        Object valueObj = FifoMap.getInstance().pop(fifoName, timeout);
        if (valueObj != null) {
            value = valueObj.toString();
        }
    } catch (InterruptedException ex) {
        log.warn("Interrupted pop from queue " + fifoName);
        value = "INTERRUPTED";
    }
    JMeterVariables vars = getVariables();
    if (vars != null && values.length > 1) {
        String varName = ((CompoundVariable) values[1]).execute().trim();
        vars.put(varName, value);
    }
    return value;
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) 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