org.apache.jmeter.save.SaveService Java Examples

The following examples show how to use org.apache.jmeter.save.SaveService. 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: 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 #2
Source File: MergeResultsService.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
private static void writeFileStart(PrintWriter writer,
        SampleSaveConfiguration saveConfig) {
    if (saveConfig.saveAsXml()) {
        writer.print(XML_HEADER);
        // Write the EOL separately so we generate LF line ends on Unix and
        // Windows
        writer.print("\n"); 
        String pi = saveConfig.getXmlPi();
        if (pi.length() > 0) {
            writer.println(pi);
        }
        writer.print(TESTRESULTS_START_V1_1_PREVER);
        writer.print(SaveService.getVERSION());
        writer.print(TESTRESULTS_START_V1_1_POSTVER);
        // Write the EOL separately so we generate LF line ends on Unix and
        // Windows
        writer.print("\n"); 
    } else if (saveConfig.saveFieldNames()) {
        writer.println(CSVSaveService
                .printableFieldNamesToString(saveConfig));
    }
}
 
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: 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 #5
Source File: TestUtilities.java    From jmeter-prometheus-plugin with Apache License 2.0 5 votes vote down vote up
public static void createJmeterEnv() {
  	
      JMeterUtils.setJMeterHome("src/test/resources");
      JMeterUtils.setLocale(Locale.ENGLISH);
      JMeterUtils.loadJMeterProperties("src/test/resources/bin/jmeter.properties");
      
      try {
	SaveService.loadProperties();
} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}

      JMeterTreeModel jMeterTreeModel = new JMeterTreeModel();
      JMeterTreeListener jMeterTreeListener = new JMeterTreeListener();
      jMeterTreeListener.setModel(jMeterTreeModel);
      
      JMeterContextService.getContext().setVariables(new JMeterVariables());
      StandardJMeterEngine engine = new StandardJMeterEngine();
      JMeterContextService.getContext().setEngine(engine);
      
      JMeterThreadMonitor monitor = new NOOPThreadMonitor();
      
      
      HashTree hashtree = new HashTree();
      hashtree.add(new LoopController());
      
      JMeterThread thread = new JMeterThread(hashtree, monitor, null);
      thread.setThreadName("test thread");
      JMeterContextService.getContext().setThread(thread);
      
      
      ThreadGroup tg1 = new ThreadGroup();
      tg1.setName("tg1");
      JMeterContextService.getContext().setThreadGroup(tg1);
      
  }
 
Example #6
Source File: TestProvider.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
public TestProvider() throws IllegalUserActionException, IOException {
    File file = new File(this.getClass().getResource("/com/blazemeter/jmeter/debugger/sample1.jmx").getFile());
    String basedir = TestJMeterUtils.fixWinPath(file.getParentFile().getAbsolutePath());

    File f = new File(basedir + "/sample1.jmx");
    mdl.addSubTree(SaveService.loadTree(f), (JMeterTreeNode) mdl.getRoot());
}
 
Example #7
Source File: TestProvider.java    From jmeter-debugger with Apache License 2.0 5 votes vote down vote up
public TestProvider(String path, String name) throws IllegalUserActionException, IOException {
    File file = new File(this.getClass().getResource(path).getFile());
    String basedir = TestJMeterUtils.fixWinPath(file.getParentFile().getAbsolutePath());

    File f = new File(basedir + '/' + name);
    mdl.addSubTree(SaveService.loadTree(f), (JMeterTreeNode) mdl.getRoot());
}
 
Example #8
Source File: BaseLNPTestCase.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Setup and load the JMeter configuration and property files to run the Jmeter test.
 * @throws IOException if the save service properties file cannot be loaded.
 */
private void setJmeterProperties() throws IOException {
    JMeterUtils.loadJMeterProperties(TestProperties.JMETER_PROPERTIES_PATH);
    JMeterUtils.setJMeterHome(TestProperties.JMETER_HOME);
    JMeterUtils.initLocale();
    SaveService.loadProperties();
}
 
Example #9
Source File: MergeResultsService.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private static PrintWriter getFileWriter(String filename,
        SampleSaveConfiguration saveConfig) throws IOException {
    if (filename == null || filename.length() == 0) {
        return null;
    }
    filename = FileServer.resolveBaseRelativeName(filename);
    FileEntry fe = files.get(filename);
    PrintWriter writer;

    if (fe == null) {
        // Find the name of the directory containing the file
        // and create it - if there is one
        File pdir = new File(filename).getParentFile();
        if (pdir != null) {
            // returns false if directory already exists, so need to check
            // again
            if (pdir.mkdirs()) {
                log.info("Folder " + pdir.getAbsolutePath()
                        + " was created");
            }
            // else if might have been created by another process so not a
            // problem
            if (!pdir.exists()) {
                log.warn("Error creating directories for "
                        + pdir.toString());
            }
        }
        writer = new PrintWriter(new OutputStreamWriter(
                new BufferedOutputStream(new FileOutputStream(filename)),
                SaveService.getFileEncoding("UTF-8")), SAVING_AUTOFLUSH); 
        log.debug("Opened file: " + filename);
        files.put(filename, new FileEntry(writer, saveConfig));
    } else {
        writer = fe.pw;
    }
    writeFileStart(writer, saveConfig);
    return writer;
}
 
Example #10
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 #11
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();
}