org.apache.jorphan.collections.HashTree Java Examples

The following examples show how to use org.apache.jorphan.collections.HashTree. 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: JMeterThreadParallelTest.java    From jmeter-bzm-plugins with Apache License 2.0 7 votes vote down vote up
@Test
public void testStopParentThread() {
    DummyThreadGroup monitor = new DummyThreadGroup();
    ListenerNotifier listenerNotifier = new ListenerNotifier();

    HashTree tree = new HashTree();
    LoopControllerExt loopControllerExt = new LoopControllerExt();
    tree.add(loopControllerExt);

    JMeterThreadExt parentThread = new JMeterThreadExt(tree, monitor, listenerNotifier);
    parentThread.setThreadGroup(monitor);
    JMeterContextService.getContext().setThread(parentThread);

    JMeterThreadParallel parallel = new JMeterThreadParallel(tree, monitor, listenerNotifier, true);
    parallel.setThreadGroup(monitor);
    loopControllerExt.thread = parallel;
    parallel.run();

    assertTrue(parentThread.isStopped);
}
 
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: UltimateThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testScheduleThreadAll() {
    System.out.println("scheduleThreadAll");
    HashTree hashtree = new HashTree();
    hashtree.add(new LoopController());

    CollectionProperty prop = JMeterPluginsUtils.tableModelRowsToCollectionProperty(dataModel, UltimateThreadGroup.DATA_PROPERTY);
    instance.setData(prop);
    instance.testStarted();

    for (int n = 0; n < instance.getNumThreads(); n++) {
        JMeterThread thread = new JMeterThread(hashtree, null, null);
        thread.setThreadNum(n);
        instance.scheduleThread(thread);
    }
}
 
Example #4
Source File: JMeterRecorder.java    From jsflight with Apache License 2.0 6 votes vote down vote up
public void saveScenario(OutputStream outStream, int recordingIndex) throws IOException
{
    LOG.info("Start {} scenario saving", recordingIndex);
    LOG.info("Cloning template tree");
    HashTree hashTree = (HashTree)mainHashTreeTemplate.clone();
    LOG.info("Searching for main nodes and trees");
    findMainNodesAndTrees(hashTree);

    RecordingController recordingController = recordingControllers.get(recordingIndex);
    HashTree recordingControllerSubTree = transactionControllerSubTree.add(recordingController);

    LOG.info("Extracting test elements");
    List<TestElement> samples = extractAppropriateTestElements(recordingController);

    LOG.info("Placing test elements");
    placeAndProcessTestElements(recordingControllerSubTree, samples);
    LOG.info("Saving into out stream");
    SaveService.saveTree(hashTree, outStream);
}
 
Example #5
Source File: UltimateThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testScheduleThread() {
    System.out.println("scheduleThread");
    HashTree hashtree = new HashTree();
    hashtree.add(new LoopController());
    JMeterThread thread = new JMeterThread(hashtree, null, null);

    CollectionProperty prop = JMeterPluginsUtils.tableModelRowsToCollectionProperty(dataModel, UltimateThreadGroup.DATA_PROPERTY);
    instance.setData(prop);
    instance.testStarted();

    instance.scheduleThread(thread);

    assertTrue(thread.getStartTime() > 0);
    assertTrue(thread.getEndTime() > thread.getStartTime());
}
 
Example #6
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 #7
Source File: DirectoryListingConfigTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testThreadStopping() throws Exception {
    DirectoryListingConfig config = new DirectoryListingConfig();

    File rootDir = TestDirectoryListingConfigActionTest.createFileTree();

    setDirectoryConfig(config, rootDir.getAbsolutePath(), VARIABLE_NAME, true, false, false, false, true, false);

    final HashTree hashTree = new HashTree();
    hashTree.add(new LoopController());

    JMeterThread thread = new JMeterThread(hashTree, null, null);
    JMeterContextService.getContext().setThread(thread);

    testFlow(config);

    try {
        config.iterationStart(null);
    } catch (JMeterStopThreadException ex) {
        assertEquals("All files in the directory have been passed.", ex.getMessage());
    }
}
 
Example #8
Source File: JMeterScriptProcessor.java    From jsflight with Apache License 2.0 6 votes vote down vote up
/**
 * Post process every stored request just before it get saved to disk
 *
 * @param sampler recorded http-request (sampler)
 * @param tree   HashTree (XML like data structure) that represents exact recorded sampler
 */
public void processScenario(HTTPSamplerBase sampler, HashTree tree, Arguments userVariables, JMeterRecorder recorder)
{
    Binding binding = new Binding();
    binding.setVariable(ScriptBindingConstants.LOGGER, LOG);
    binding.setVariable(ScriptBindingConstants.SAMPLER, sampler);
    binding.setVariable(ScriptBindingConstants.TREE, tree);
    binding.setVariable(ScriptBindingConstants.CONTEXT, recorder.getContext());
    binding.setVariable(ScriptBindingConstants.JSFLIGHT, JMeterJSFlightBridge.getInstance());
    binding.setVariable(ScriptBindingConstants.USER_VARIABLES, userVariables);
    binding.setVariable(ScriptBindingConstants.CLASSLOADER, classLoader);

    Script compiledProcessScript = ScriptEngine.getScript(getScenarioProcessorScript());
    if (compiledProcessScript == null)
    {
        return;
    }
    compiledProcessScript.setBinding(binding);
    LOG.info("Run compiled script");
    try {
        compiledProcessScript.run();
    } catch (Throwable throwable) {
        LOG.error(throwable.getMessage(), throwable);
    }
}
 
Example #9
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 #10
Source File: JMeterRecorder.java    From jsflight with Apache License 2.0 6 votes vote down vote up
private void placeAndProcessTestElements(HashTree hashTree, List<TestElement> samples)
{
    for (TestElement element : samples)
    {
        List<TestElement> descendants = findAndRemoveHeaderManagers(element);
        HashTree parent = hashTree.add(element);
        descendants.forEach(parent::add);

        if (element instanceof HTTPSamplerBase)
        {
            HTTPSamplerBase http = (HTTPSamplerBase)element;

            LOG.info("Start sampler processing");
            scriptProcessor.processScenario(http, parent, vars, this);
            LOG.info("Stop sampler processing");
        }
    }
}
 
Example #11
Source File: ParallelSampler.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
private HashTree getTestTree(TestElement te) {
    // can't use GenericController because of infinite looping
    CustomLoopController wrapper = new CustomLoopController(JMeterContextService.getContext());
    wrapper.setLoops(1);
    wrapper.setContinueForever(false);

    wrapper.addTestElement(te);
    wrapper.setName("wrapped " + te.getName());
    wrapper.setRunningVersion(isRunningVersion());

    HashTree tree = new HashTree();
    HashTree subTree = getSubTree(te);
    if (subTree != null) {
        tree.add(wrapper, subTree);
    } else {
        tree.add(wrapper);
    }
    return tree;
}
 
Example #12
Source File: ParallelSampler.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
private HashTree getSubTree(TestElement te) {
    try {
        Field field = JMeterThread.class.getDeclaredField("testTree");
        field.setAccessible(true);
        JMeterThread parentThread = JMeterContextService.getContext().getThread();
        if (parentThread == null) {
            log.error("Current thread is null.");
            throw new NullPointerException();
        }
        HashTree testTree = (HashTree) field.get(parentThread);
        SearchByClass<?> searcher = new SearchByClass<>(te.getClass());
        testTree.traverse(searcher);
        return searcher.getSubTree(te);
    } catch (ReflectiveOperationException ex) {
        log.warn("Can not get sub tree for Test element " + te.getName(), ex);
        return null;
    }
}
 
Example #13
Source File: SteppingThreadGroupTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testScheduleThreadIntegerOverflow() {
    System.out.println("scheduleThreadIntegerOverflow");
    HashTree hashtree = new HashTree();
    hashtree.add(new LoopController());
    JMeterThread thread = new JMeterThread(hashtree, null, null);
    SteppingThreadGroup instance = new SteppingThreadGroup();
    int numThreads = 3;
    instance.setNumThreads(numThreads);
    int inUserCount = 1;
    instance.setInUserCount("" + inUserCount);
    instance.setInUserCountBurst("0");
    int inUserPeriod = 224985600;
    instance.setInUserPeriod("" + inUserPeriod);
    instance.setRampUp("0");
    instance.setThreadGroupDelay("0");
    int flightTime = 33;
    instance.setFlightTime("" + flightTime);

    thread.setThreadNum(0);
    instance.scheduleThread(thread);

    assertEquals(1000L * ((inUserCount + 1) * inUserPeriod + inUserCount * flightTime), thread.getEndTime() - thread.getStartTime());

}
 
Example #14
Source File: TestPlanCheckTool.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
private int doJob() {
    HashTree testTree;
    try {
        testTree = loadJMX(new File(jmx));
        log.info("JMX is fine");
    } catch (Exception e) {
        log.error("Failed to load JMX", e);
        return 1;
    }

    if (isStats) {
        showStats(testTree);
    }

    if (isDump) {
        dumpTree(testTree);
    }
    return 0;
}
 
Example #15
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 #16
Source File: CustomTreeClonerTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testFlow() throws Exception {
    final CookieManager manager = new CookieManager();
    final ThroughputController controller = new ThroughputController();

    CustomTreeCloner cloner = new CustomTreeCloner();
    HashTree tree = createTestTree(controller, manager);
    tree.traverse(cloner);

    ListedHashTree clonedTree = cloner.getClonedTree();
    ListedHashTree loop = (ListedHashTree) clonedTree.values().toArray()[0];

    Object actualController = loop.keySet().toArray()[0];
    assertTrue("This links should be to the same instance", controller == actualController);

    Object actualManager = loop.get(actualController).keySet().toArray()[0];
    assertTrue("Cookie manager should be changed to ThreadSafe instance", actualManager instanceof ThreadSafeCookieManager);
}
 
Example #17
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
@Test
public void runDebugEngine() throws Exception {
    TestProvider prov = new TestProvider();

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(88, hook.cnt);
}
 
Example #18
Source File: Debugger.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
public void start() {
    log.debug("Start debugging");
    frontend.started();

    HashTree hashTree = getSelectedTree();
    StandardJMeterEngine.register(new StateListener()); // oh, dear, they use static field then clean it...
    engine = new DebuggerEngine(JMeterContextService.getContext());
    engine.setStepper(this);
    JMeter.convertSubTree(hashTree);
    engine.configure(hashTree);
    try {
        engine.runTest();
    } catch (JMeterEngineException e) {
        log.error("Failed to pauseContinue debug", e);
        stop();
    }
}
 
Example #19
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void runRealEngine() throws Exception {
    TestTreeProvider prov = new TestProvider();

    HashTree hashTree = prov.getTestTree();
    JMeter.convertSubTree(hashTree);

    StandardJMeterEngine engine = new StandardJMeterEngine();
    engine.configure(hashTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
}
 
Example #20
Source File: Http2JMeter.java    From jsflight with Apache License 2.0 5 votes vote down vote up
public void addAuthHttpSample(HashTree txTree, String login)
{
    HTTPSampler sample = new HTTPSampler();
    sample.setProperty(TestElement.GUI_CLASS, "HttpTestSampleGui");
    sample.setDomain("${host}");
    sample.setProperty(HTTPSampler.PORT, "${port}");
    sample.setMethod("GET");
    sample.setPath("/sd/operator?processAs=" + login);
    sample.setFollowRedirects(true);
    sample.setName("Auth " + login);
    txTree.add(sample);
}
 
Example #21
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void runVariablesInControllers() throws Exception {
    TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/loops.jmx", "loops.jmx");

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    TestSampleListener listener = new TestSampleListener();
    testTree.add(testTree.getArray()[0], listener);

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(12, hook.cnt);

    assertEquals(3, listener.events.size());
}
 
Example #22
Source File: InstructorSessionResultLNPTest.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
private void addLoadPageController(HashTree threadGroup, Map<String, String> argumentsMap) {
    HashTree loadPageController = threadGroup.add(JMeterElements.genericController());

    loadPageController.add(JMeterElements.defaultSampler(argumentsMap));

    String getSessionPath = "webapi/session";
    loadPageController.add(JMeterElements.httpGetSampler(getSessionPath));

    String getQuestionsPath = "webapi/questions";
    loadPageController.add(JMeterElements.httpGetSampler(getQuestionsPath));
}
 
Example #23
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void runVariablesInAssertions() throws Exception {
    TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/debug.jmx", "debug.jmx");

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    TestSampleListener listener = new TestSampleListener();
    testTree.add(testTree.getArray()[0], listener);

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(4, hook.cnt);

    assertEquals(1, listener.events.size());
    SampleEvent event = listener.events.get(0);
    SampleResult result = event.getResult();
    AssertionResult[] assertionResults = result.getAssertionResults();
    assertEquals(1, assertionResults.length);

    AssertionResult assertionRes = assertionResults[0];
    assertNull(assertionRes.getFailureMessage());
}
 
Example #24
Source File: DebuggerDialog.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
private void selectThreadGroup(AbstractThreadGroup tg) {
    debugger.selectThreadGroup(tg);
    treeModel.clearTestPlan();
    HashTree origTree = debugger.getSelectedTree();
    TreeCloner cloner = new TreeCloner();
    origTree.traverse(cloner);
    HashTree selectedTree = cloner.getClonedTree();

    // Hack to resolve ModuleControllers from JMeter.java
    SearchClass<ReplaceableController> replaceableControllers = new SearchClass<>(ReplaceableController.class);
    selectedTree.traverse(replaceableControllers);
    Collection<ReplaceableController> replaceableControllersRes = replaceableControllers.getSearchResults();
    for (ReplaceableController replaceableController : replaceableControllersRes) {
        replaceableController.resolveReplacementSubTree((JMeterTreeNode) treeModel.getRoot());
    }

    JMeter.convertSubTree(selectedTree);
    try {
        treeModel.addSubTree(selectedTree, (JMeterTreeNode) treeModel.getRoot());
    } catch (IllegalUserActionException e) {
        throw new RuntimeException(e);
    }

    // select TG for visual convenience
    SearchByClass<DebuggingThreadGroup> tgs = new SearchByClass<>(DebuggingThreadGroup.class);
    selectedTree.traverse(tgs);
    for (DebuggingThreadGroup forSel : tgs.getSearchResults()) {
        Wrapper<AbstractThreadGroup> wtg = new ThreadGroupWrapper();
        wtg.setWrappedElement(forSel);
        selectTargetInTree(wtg);
    }
}
 
Example #25
Source File: TestPlanCheckTool.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private HashTree loadJMX(File file) throws Exception {
    HashTree tree = SaveService.loadTree(file);

    // unfortunately core JMeter code does not throw exception, we may only guess...
    if (tree == null) {
        throw new TestPlanBrokenException("There was problems loading test plan. Please investigate error messages above.");
    }

    JMeter.convertSubTree(tree); // Remove the disabled items

    JMeterEngine engine = new StandardJMeterEngine();
    engine.configure(tree);

    return tree;
}
 
Example #26
Source File: TestPlanCheckTool.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void addNode(Object o, HashTree hashTree) {
    if (o instanceof TestElement) {
        TestElement el = (TestElement) o;
        log.info(StringUtils.repeat(" ", indent) + "[" + el.getClass().getSimpleName() + "] " + el.getName());
    } else {
        log.info(StringUtils.repeat(" ", indent) + o);
    }
    indent++;
}
 
Example #27
Source File: TestPlanCheckTool.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void addNode(Object node, HashTree subTree) {
    if (node instanceof AbstractThreadGroup) {
        tGroups++;
    } else if (node instanceof Controller) {
        controllers++;
    } else if (node instanceof Sampler) {
        samplers++;
    } else if (node instanceof AbstractListenerElement) {
        listeners++;
    } else if (node instanceof PreProcessor) {
        preProc++;
    } else if (node instanceof PostProcessor) {
        postProc++;
    } else if (node instanceof Assertion) {
        assertions++;
    } else if (node instanceof Timer) {
        timers++;
    } else if (node instanceof ConfigElement) {
        configs++;
    } else if (node instanceof TestPlan) {
        log.debug("Ok, we got the root of test plan");
    } else if (node instanceof WorkBench) {
        log.debug("Ok, we got the root of test plan");
    } else {
        log.warn("Strange object in tree: " + node);
        others++;
    }
}
 
Example #28
Source File: TreeClonerTG.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Override
public final void addNode(Object node, HashTree subTree) {
    if (!ignoring && isIgnored(node)) {
        ignoring = true;
    }

    if (!ignoring) {
        node = addNodeToTree(node);
    }
    stack.addLast(node);
}
 
Example #29
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 #30
Source File: DebuggerEngineTest.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
@Test
public void runVariablesDebugEngine() throws Exception {
    TestProvider prov = new TestProvider("/com/blazemeter/jmeter/debugger/vars.jmx", "vars.jmx");

    Debugger sel = new Debugger(prov, new FrontendMock());
    AbstractThreadGroup tg = prov.getTG(0);
    sel.selectThreadGroup(tg);
    HashTree testTree = sel.getSelectedTree();

    TestSampleListener listener = new TestSampleListener();
    testTree.add(testTree.getArray()[0], listener);

    DebuggingThreadGroup tg2 = (DebuggingThreadGroup) getFirstTG(testTree);
    LoopController samplerController = (LoopController) tg2.getSamplerController();
    samplerController.setLoops(1);
    samplerController.setContinueForever(false);

    JMeter.convertSubTree(testTree);

    DebuggerEngine engine = new DebuggerEngine(JMeterContextService.getContext());
    StepTriggerCounter hook = new StepTriggerCounter();
    engine.setStepper(hook);
    engine.configure(testTree);
    engine.runTest();
    while (engine.isActive()) {
        Thread.sleep(1000);
    }
    assertEquals(8, hook.cnt);

    assertEquals(3, listener.events.size());
    for (SampleEvent event : listener.events) {
        SampleResult res = event.getResult();
        String label = res.getSampleLabel();
        assertTrue("Label: " + label + " must end with '123'", label.endsWith("123"));
        assertFalse("Variable ${VAR} must be changed to '123' value. label: " + label, label.contains("${VAR}"));
        assertTrue("label: '" + label + "' response: '" + res.getResponseMessage() +"'", res.isSuccessful());
    }
}