Search in sources :

Example 21 with Sampler

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());
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) ReplaceStringWithFunctions(org.apache.jmeter.engine.util.ReplaceStringWithFunctions) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) HashMap(java.util.HashMap) StringProperty(org.apache.jmeter.testelement.property.StringProperty) JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) TestSampler(org.apache.jmeter.junit.stubs.TestSampler) Sampler(org.apache.jmeter.samplers.Sampler) TestSampler(org.apache.jmeter.junit.stubs.TestSampler) Test(org.junit.Test)

Example 22 with Sampler

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);
}
Also used : TestSampler(org.apache.jmeter.junit.stubs.TestSampler) Sampler(org.apache.jmeter.samplers.Sampler) TestSampler(org.apache.jmeter.junit.stubs.TestSampler) Test(org.junit.Test)

Example 23 with Sampler

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;
}
Also used : Sampler(org.apache.jmeter.samplers.Sampler)

Example 24 with Sampler

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;
}
Also used : Sampler(org.apache.jmeter.samplers.Sampler)

Example 25 with Sampler

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;
}
Also used : Sampler(org.apache.jmeter.samplers.Sampler) SampleResult(org.apache.jmeter.samplers.SampleResult)

Aggregations

Sampler (org.apache.jmeter.samplers.Sampler)33 SampleResult (org.apache.jmeter.samplers.SampleResult)11 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)9 JMeterContext (org.apache.jmeter.threads.JMeterContext)9 Test (org.junit.Test)9 TransactionSampler (org.apache.jmeter.control.TransactionSampler)6 DebugSampler (org.apache.jmeter.sampler.DebugSampler)6 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)5 Controller (org.apache.jmeter.control.Controller)3 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)3 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)3 JMeterStopTestException (org.apache.jorphan.util.JMeterStopTestException)3 JMeterStopTestNowException (org.apache.jorphan.util.JMeterStopTestNowException)3 JMeterStopThreadException (org.apache.jorphan.util.JMeterStopThreadException)3 Logger (org.slf4j.Logger)3 Properties (java.util.Properties)2 Argument (org.apache.jmeter.config.Argument)2 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)2 TestElement (org.apache.jmeter.testelement.TestElement)2 Cache (com.github.benmanes.caffeine.cache.Cache)1