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;
}
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"));
}
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());
}
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();
}
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;
}
Aggregations