Java Code Examples for org.apache.jmeter.save.SaveService#loadTree()

The following examples show how to use org.apache.jmeter.save.SaveService#loadTree() . 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: 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 2
Source File: PrometheusListenerTest.java    From jmeter-prometheus-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void canReadJMX() throws IOException {
	File jmx = new File("target/test-classes/simple_prometheus_example.jmx");
	HashTree tree = SaveService.loadTree(jmx);

	Assert.assertNotNull(tree);
}
 
Example 3
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 4
Source File: JMeterRecorder.java    From jsflight with Apache License 2.0 4 votes vote down vote up
public void reset() throws IOException
{
    mainHashTreeTemplate = SaveService.loadTree(new File(pathToTemplate));

    splitScenario();
}