use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class TestLoopController method testBug54467.
@Test
public void testBug54467() throws Exception {
JMeterContext jmctx = JMeterContextService.getContext();
LoopController loop = new LoopController();
Map<String, String> variables = new HashMap<>();
ReplaceStringWithFunctions transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables);
jmctx.setVariables(new JMeterVariables());
StringProperty prop = new StringProperty(LoopController.LOOPS, "${__Random(1,12,)}");
JMeterProperty newProp = transformer.transformValue(prop);
newProp.setRunningVersion(true);
loop.setProperty(newProp);
loop.addTestElement(new TestSampler("random run"));
loop.setRunningVersion(true);
loop.initialize();
int loops = loop.getLoops();
for (int i = 0; i < loops; i++) {
Sampler s = loop.next();
assertNotNull(s);
}
assertNull(loop.next());
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class TestRunTime method testProcessing.
@Test
public void testProcessing() throws Exception {
RunTime controller = new RunTime();
controller.setRuntime(10);
TestSampler samp1 = new TestSampler("Sample 1", 500);
TestSampler samp2 = new TestSampler("Sample 2", 480);
LoopController sub1 = new LoopController();
sub1.setLoops(2);
sub1.setContinueForever(false);
sub1.addTestElement(samp1);
LoopController sub2 = new LoopController();
sub2.setLoops(40);
sub2.setContinueForever(false);
sub2.addTestElement(samp2);
controller.addTestElement(sub1);
controller.addTestElement(sub2);
controller.setRunningVersion(true);
sub1.setRunningVersion(true);
sub2.setRunningVersion(true);
controller.initialize();
Sampler sampler = null;
int loops = 0;
long now = System.currentTimeMillis();
while ((sampler = controller.next()) != null) {
loops++;
sampler.sample(null);
}
long elapsed = System.currentTimeMillis() - now;
assertTrue("Should be at least 20 loops " + loops, loops >= 20);
assertTrue("Should be fewer than 30 loops " + loops, loops < 30);
assertTrue("Should take at least 10 seconds " + elapsed, elapsed >= 10000);
assertTrue("Should take less than 12 seconds " + elapsed, elapsed <= 12000);
assertEquals("Sampler 1 should run 2 times", 2, samp1.getSamples());
assertTrue("Sampler 2 should run >= 18 times", samp2.getSamples() >= 18);
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class TransactionController method nextWithTransactionSampler.
///////////////// Transaction Controller - parent ////////////////
private Sampler nextWithTransactionSampler() {
// Check if transaction is done
if (transactionSampler != null && transactionSampler.isTransactionDone()) {
if (log.isDebugEnabled()) {
log.debug("End of transaction {}", getName());
}
// This transaction is done
transactionSampler = null;
return null;
}
// Check if it is the start of a new transaction
if (// must be the start of the subtree
isFirst()) {
if (log.isDebugEnabled()) {
log.debug("Start of transaction {}", getName());
}
transactionSampler = new TransactionSampler(this, getName());
}
// Sample the children of the transaction
Sampler subSampler = super.next();
transactionSampler.setSubSampler(subSampler);
// If we do not get any sub samplers, the transaction is done
if (subSampler == null) {
transactionSampler.setTransactionDone();
}
return transactionSampler;
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class TransactionController method nextIsAController.
@Override
protected Sampler nextIsAController(Controller controller) throws NextIsNullException {
if (!isGenerateParentSample()) {
return super.nextIsAController(controller);
}
Sampler returnValue;
Sampler sampler = controller.next();
if (sampler == null) {
currentReturnedNull(controller);
// We need to call the super.next, instead of this.next, which is done in GenericController,
// because if we call this.next(), it will return the TransactionSampler, and we do not want that.
// We need to get the next real sampler or controller
returnValue = super.next();
} else {
returnValue = sampler;
}
return returnValue;
}
use of org.apache.jmeter.samplers.Sampler in project jmeter by apache.
the class TransactionController method nextWithoutTransactionSampler.
////////////////////// Transaction Controller - additional sample //////////////////////////////
private Sampler nextWithoutTransactionSampler() {
if (// must be the start of the subtree
isFirst()) {
calls = 0;
noFailingSamples = 0;
res = new SampleResult();
res.setSampleLabel(getName());
// Assume success
res.setSuccessful(true);
res.sampleStart();
//???
prevEndTime = res.getStartTime();
pauseTime = 0;
}
boolean isLast = current == super.subControllersAndSamplers.size();
Sampler returnValue = super.next();
if (// Must be the end of the controller
returnValue == null && isLast) {
if (res != null) {
// See BUG 55816
if (!isIncludeTimers()) {
long processingTimeOfLastChild = res.currentTimeInMillis() - prevEndTime;
pauseTime += processingTimeOfLastChild;
}
res.setIdleTime(pauseTime + res.getIdleTime());
res.sampleEnd();
res.setResponseMessage(TransactionController.NUMBER_OF_SAMPLES_IN_TRANSACTION_PREFIX + calls + ", number of failing samples : " + noFailingSamples);
if (res.isSuccessful()) {
res.setResponseCodeOK();
}
notifyListeners();
}
} else {
// We have sampled one of our children
calls++;
}
return returnValue;
}
Aggregations