Search in sources :

Example 1 with DebugSampler

use of org.apache.jmeter.sampler.DebugSampler in project jmeter by apache.

the class TestTransactionController method testIssue57958.

/**
     * @see "http://bz.apache.org/bugzilla/show_bug.cgi?id=57958"
     */
@Test
public void testIssue57958() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    TestSampleListener listener = new TestSampleListener();
    TransactionController transactionController = new TransactionController();
    transactionController.setGenerateParentSample(true);
    ResponseAssertion assertion = new ResponseAssertion();
    assertion.setTestFieldResponseCode();
    assertion.setToEqualsType();
    assertion.addTestString("201");
    DebugSampler debugSampler = new DebugSampler();
    debugSampler.addTestElement(assertion);
    LoopController loop = new LoopController();
    loop.setLoops(1);
    loop.setContinueForever(false);
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, transactionController);
    hashTree.add(transactionController, debugSampler);
    hashTree.add(transactionController, listener);
    hashTree.add(debugSampler, assertion);
    TestCompiler compiler = new TestCompiler(hashTree);
    hashTree.traverse(compiler);
    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setNumThreads(1);
    ListenerNotifier notifier = new ListenerNotifier();
    JMeterThread thread = new JMeterThread(hashTree, threadGroup, notifier);
    thread.setThreadGroup(threadGroup);
    thread.setOnErrorStopThread(true);
    thread.run();
    assertEquals("Must one transaction samples with parent debug sample", 1, listener.events.size());
    assertEquals("Number of samples in transaction : 1, number of failing samples : 1", listener.events.get(0).getResult().getResponseMessage());
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) ListedHashTree(org.apache.jorphan.collections.ListedHashTree) ResponseAssertion(org.apache.jmeter.assertions.ResponseAssertion) DebugSampler(org.apache.jmeter.sampler.DebugSampler) TestCompiler(org.apache.jmeter.threads.TestCompiler) ThreadGroup(org.apache.jmeter.threads.ThreadGroup) JMeterThread(org.apache.jmeter.threads.JMeterThread) ListenerNotifier(org.apache.jmeter.threads.ListenerNotifier) Test(org.junit.Test)

Example 2 with DebugSampler

use of org.apache.jmeter.sampler.DebugSampler in project jmeter by apache.

the class TestIfController method testBug53768.

/**
     * See Bug 53768
     * 
     * @throws Exception
     *             if something fails
     */
@Test
public void testBug53768() throws Exception {
    LoopController controller = new LoopController();
    controller.setLoops(1);
    controller.setContinueForever(false);
    Arguments arguments = new Arguments();
    arguments.addArgument("VAR1", "0", "=");
    DebugSampler debugSampler1 = new DebugSampler();
    debugSampler1.setName("VAR1 = ${VAR1}");
    IfController ifCont = new IfController("true==false");
    ifCont.setUseExpression(false);
    ifCont.setEvaluateAll(false);
    IfController ifCont2 = new IfController("true==true");
    ifCont2.setUseExpression(false);
    ifCont2.setEvaluateAll(false);
    CounterConfig counterConfig = new CounterConfig();
    counterConfig.setStart(1);
    counterConfig.setIncrement(1);
    counterConfig.setVarName("VAR1");
    DebugSampler debugSampler2 = new DebugSampler();
    debugSampler2.setName("VAR1 = ${VAR1}");
    controller.addTestElement(arguments);
    controller.addTestElement(debugSampler1);
    controller.addTestElement(ifCont);
    ifCont.addTestElement(ifCont2);
    ifCont2.addTestElement(counterConfig);
    controller.addTestElement(debugSampler2);
    controller.initialize();
    controller.setRunningVersion(true);
    ifCont.setRunningVersion(true);
    ifCont2.setRunningVersion(true);
    counterConfig.setRunningVersion(true);
    arguments.setRunningVersion(true);
    debugSampler1.setRunningVersion(true);
    debugSampler2.setRunningVersion(true);
    ifCont2.addIterationListener(counterConfig);
    JMeterVariables vars = new JMeterVariables();
    JMeterContext jmctx = JMeterContextService.getContext();
    jmctx.setVariables(vars);
    vars.put("VAR1", "0");
    try {
        Sampler sampler = controller.next();
        sampler.sample(null);
        assertEquals("0", vars.get("VAR1"));
        sampler = controller.next();
        sampler.sample(null);
        assertEquals("0", vars.get("VAR1"));
    } catch (StackOverflowError e) {
        fail("Stackoverflow occurred in testStackOverflow");
    }
}
Also used : JMeterVariables(org.apache.jmeter.threads.JMeterVariables) DebugSampler(org.apache.jmeter.sampler.DebugSampler) JMeterContext(org.apache.jmeter.threads.JMeterContext) CounterConfig(org.apache.jmeter.modifiers.CounterConfig) DebugSampler(org.apache.jmeter.sampler.DebugSampler) TestSampler(org.apache.jmeter.junit.stubs.TestSampler) Sampler(org.apache.jmeter.samplers.Sampler) Arguments(org.apache.jmeter.config.Arguments) Test(org.junit.Test)

Aggregations

DebugSampler (org.apache.jmeter.sampler.DebugSampler)2 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)2 Test (org.junit.Test)2 ResponseAssertion (org.apache.jmeter.assertions.ResponseAssertion)1 Arguments (org.apache.jmeter.config.Arguments)1 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)1 CounterConfig (org.apache.jmeter.modifiers.CounterConfig)1 Sampler (org.apache.jmeter.samplers.Sampler)1 JMeterContext (org.apache.jmeter.threads.JMeterContext)1 JMeterThread (org.apache.jmeter.threads.JMeterThread)1 ListenerNotifier (org.apache.jmeter.threads.ListenerNotifier)1 TestCompiler (org.apache.jmeter.threads.TestCompiler)1 ThreadGroup (org.apache.jmeter.threads.ThreadGroup)1 ListedHashTree (org.apache.jorphan.collections.ListedHashTree)1