Java Code Examples for org.apache.jmeter.JMeter#convertSubTree()

The following examples show how to use org.apache.jmeter.JMeter#convertSubTree() . 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: 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 2
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 3
Source File: WeightedSwitchControllerTest.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoopControllerWithNestedDisableController() throws Exception {
    JMeterContextService.getContext().setVariables(new JMeterVariables());
    TestSampleListener listener = new TestSampleListener();

    URL resource = WeightedSwitchControllerTest.class.getResource("/disableController.jmx");
    File testPlan = new File(resource.getFile());

    HashTree hashTree = SaveService.loadTree(testPlan);

    hashTree.add(hashTree.getArray()[0], listener);
    JMeter.convertSubTree(hashTree);
    StandardJMeterEngine engine = new StandardJMeterEngine();
    engine.configure(hashTree);
    engine.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(100, listener.events.size());
    assertEquals(50, (int) totalResults.get("Debug 1"));
    assertEquals(50, (int) totalResults.get("Debug 3"));
    assertNull(totalResults.get("Debug 2"));
}
 
Example 4
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 5
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 6
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());
    }
}
 
Example 7
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 8
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 9
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;
}