org.apache.jmeter.threads.JMeterContextService Java Examples

The following examples show how to use org.apache.jmeter.threads.JMeterContextService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JMeterThreadParallelTest.java    From jmeter-bzm-plugins with Apache License 2.0 7 votes vote down vote up
@Test
public void testStopParentThread() {
    DummyThreadGroup monitor = new DummyThreadGroup();
    ListenerNotifier listenerNotifier = new ListenerNotifier();

    HashTree tree = new HashTree();
    LoopControllerExt loopControllerExt = new LoopControllerExt();
    tree.add(loopControllerExt);

    JMeterThreadExt parentThread = new JMeterThreadExt(tree, monitor, listenerNotifier);
    parentThread.setThreadGroup(monitor);
    JMeterContextService.getContext().setThread(parentThread);

    JMeterThreadParallel parallel = new JMeterThreadParallel(tree, monitor, listenerNotifier, true);
    parallel.setThreadGroup(monitor);
    loopControllerExt.thread = parallel;
    parallel.run();

    assertTrue(parentThread.isStopped);
}
 
Example #2
Source File: JMXMonCollector.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void testStarted(String host) {

    if (!isWorkingHost(host)) {
        return;
    }

    //ensure the data will be saved
    if (getProperty(FILENAME) == null || getProperty(FILENAME).getStringValue().trim().length() == 0) {
        if (autoGenerateFiles) {
            setupSaving(getAutoFileName());
        } else {
            log.info("JmxMon metrics will not be recorded! Please specify a file name in the gui or run the test with -JforceJmxMonFile=true");
        }
    }
    
    ctx = JMeterContextService.getContext();
    initiateConnectors();
    
    workerThread = new Thread(this);
    workerThread.start();

    super.testStarted(host);
}
 
Example #3
Source File: ParallelSampler.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
private HashTree getSubTree(TestElement te) {
    try {
        Field field = JMeterThread.class.getDeclaredField("testTree");
        field.setAccessible(true);
        JMeterThread parentThread = JMeterContextService.getContext().getThread();
        if (parentThread == null) {
            log.error("Current thread is null.");
            throw new NullPointerException();
        }
        HashTree testTree = (HashTree) field.get(parentThread);
        SearchByClass<?> searcher = new SearchByClass<>(te.getClass());
        testTree.traverse(searcher);
        return searcher.getSubTree(te);
    } catch (ReflectiveOperationException ex) {
        log.warn("Can not get sub tree for Test element " + te.getName(), ex);
        return null;
    }
}
 
Example #4
Source File: WebDriverSampler.java    From jmeter-plugins-webdriver with Apache License 2.0 6 votes vote down vote up
ScriptEngine createScriptEngineWith(SampleResult sampleResult) {
    final ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(this.getScriptLanguage());
    Bindings engineBindings = new SimpleBindings();
    WebDriverScriptable scriptable = new WebDriverScriptable();
    scriptable.setName(getName());
    scriptable.setParameters(getParameters());
    JMeterContext context = JMeterContextService.getContext();
    scriptable.setVars(context.getVariables());
    scriptable.setProps(JMeterUtils.getJMeterProperties());
    scriptable.setCtx(context);
    scriptable.setLog(LOGGER);
    scriptable.setSampleResult(sampleResult);
    scriptable.setBrowser(getWebDriver());
    engineBindings.put("WDS", scriptable);
    scriptEngine.setBindings(engineBindings, ScriptContext.ENGINE_SCOPE);
    return scriptEngine;
}
 
Example #5
Source File: FifoPopPreProcessor.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
public void process() {
    String value = null;
    try {
        Object valueObj = FifoMap.getInstance().pop(getQueueName(), getTimeoutAsLong());
        if (valueObj != null) {
            value = valueObj.toString();
        }
    } catch (InterruptedException ex) {
        log.warn("Interrupted pop from queue " + getQueueName());
        value = "INTERRUPTED";
    }
    final JMeterVariables vars = JMeterContextService.getContext().getVariables();
    if (vars != null) {
        vars.put(getVarName(), value);
    }
}
 
Example #6
Source File: DirectoryListingConfig.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void iterationStart(LoopIterationEvent loopIterationEvent) {
    boolean isIndependentListPerThread = getIndependentListPerThread();

    if (!isIndependentListPerThread && directoryListingIterator == null) {
        throw new JMeterStopThreadException("All files in the directory have been passed.");
    }

    if (getIterator().hasNext()) {
        JMeterVariables variables = JMeterContextService.getContext().getVariables();
        variables.put(
                getStringOrDefault(getDestinationVariableName(), DEFAULT_DESTINATION_VARIABLE_NAME),
                getFilePath(getIterator().next())
        );
    } else {
        // TODO: interrupt iteration
        directoryListingIterator = null;
        throw new JMeterStopThreadException("All files in the directory have been passed.");
    }
}
 
Example #7
Source File: LowerCaseTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Test of execute method, of class LowerCase.
 */
@Test
public void testExecute() throws Exception {
    System.out.println("execute");
    Collection<CompoundVariable> parameters = new ArrayList<CompoundVariable>();
    parameters.add(new CompoundVariable("ABC"));
    parameters.add(new CompoundVariable("var"));

    SampleResult previousResult = null;
    Sampler currentSampler = null;
    LowerCase instance = new LowerCase();
    instance.setParameters(parameters);
    String expResult = "abc";
    String result = instance.execute(previousResult, currentSampler);
    Assert.assertEquals(expResult, result);
    Assert.assertEquals(expResult, JMeterContextService.getContext().getVariables().get("var"));
}
 
Example #8
Source File: SetVariablesActionTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testSample() throws InvalidVariableException {

    System.out.println("next");
    Arguments args = new Arguments();
    args.addArgument("var2", "${var1}");
    args.addArgument("var3", "${var2}");


    instance.setUserDefinedVariables(args);

    ValueReplacer replacer = new ValueReplacer();
    replacer.replaceValues(instance);
    args.setRunningVersion(true);

    instance.sample(null);

    JMeterVariables vars = JMeterContextService.getContext().getVariables();
    assertEquals("${var2}", vars.get("var3"));
    assertEquals("val1", vars.get("var2"));
    instance.sample(null);
    assertEquals("val1", vars.get("var3"));
}
 
Example #9
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testYamlExtractor3() throws IOException {
    File test = new File(getClass().getResource("/test.yml").getPath());
    String response = FileUtils.readFileToString(test);

    JMeterContext context = JMeterContextService.getContext();
    JMeterVariables vars = context.getVariables();

    SampleResult samplerResult = new SampleResult();
    samplerResult.setResponseData(response.getBytes());
    context.setPreviousResult(samplerResult);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setInputFormat(JSONPathExtractor.INPUT_YAML);
    instance.setDefaultValue("DEFAULT");
    instance.setVar("developers");
    instance.setJsonPath("$.developers");
    instance.process();

    assertEquals("[\"rultor\",\"salikjan\",\"sherif\"]", vars.get("developers"));
    assertEquals("3", vars.get("developers_matchNr"));
}
 
Example #10
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcess_from_var() {
    System.out.println("process fromvar");
    JMeterContext context = JMeterContextService.getContext();
    JMeterVariables vars = context.getVariables();

    SampleResult res = new SampleResult();
    res.setResponseData("".getBytes());
    context.setPreviousResult(res);

    vars.put("SVAR", json);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setDefaultValue("DEFAULT");
    instance.setVar("test");
    instance.setJsonPath("$.store.book[*].author");
    instance.setSubject(JSONPathExtractor.SUBJECT_VARIABLE);
    instance.setSrcVariableName("SVAR");
    instance.process();
    assertEquals("[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]", vars.get("test"));
}
 
Example #11
Source File: VirtualUserController.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public Sampler next() {
    if (owner.isLimitReached()) {
        setDone(true);
    } else if (!hasArrived) {
        if (owner.isLimitReached()) {
            throw new IllegalStateException("Should not have more iterations");
        }
        hasArrived = true;
        iterationNo++;
        if (owner instanceof ArrivalsThreadGroup) {
            getOwnerAsArrivals().arrivalFact(JMeterContextService.getContext().getThread(), iterationNo);
            if (!owner.isRunning()) {
                setDone(true);
                return null;
            }
        }
    }

    return super.next();
}
 
Example #12
Source File: RandomCSVDataSetConfig.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
private void readRandom() {
    final RandomCSVReader reader = getReader();
    long lineAddr;
    synchronized (reader) {
        if (reader.hasNextRecord()) {
            lineAddr = reader.getNextLineAddr();
        } else {
            // TODO: interrupt iteration
            if (randomCSVReader != null) {
                randomCSVReader.close();
            }
            randomCSVReader = null;
            throw new JMeterStopThreadException("All records in the CSV file have been passed.");
        }
    }

    JMeterVariables variables = JMeterContextService.getContext().getVariables();
    putVariables(variables, getDestinationVariableKeys(), reader.readLineWithSeek(lineAddr));
}
 
Example #13
Source File: RandomCSVDataSetConfig.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
private void readConsistent() {
    final RandomCSVReader reader = getReader();
    synchronized (reader) {
        if (reader.hasNextRecord()) {
            JMeterVariables variables = JMeterContextService.getContext().getVariables();
            putVariables(variables, getDestinationVariableKeys(), reader.readNextLine());
        } else {
            // TODO: interrupt iteration
            if (randomCSVReader != null) {
                try {
                    randomCSVReader.closeConsistentReader();
                } catch (IOException e) {
                    LOGGER.warn("Failed to close Consistent Reader", e);
                }
            }
            randomCSVReader = null;
            throw new JMeterStopThreadException("All records in the CSV file have been passed.");
        }
    }
}
 
Example #14
Source File: RandomCSVDataSetConfigTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testPutVariables1() throws Exception {
    String path = this.getClass().getResource("/SpaceDelimiter.csv").getPath();

    JMeterVariables jMeterVariables = new JMeterVariables();
    JMeterContextService.getContext().setVariables(jMeterVariables);

    RandomCSVDataSetConfig config = new RandomCSVDataSetConfig();

    config.setFilename(path);
    config.setFileEncoding("UTF-8");
    config.setDelimiter(" ");
    config.setVariableNames("column1,column2");
    config.setRandomOrder(false);
    config.setRewindOnTheEndOfList(false);
    config.setIndependentListPerThread(false);
    config.setIgnoreFirstLine(true);

    config.testStarted();

    config.iterationStart(null);
    assertEquals(2, jMeterVariables.entrySet().size());
    assertEquals("1", jMeterVariables.get("column1"));
    assertEquals("2", jMeterVariables.get("column2"));
}
 
Example #15
Source File: AbstractOverTimeVisualizer.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void add(SampleResult sample) {
    if (relativeStartTime == 0) {
        // 
        if(!isIgnoreCurrentTestStartTime()){
            relativeStartTime = JMeterContextService.getTestStartTime(); 
        }
        isJtlLoad = false;
        if (relativeStartTime == 0) {
            relativeStartTime = sample.getStartTime();
            isJtlLoad = true;
        }
        relativeStartTime = relativeStartTime - relativeStartTime%getGranulation();
        handleRelativeStartTime();
    }
    if(isJtlLoad) {
        if(relativeStartTime > sample.getStartTime()) {
            relativeStartTime = sample.getStartTime() - sample.getStartTime()%getGranulation();
            handleRelativeStartTime();
        }
    }
}
 
Example #16
Source File: JMXMonCollector.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
   * Update the worker thread jmeter context with the main thread one
   * @param isInit if true the context a full copy is done, if false only update is done
   */
  private void syncContext(boolean isInit)
  {
  	// jmeter context synchronisation
  	JMeterContext current = JMeterContextService.getContext();
JMeterContext ctx = this.getThreadContext();

if (isInit)
{
	current.setCurrentSampler(ctx.getCurrentSampler());
	current.setEngine(ctx.getEngine());
	current.setRestartNextLoop(ctx.isRestartNextLoop());
	current.setSamplingStarted(ctx.isSamplingStarted());
	current.setThread(ctx.getThread());
	current.setThreadGroup(ctx.getThreadGroup());
	current.setThreadNum(ctx.getThreadNum());
}
current.setVariables(ctx.getVariables());
current.setPreviousResult(ctx.getPreviousResult());
//current.getSamplerContext().putAll(ctx.getSamplerContext());
  }
 
Example #17
Source File: UpperCaseTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Test of execute method, of class UpperCase.
 */
@Test
public void testExecute() throws Exception {
    System.out.println("execute");
    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable("abc"));
    parameters.add(new CompoundVariable("var"));

    SampleResult previousResult = null;
    Sampler currentSampler = null;
    UpperCase instance = new UpperCase();
    instance.setParameters(parameters);
    String expResult = "ABC";
    String result = instance.execute(null, null);
    Assert.assertEquals(expResult, result);
    Assert.assertEquals(expResult, JMeterContextService.getContext().getVariables().get("var"));
}
 
Example #18
Source File: PlainTextConfigElement.java    From pepper-box with Apache License 2.0 6 votes vote down vote up
/**
 * For every JMeter sample, iterationStart method gets invoked, it initializes load generator and for each iteration sets new message as JMeter variable
 *
 * @param loopIterationEvent
 */
@Override
public void iterationStart(LoopIterationEvent loopIterationEvent) {

    //Check if load generator is instantiated
    if (generator == null) {

        try {

            //instantiate plaintext load generator
            generator = new PlaintTextLoadGenerator(getJsonSchema());

        } catch (Exception e) {
            log.error("Failed to create PlaintTextLoadGenerator instance", e);
        }

    }

    //For ever iteration put message in jmeter variables
    JMeterVariables variables = JMeterContextService.getContext().getVariables();
    variables.putObject(placeHolder, generator.nextMessage());
}
 
Example #19
Source File: SerializedConfigElement.java    From pepper-box with Apache License 2.0 6 votes vote down vote up
/**
 * For every JMeter sample, iterationStart method gets invoked, it initializes load generator and for each iteration sets new message as JMeter variable
 *
 * @param loopIterationEvent
 */
@Override
public void iterationStart(LoopIterationEvent loopIterationEvent) {

    try {
        //Check if load generator is instantiated
        if (generator == null) {

            //instantiate serialized load generator
            generator = new SerializedLoadGenerator(className, objProperties);

        }

        //For ever iteration put message in jmeter variables
        JMeterVariables variables = JMeterContextService.getContext().getVariables();
        variables.putObject(placeHolder, generator.nextMessage());
    } catch (Exception e) {
        log.error("Failed to create PlaintTextLoadGenerator instance", e);
    }
}
 
Example #20
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testReported1() {
    System.out.println("process reported");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData(json2.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setVar("GroupID");
    instance.setJsonPath("$.data.groups[?(@.name=='Zaz')].id");
    instance.setDefaultValue("NOTFOUND");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertNotEquals("NOTFOUND", vars.get("GroupID"));
    assertEquals("378e9b20-99bb-4d1f-bf2c-6a4a6c69a8ed", vars.get("GroupID_1"));
}
 
Example #21
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testReported1_3() {
    System.out.println("process reported");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData(json2.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setVar("GroupID");
    instance.setJsonPath("$.data.groups[?(@.name==Avtovaz)].id");
    instance.setDefaultValue("NOTFOUND");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertEquals("NOTFOUND", vars.get("GroupID"));
}
 
Example #22
Source File: PepperBoxLoadGenTest.java    From pepper-box with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {

    zkServer = new EmbeddedZookeeper();

    String zkConnect = ZKHOST + ":" + zkServer.port();
    zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = ZkUtils.apply(zkClient, false);

    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST +":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);
    //AdminUtils.createTopic(zkUtils, TOPIC, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

    JMeterContext jmcx = JMeterContextService.getContext();
    jmcx.setVariables(new JMeterVariables());

}
 
Example #23
Source File: AbstractSimpleThreadGroup.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void start(int groupNum, ListenerNotifier notifier, ListedHashTree threadGroupTree, StandardJMeterEngine engine) {
    running = true;

    int numThreads = getNumThreads();

    log.info("Starting thread group number " + groupNum + " threads " + numThreads);

    long now = System.currentTimeMillis(); // needs to be same time for all threads in the group
    final JMeterContext context = JMeterContextService.getContext();
    for (int i = 0; running && i < numThreads; i++) {
        JMeterThread jmThread = makeThread(groupNum, notifier, threadGroupTree, engine, i, context);
        scheduleThread(jmThread, now); // set start and end time
        Thread newThread = new Thread(jmThread, jmThread.getThreadName());
        registerStartedThread(jmThread, newThread);
        newThread.start();
    }

    log.info("Started thread group number " + groupNum);
}
 
Example #24
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcess_chinese() {
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    String chinese = "{\"carBrandName\":\"大众\"}";

    res.setResponseData(chinese.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setDefaultValue("DEFAULT");
    instance.setVar("test");
    instance.setJsonPath("$.carBrandName");
    instance.process();
    JMeterVariables vars = context.getVariables();
    // freaking "static final" DEFAULT_ENCODING field in SampleResult does not allow us to assert this
    // assertEquals("大众", vars.get("test"));
}
 
Example #25
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcess() {
    System.out.println("process");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData(json.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setDefaultValue("DEFAULT");
    instance.setVar("test");
    instance.setJsonPath("$.store.book[*].author");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertEquals("[\"Nigel Rees\",\"Evelyn Waugh\",\"Herman Melville\",\"J. R. R. Tolkien\"]", vars.get("test"));
}
 
Example #26
Source File: JSONPathExtractorTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test // FIXME: we need to solve this one day
public void testReported2() {
    System.out.println("process reported");
    JMeterContext context = JMeterContextService.getContext();
    SampleResult res = new SampleResult();
    res.setResponseData(json3.getBytes());
    context.setPreviousResult(res);

    JSONPathExtractor instance = new JSONPathExtractor();
    instance.setVar("var");
    instance.setJsonPath("$.data[?(@.attr.value>0)][0].attr");
    instance.setDefaultValue("NOTFOUND");
    instance.process();
    JMeterVariables vars = context.getVariables();
    assertNotEquals("NOTFOUND", vars.get("var"));
    assertEquals("{value=1}", vars.get("var"));
}
 
Example #27
Source File: Debugger.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
public void start() {
    log.debug("Start debugging");
    frontend.started();

    HashTree hashTree = getSelectedTree();
    StandardJMeterEngine.register(new StateListener()); // oh, dear, they use static field then clean it...
    engine = new DebuggerEngine(JMeterContextService.getContext());
    engine.setStepper(this);
    JMeter.convertSubTree(hashTree);
    engine.configure(hashTree);
    try {
        engine.runTest();
    } catch (JMeterEngineException e) {
        log.error("Failed to pauseContinue debug", e);
        stop();
    }
}
 
Example #28
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
@Test
public void runDebugEngine() throws Exception {
    TestProvider prov = new TestProvider();

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(88, hook.cnt);
}
 
Example #29
Source File: MonitoringResultsCollector.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
   * Update the worker thread jmeter context with the main thread one
   * @param isInit if true the context a full copy is done, if false only update is done
   */
  private void syncContext(boolean isInit)
  {
  	// jmeter context synchronisation
  	JMeterContext current = JMeterContextService.getContext();
JMeterContext ctx = this.getThreadContext();

if (isInit)
{
	current.setCurrentSampler(ctx.getCurrentSampler());
	current.setEngine(ctx.getEngine());
	current.setRestartNextLoop(ctx.isRestartNextLoop());
	current.setSamplingStarted(ctx.isSamplingStarted());
	current.setThread(ctx.getThread());
	current.setThreadGroup(ctx.getThreadGroup());
	current.setThreadNum(ctx.getThreadNum());
}
current.setVariables(ctx.getVariables());
current.setPreviousResult(ctx.getPreviousResult());
//current.getSamplerContext().putAll(ctx.getSamplerContext());
  }
 
Example #30
Source File: Base64DecodeTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@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"));
}