Java Code Examples for org.apache.jorphan.collections.ListedHashTree#add()

The following examples show how to use org.apache.jorphan.collections.ListedHashTree#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeedbackSessionViewLNPTest.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected ListedHashTree getLnpTestPlan() {
    ListedHashTree testPlan = new ListedHashTree(JMeterElements.testPlan());
    HashTree threadGroup = testPlan.add(
            JMeterElements.threadGroup(NUMBER_OF_USER_ACCOUNTS, RAMP_UP_PERIOD, 1));
    threadGroup.add(JMeterElements.csvDataSet(getPathToTestDataFile(getCsvConfigPath())));
    threadGroup.add(JMeterElements.cookieManager());
    threadGroup.add(JMeterElements.defaultSampler());
    threadGroup.add(JMeterElements.onceOnlyController())
            .add(JMeterElements.loginSampler());

    // Add HTTP samplers for test endpoint
    String getSessionsPath = "webapi/student?courseid=${courseId}";
    threadGroup.add(JMeterElements.httpSampler(getSessionsPath, GET, null));

    String getSessionDetailsPath = "webapi/session?courseid=${courseId}&fsname=${fsname}&intent=STUDENT_SUBMISSION";
    threadGroup.add(JMeterElements.httpSampler(getSessionDetailsPath, GET, null));

    String getQuestionsPath = "webapi/questions?courseid=${courseId}&fsname=${fsname}&intent=STUDENT_SUBMISSION";
    threadGroup.add(JMeterElements.httpSampler(getQuestionsPath, GET, null));

    return testPlan;
}
 
Example 2
Source File: StudentProfileLNPTest.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected ListedHashTree getLnpTestPlan() {
    ListedHashTree testPlan = new ListedHashTree(JMeterElements.testPlan());
    HashTree threadGroup = testPlan.add(
            JMeterElements.threadGroup(NUMBER_OF_USER_ACCOUNTS, RAMP_UP_PERIOD, 1));

    threadGroup.add(JMeterElements.csvDataSet(getPathToTestDataFile(getCsvConfigPath())));
    threadGroup.add(JMeterElements.cookieManager());
    threadGroup.add(JMeterElements.defaultSampler());
    threadGroup.add(JMeterElements.onceOnlyController())
            .add(JMeterElements.loginSampler());

    // Add HTTP sampler for test endpoint
    threadGroup.add(JMeterElements.httpGetSampler(getTestEndpoint()));

    return testPlan;
}
 
Example 3
Source File: FeedbackSessionSubmitLNPTest.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected ListedHashTree getLnpTestPlan() {
    ListedHashTree testPlan = new ListedHashTree(JMeterElements.testPlan());
    HashTree threadGroup = testPlan.add(
            JMeterElements.threadGroup(NUMBER_OF_USER_ACCOUNTS, RAMP_UP_PERIOD, 1));
    threadGroup.add(JMeterElements.csvDataSet(getPathToTestDataFile(getCsvConfigPath())));
    threadGroup.add(JMeterElements.cookieManager());
    threadGroup.add(JMeterElements.defaultSampler());
    threadGroup.add(JMeterElements.onceOnlyController())
            .add(JMeterElements.loginSampler())
            .add(JMeterElements.csrfExtractor("csrfToken"));

    HeaderManager headerManager = JMeterElements.headerManager(getRequestHeaders());
    threadGroup.add(headerManager);

    for (int i = 1; i <= NUMBER_OF_QUESTIONS; i++) {
        String body = "{\"questionType\": \"TEXT\","
                + "\"recipientIdentifier\": \"${studentEmail}\","
                + "\"responseDetails\": {\"answer\": \"<p>test</p>\", \"questionType\": \"TEXT\"}}";
        String path = "webapi/response?questionid=${question" + i + "id}"
                + "&intent=STUDENT_SUBMISSION";
        threadGroup.add(JMeterElements.httpSampler(path, POST, body));
    }

    return testPlan;
}
 
Example 4
Source File: InstructorStudentEnrollmentLNPTest.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected ListedHashTree getLnpTestPlan() {
    ListedHashTree testPlan = new ListedHashTree(JMeterElements.testPlan());
    HashTree threadGroup = testPlan.add(
            JMeterElements.threadGroup(NUM_INSTRUCTORS, RAMP_UP_PERIOD, 1));

    threadGroup.add(JMeterElements.csvDataSet(getPathToTestDataFile(getCsvConfigPath())));
    threadGroup.add(JMeterElements.cookieManager());
    threadGroup.add(JMeterElements.defaultSampler());

    threadGroup.add(JMeterElements.onceOnlyController())
            .add(JMeterElements.loginSampler())
            .add(JMeterElements.csrfExtractor("csrfToken"));

    // Add HTTP sampler for test endpoint
    HeaderManager headerManager = JMeterElements.headerManager(getRequestHeaders());
    threadGroup.add(JMeterElements.httpSampler(getTestEndpoint(), PUT, "${enrollData}"))
            .add(headerManager);

    return testPlan;
}
 
Example 5
Source File: InstructorSessionResultLNPTest.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected ListedHashTree getLnpTestPlan() {
    ListedHashTree testPlan = new ListedHashTree(JMeterElements.testPlan());
    HashTree threadGroup = testPlan.add(
            JMeterElements.threadGroup(1, RAMP_UP_PERIOD, 1));

    threadGroup.add(JMeterElements.csvDataSet(getPathToTestDataFile(getCsvConfigPath())));
    threadGroup.add(JMeterElements.cookieManager());
    threadGroup.add(JMeterElements.defaultSampler());
    threadGroup.add(JMeterElements.onceOnlyController())
            .add(JMeterElements.loginSampler());

    // Set query param.
    Map<String, String> sectionsArgumentsMap = new HashMap<>();
    sectionsArgumentsMap.put("courseid", "${courseId}");

    Map<String, String> argumentsMap = new HashMap<>(sectionsArgumentsMap);
    argumentsMap.put("fsname", "${fsname}");
    argumentsMap.put("intent", "INSTRUCTOR_RESULT");

    addLoadPageController(threadGroup, argumentsMap);
    addLoadSectionsController(threadGroup, sectionsArgumentsMap);
    addLoadNoResponsePanelController(threadGroup, argumentsMap);
    addLoadQuestionPanelController(threadGroup, argumentsMap);
    addLoadSectionPanelController(threadGroup, argumentsMap);

    return testPlan;
}
 
Example 6
Source File: ArrivalsThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
public static ListedHashTree getListedHashTree(AbstractThreadGroup atg, boolean stopThread) {
    ListedHashTree tree = new ListedHashTree();
    TestAction pauser = new TestAction();
    if (stopThread) {
        pauser.setAction(TestAction.STOP);
    } else {
        pauser.setAction(TestAction.PAUSE);
    }
    pauser.setTarget(TestAction.THREAD);

    pauser.setDuration(String.valueOf(300));
    tree.add(atg, pauser);
    return tree;
}
 
Example 7
Source File: ParallelSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test(timeout=3000)
public void testStartNextIteration() {
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    TestSampleListener listener = new TestSampleListener();

    TestAction action = new TestAction();
    action.setAction(3);

    DebugSampler samplerBefore = new DebugSampler();
    samplerBefore.setName("samplerBefore");

    DebugSampler samplerAfter = new DebugSampler();
    samplerAfter.setName("samplerAfter");

    WhileController whileController = new WhileController();

    ParallelSampler sampler = new ParallelSampler();
    sampler.setGenerateParent(true);
    LoopController loop = new LoopController();
    loop.setLoops(2);
    loop.setContinueForever(false);

    // parallel subtree
    ListedHashTree parallelTree = new ListedHashTree();
    parallelTree.add(samplerBefore);
    parallelTree.add(action);

    // while subtree
    ListedHashTree whileTree = new ListedHashTree();
    whileTree.add(whileController, parallelTree);

    // parallel Sampler subtree
    ListedHashTree parallelSamplerTree = new ListedHashTree();
    parallelSamplerTree.add(sampler, whileTree);

    // TG sub tree
    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setNumThreads(1);
    threadGroup.setSamplerController(loop);

    ListedHashTree loopTree = new ListedHashTree();
    loopTree.add(threadGroup, parallelSamplerTree);
    loopTree.add(threadGroup, samplerAfter);
    loopTree.add(threadGroup, listener);

    TestCompiler compiler = new TestCompiler(loopTree);
    loopTree.traverse(compiler);

    ListenerNotifier notifier = new ListenerNotifier();

    JMeterThread thread = new JMeterThread(loopTree, threadGroup, notifier);
    thread.setThreadGroup(threadGroup);
    thread.setEngine(new StandardJMeterEngine());
    thread.setOnErrorStopThread(true);
    thread.run();

    assertEquals(2, listener.events.size());
}
 
Example 8
Source File: ParallelSamplerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test(timeout=3000)
public void testInfinityStopTest() {
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    TestSampleListener listener = new TestSampleListener();

    TestAction action = new TestAction();
    action.setAction(0);
    action.setTarget(2);

    WhileController whileController = new WhileController();

    ParallelSampler sampler = new ParallelSampler();
    sampler.setGenerateParent(true);
    LoopController loop = new LoopController();
    loop.setLoops(1);
    loop.setContinueForever(false);

    // test tree
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, sampler);
    hashTree.add(sampler, listener);
    hashTree.add(sampler, whileController);
    hashTree.add(whileController, action);
    hashTree.add(whileController, listener);

    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.setEngine(new StandardJMeterEngine());
    thread.run();

    assertEquals(1, listener.events.size());
}
 
Example 9
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testNestedWSC() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());


    TestSampleListener listener = new TestSampleListener();

    // top WSC
    WeightedSwitchController topWSC = new WeightedSwitchController();
    PowerTableModel topPTM = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    topPTM.addRow(new String[]{"wsc1", "2"});
    topPTM.addRow(new String[]{"wsc2", "2"});
    topPTM.addRow(new String[]{"D_#1", "1"});
    topPTM.addRow(new String[]{"D_#2", "1"});
    topWSC.setData(topPTM);

    DebugSampler d1 = new DebugSampler();
    d1.setName("D_#1");
    DebugSampler d2 = new DebugSampler();
    d2.setName("D_#2");

    // first child WSC of top WSC
    WeightedSwitchController childWSC1 = new WeightedSwitchController();
    childWSC1.setName("wsc1");
    PowerTableModel childPTM1 = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    childPTM1.addRow(new String[]{"D1_#1", "1"});
    childPTM1.addRow(new String[]{"D1_#2", "1"});
    childWSC1.setData(childPTM1);

    DebugSampler d1_1 = new DebugSampler();
    d1_1.setName("D1_#1");
    DebugSampler d1_2 = new DebugSampler();
    d1_2.setName("D1_#2");

    // second child WSC of top WSC
    WeightedSwitchController childWSC2 = new WeightedSwitchController();
    childWSC2.setName("wsc2");
    PowerTableModel childPTM2 = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    childPTM2.addRow(new String[]{"D2_#1", "1"});
    childPTM2.addRow(new String[]{"D2_#2", "1"});
    childWSC2.setData(childPTM2);

    DebugSampler d2_1 = new DebugSampler();
    d2_1.setName("D2_#1");
    DebugSampler d2_2 = new DebugSampler();
    d2_2.setName("D2_#2");

    // main loop
    LoopController loop = new LoopController();
    loop.setLoops(6);
    loop.setContinueForever(false);

    // test tree
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, topWSC);
    hashTree.add(topWSC, listener);
    hashTree.add(topWSC, childWSC1);
    hashTree.add(childWSC1, d1_1);
    hashTree.add(childWSC1, d1_2);
    hashTree.add(childWSC1, listener);
    hashTree.add(topWSC, childWSC2);
    hashTree.add(childWSC2, d2_1);
    hashTree.add(childWSC2, d2_2);
    hashTree.add(childWSC2, listener);
    hashTree.add(topWSC, d1);
    hashTree.add(topWSC, d2);

    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(6, listener.events.size());
    List<String> labels = new ArrayList<>();
    labels.add("D_#1");
    labels.add("D_#2");
    labels.add("D1_#1");
    labels.add("D1_#2");
    labels.add("D2_#1");
    labels.add("D2_#2");
    for (SampleEvent event : listener.events) {
        assertTrue(labels.contains(event.getResult().getSampleLabel()));
    }
}
 
Example 10
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testNestedSimpleControllers() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());


    TestSampleListener listener = new TestSampleListener();

    // top WSC
    WeightedSwitchController topWSC = new WeightedSwitchController();
    PowerTableModel topPTM = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    topPTM.addRow(new String[]{"ex1", "10"});
    topPTM.addRow(new String[]{"ex2", "20"});
    topWSC.setData(topPTM);


    // first child: simple controller
    GenericController ex1 = new GenericController();
    ex1.setName("ex1");
    DebugSampler example1_1 = new DebugSampler();
    example1_1.setName("example1_1");
    DebugSampler example1_2 = new DebugSampler();
    example1_2.setName("example1_2");

    // second child: simple controller
    GenericController ex2 = new GenericController();
    ex2.setName("ex2");
    DebugSampler example2_1 = new DebugSampler();
    example2_1.setName("example2_1");
    DebugSampler example2_2 = new DebugSampler();
    example2_2.setName("example2_2");

    // main loop
    LoopController loop = new LoopController();
    loop.setLoops(60);
    loop.setContinueForever(false);

    // test tree
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, topWSC);
    hashTree.add(topWSC, listener);
    hashTree.add(topWSC, ex1);
    hashTree.add(ex1, example1_1);
    hashTree.add(ex1, example1_2);
    hashTree.add(ex1, listener);
    hashTree.add(topWSC, ex2);
    hashTree.add(ex2, example2_1);
    hashTree.add(ex2, example2_2);
    hashTree.add(ex2, listener);

    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();

    Map<String, Integer> totalResults = new HashMap<>();
    for (SampleEvent event : listener.events) {
        String label = event.getResult().getSampleLabel();
        if (totalResults.containsKey(label)) {
            totalResults.put(label, totalResults.get(label) + 1);
        } else {
            totalResults.put(label, 1);
        }
    }

    assertEquals(120, listener.events.size());
    assertEquals(20, (int) totalResults.get("example1_1"));
    assertEquals(20, (int) totalResults.get("example1_2"));
    assertEquals(40, (int) totalResults.get("example2_1"));
    assertEquals(40, (int) totalResults.get("example2_2"));
}
 
Example 11
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testNestedTransactionControllers() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());


    TestSampleListener listener = new TestSampleListener();

    // top WSC
    WeightedSwitchController topWSC = new WeightedSwitchController();
    PowerTableModel topPTM = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    topPTM.addRow(new String[]{"ex1", "10"});
    topPTM.addRow(new String[]{"ex2", "20"});
    topWSC.setData(topPTM);


    // first child: transaction controller
    TransactionController ex1 = new TransactionController();
    ex1.setName("ex1");
    DebugSampler example1_1 = new DebugSampler();
    example1_1.setName("example1_1");
    DebugSampler example1_2 = new DebugSampler();
    example1_2.setName("example1_2");

    // second child: transaction controller
    TransactionController ex2 = new TransactionController();
    ex2.setName("ex2");
    DebugSampler example2_1 = new DebugSampler();
    example2_1.setName("example2_1");
    DebugSampler example2_2 = new DebugSampler();
    example2_2.setName("example2_2");

    // main loop
    LoopController loop = new LoopController();
    loop.setLoops(3);
    loop.setContinueForever(false);

    // test tree
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, topWSC);
    hashTree.add(topWSC, listener);
    hashTree.add(topWSC, ex1);
    hashTree.add(ex1, example1_1);
    hashTree.add(ex1, example1_2);
    hashTree.add(ex1, listener);
    hashTree.add(topWSC, ex2);
    hashTree.add(ex2, example2_1);
    hashTree.add(ex2, example2_2);
    hashTree.add(ex2, listener);

    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();

    Map<String, Integer> totalResults = new HashMap<>();
    for (SampleEvent event : listener.events) {
        String label = event.getResult().getSampleLabel();
        if (totalResults.containsKey(label)) {
            totalResults.put(label, totalResults.get(label) + 1);
        } else {
            totalResults.put(label, 1);
        }
    }

    assertEquals(9, listener.events.size());
    assertEquals(1, (int) totalResults.get("example1_1"));
    assertEquals(1, (int) totalResults.get("example1_2"));
    assertEquals(2, (int) totalResults.get("example2_1"));
    assertEquals(2, (int) totalResults.get("example2_2"));
    assertEquals(1, (int) totalResults.get("ex1")); // transaction result
    assertEquals(2, (int) totalResults.get("ex2")); // transaction result
}
 
Example 12
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testResetTransactionControllerUnderSimpleController() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());


    TestSampleListener listener = new TestSampleListener();

    // top WSC
    WeightedSwitchController topWSC = new WeightedSwitchController();
    PowerTableModel topPTM = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
    topPTM.addRow(new String[]{"simple1", "100"});
    topPTM.addRow(new String[]{"simple2", "100"});
    topWSC.setData(topPTM);

    GenericController simple1 = new GenericController();
    simple1.setName("simple1");

    GenericController simple2 = new GenericController();
    simple2.setName("simple2");

    // first child: transaction controller
    TransactionController ex1 = new TransactionController();
    ex1.setName("ex1");
    DebugSampler example1_1 = new DebugSampler();
    example1_1.setName("example1_1");
    DebugSampler example1_2 = new DebugSampler();
    example1_2.setName("example1_2");

    // second child: transaction controller
    TransactionController ex2 = new TransactionController();
    ex2.setName("ex2");
    DebugSampler example2_1 = new DebugSampler();
    example2_1.setName("example2_1");
    DebugSampler example2_2 = new DebugSampler();
    example2_2.setName("example2_2");

    // main loop
    LoopController loop = new LoopController();
    loop.setLoops(4);
    loop.setContinueForever(false);

    // test tree
    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(loop);
    hashTree.add(loop, topWSC);
    hashTree.add(topWSC, listener);
    hashTree.add(topWSC, simple1);
    hashTree.add(simple1, ex1);
    hashTree.add(ex1, example1_1);
    hashTree.add(ex1, example1_2);
    hashTree.add(ex1, listener);
    hashTree.add(topWSC, simple2);
    hashTree.add(simple2, ex2);
    hashTree.add(ex2, example2_1);
    hashTree.add(ex2, example2_2);
    hashTree.add(ex2, listener);

    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();

    Map<String, Integer> totalResults = new HashMap<>();
    for (SampleEvent event : listener.events) {
        String label = event.getResult().getSampleLabel();
        if (totalResults.containsKey(label)) {
            totalResults.put(label, totalResults.get(label) + 1);
        } else {
            totalResults.put(label, 1);
        }
    }

    assertEquals(12, listener.events.size());
    assertEquals(2, (int) totalResults.get("example1_1"));
    assertEquals(2, (int) totalResults.get("example1_2"));
    assertEquals(2, (int) totalResults.get("example2_1"));
    assertEquals(2, (int) totalResults.get("example2_2"));
    assertEquals(2, (int) totalResults.get("ex1")); // transaction result
    assertEquals(2, (int) totalResults.get("ex2")); // transaction result
}
 
Example 13
Source File: ConcurrencyThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
@Test
public void testStartNextLoop() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());

    TestSampleListener listener = new TestSampleListener();

    DebugSampler beforeSampler = new DebugSamplerExt();
    beforeSampler.setName("Before Test Action sampler");

    TestAction testAction = new TestAction();
    testAction.setAction(TestAction.RESTART_NEXT_LOOP);

    DebugSampler afterSampler = new DebugSamplerExt();
    afterSampler.setName("After Test Action sampler");


    ConcurrencyThreadGroup ctg = new ConcurrencyThreadGroup();
    ctg.setProperty(new StringProperty(AbstractThreadGroup.ON_SAMPLE_ERROR, AbstractThreadGroup.ON_SAMPLE_ERROR_CONTINUE));
    ctg.setRampUp("0");
    ctg.setTargetLevel("1");
    ctg.setSteps("0");
    ctg.setHold("5"); // TODO: increase this value for debugging
    ctg.setIterationsLimit("10");
    ctg.setUnit("S");

    ListedHashTree hashTree = new ListedHashTree();
    hashTree.add(ctg);
    hashTree.add(ctg, beforeSampler);
    hashTree.add(ctg, testAction);
    hashTree.add(ctg, afterSampler);
    hashTree.add(ctg, listener);

    TestCompiler compiler = new TestCompiler(hashTree);
    hashTree.traverse(compiler);

    ListenerNotifier notifier = new ListenerNotifier();

    ctg.start(1, notifier, hashTree, new StandardJMeterEngine());

    ctg.waitThreadsStopped();

    for (SampleEvent event : listener.events) {
        assertEquals("Before Test Action sampler", event.getResult().getSampleLabel());
    }
}
 
Example 14
Source File: ConcurrencyThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
private Object[] createTestPlan() {
    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");
    ctg.setHold("10"); // TODO: increase this value for debugging
    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);

    return new Object[] {
            hashTree,
            ctg
    };
}