use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class TestIfController method testEvaluateAllChildrenWithoutSubController.
/**
* Test false return on sample3 (sample4 doesn't execute)
*
* @throws Exception
* if something fails
*/
@Test
public void testEvaluateAllChildrenWithoutSubController() throws Exception {
LoopController controller = new LoopController();
controller.setLoops(2);
controller.addTestElement(new TestSampler("Sample1"));
IfController ifCont = new IfController("true==true");
ifCont.setEvaluateAll(true);
controller.addTestElement(ifCont);
ifCont.addTestElement(new TestSampler("Sample2"));
TestSampler sample3 = new TestSampler("Sample3");
ifCont.addTestElement(sample3);
TestSampler sample4 = new TestSampler("Sample4");
ifCont.addTestElement(sample4);
String[] order = new String[] { "Sample1", "Sample2", "Sample3", "Sample1", "Sample2", "Sample3" };
int counter = 0;
controller.initialize();
controller.setRunningVersion(true);
ifCont.setRunningVersion(true);
Sampler sampler = null;
while ((sampler = controller.next()) != null) {
sampler.sample(null);
if (sampler.getName().equals("Sample3")) {
ifCont.setCondition("true==false");
}
assertEquals(order[counter], sampler.getName());
counter++;
}
assertEquals(counter, 6);
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class TestIfController method testStackOverflow.
/**
* See Bug 56160
*
* @throws Exception
* if something fails
*/
@Test
public void testStackOverflow() throws Exception {
LoopController controller = new LoopController();
controller.setLoops(1);
controller.setContinueForever(false);
IfController ifCont = new IfController("true==false");
ifCont.setUseExpression(false);
ifCont.setEvaluateAll(false);
WhileController whileController = new WhileController();
whileController.setCondition("${__javaScript(\"true\" != \"false\")}");
whileController.addTestElement(new TestSampler("Sample1"));
controller.addTestElement(ifCont);
ifCont.addTestElement(whileController);
Sampler sampler = null;
int counter = 0;
controller.initialize();
controller.setRunningVersion(true);
ifCont.setRunningVersion(true);
whileController.setRunningVersion(true);
try {
while ((sampler = controller.next()) != null) {
sampler.sample(null);
counter++;
}
assertEquals(0, counter);
} catch (StackOverflowError e) {
fail("Stackoverflow occurred in testStackOverflow");
}
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class TestIfController method testProcessingTrue.
@Test
public void testProcessingTrue() throws Exception {
LoopController controller = new LoopController();
controller.setLoops(2);
controller.addTestElement(new TestSampler("Sample1"));
IfController ifCont = new IfController("true==true");
ifCont.setEvaluateAll(true);
ifCont.addTestElement(new TestSampler("Sample2"));
TestSampler sample3 = new TestSampler("Sample3");
ifCont.addTestElement(sample3);
controller.addTestElement(ifCont);
String[] order = new String[] { "Sample1", "Sample2", "Sample3", "Sample1", "Sample2", "Sample3" };
int counter = 0;
controller.initialize();
controller.setRunningVersion(true);
ifCont.setRunningVersion(true);
Sampler sampler = null;
while ((sampler = controller.next()) != null) {
sampler.sample(null);
assertEquals(order[counter], sampler.getName());
counter++;
}
assertEquals(counter, 6);
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class TimeShift method execute.
/** {@inheritDoc} */
@Override
public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
String dateString;
LocalDateTime localDateTimeToShift = LocalDateTime.now(systemDefaultZoneID);
DateTimeFormatter formatter = null;
if (!StringUtils.isEmpty(format)) {
try {
formatter = dateTimeFormatterCache.get(format, key -> createFormatter((String) key));
} catch (IllegalArgumentException ex) {
// $NON-NLS-1$
log.error("Format date pattern '{}' is invalid (see https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html)", format, ex);
return "";
}
}
if (!dateToShift.isEmpty()) {
try {
if (formatter != null) {
localDateTimeToShift = LocalDateTime.parse(dateToShift, formatter);
} else {
localDateTimeToShift = LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(dateToShift)), ZoneId.systemDefault());
}
} catch (DateTimeParseException | NumberFormatException ex) {
// $NON-NLS-1$
log.error("Failed to parse the date '{}' to shift", dateToShift, ex);
}
}
// Check amount value to shift
if (!StringUtils.isEmpty(amountToShift)) {
try {
Duration duration = Duration.parse(amountToShift);
localDateTimeToShift = localDateTimeToShift.plus(duration);
} catch (DateTimeParseException ex) {
// $NON-NLS-1$
log.error("Failed to parse the amount duration '{}' to shift (see https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html#parse-java.lang.CharSequence-) ", amountToShift, ex);
}
}
if (formatter != null) {
dateString = localDateTimeToShift.format(formatter);
} else {
ZoneOffset offset = ZoneOffset.systemDefault().getRules().getOffset(localDateTimeToShift);
dateString = String.valueOf(localDateTimeToShift.toInstant(offset).toEpochMilli());
}
if (!StringUtils.isEmpty(variableName)) {
JMeterVariables vars = getVariables();
if (vars != null) {
// vars will be null on TestPlan
vars.put(variableName, dateString);
}
}
return dateString;
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class TestURLRewritingModifier method testNonHTTPSampler.
@Test
public void testNonHTTPSampler() throws Exception {
Sampler sampler = new NullSampler();
response = new SampleResult();
context.setCurrentSampler(sampler);
context.setPreviousResult(response);
mod.process();
}
Aggregations