Search in sources :

Example 16 with SampleSaveConfiguration

use of org.apache.jmeter.samplers.SampleSaveConfiguration in project xwiki-platform by xwiki.

the class HTTPPerformanceTest method execute.

public void execute(List<HTTPSampler> samplers, String user, String password) {
    // jmeter.properties
    JMeterUtils.loadJMeterProperties("target/jmeter/home/bin/saveservice.properties");
    JMeterUtils.setLocale(Locale.ENGLISH);
    JMeterUtils.setJMeterHome("target/jmeter/home");
    // Result collector
    ResultCollector resultCollector = new ResultCollector();
    resultCollector.setFilename("target/jmeter/report.jtl");
    SampleSaveConfiguration saveConfiguration = new SampleSaveConfiguration();
    saveConfiguration.setAsXml(true);
    saveConfiguration.setCode(true);
    saveConfiguration.setLatency(true);
    saveConfiguration.setTime(true);
    saveConfiguration.setTimestamp(true);
    resultCollector.setSaveConfig(saveConfiguration);
    // Thread Group
    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setName("xwiki");
    threadGroup.setNumThreads(1);
    threadGroup.setRampUp(1);
    LoopController loopCtrl = new LoopController();
    loopCtrl.setLoops(5);
    loopCtrl.setFirst(true);
    threadGroup.setSamplerController(loopCtrl);
    HashTree threadGroupTree = new HashTree();
    threadGroupTree.add(samplers);
    // Test plan
    TestPlan testPlan = new TestPlan("ping");
    HashTree testPlanTree = new HashTree();
    testPlanTree.add(threadGroup, threadGroupTree);
    testPlanTree.add(resultCollector);
    HashTree hashTree = new HashTree();
    hashTree.add(testPlan, testPlanTree);
    // Engine
    StandardJMeterEngine jm = new StandardJMeterEngine("localhost");
    jm.configure(hashTree);
    jm.run();
}
Also used : SampleSaveConfiguration(org.apache.jmeter.samplers.SampleSaveConfiguration) HashTree(org.apache.jorphan.collections.HashTree) StandardJMeterEngine(org.apache.jmeter.engine.StandardJMeterEngine) TestPlan(org.apache.jmeter.testelement.TestPlan) ThreadGroup(org.apache.jmeter.threads.ThreadGroup) LoopController(org.apache.jmeter.control.LoopController) ResultCollector(org.apache.jmeter.reporters.ResultCollector)

Example 17 with SampleSaveConfiguration

use of org.apache.jmeter.samplers.SampleSaveConfiguration in project jmeter by apache.

the class ResultCollector method sampleOccurred.

/**
 * When a test result is received, display it and save it.
 *
 * @param event
 *            the sample event that was received
 */
@Override
public void sampleOccurred(SampleEvent event) {
    SampleResult result = event.getResult();
    if (isSampleWanted(result.isSuccessful())) {
        sendToVisualizer(result);
        if (out != null && !isResultMarked(result) && !this.isStats) {
            SampleSaveConfiguration config = getSaveConfig();
            result.setSaveConfig(config);
            try {
                if (config.saveAsXml()) {
                    SaveService.saveSampleResult(event, out);
                } else {
                    // !saveAsXml
                    CSVSaveService.saveSampleResult(event, out);
                }
            } catch (Exception err) {
                // should throw exception back to caller
                log.error("Error trying to record a sample", err);
            }
        }
    }
    if (summariser != null) {
        summariser.sampleOccurred(event);
    }
}
Also used : SampleSaveConfiguration(org.apache.jmeter.samplers.SampleSaveConfiguration) SampleResult(org.apache.jmeter.samplers.SampleResult) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 18 with SampleSaveConfiguration

use of org.apache.jmeter.samplers.SampleSaveConfiguration in project jmeter by apache.

the class CSVSaveService method saveSampleResult.

/**
 * @param event {@link SampleEvent}
 * @param out {@link PrintWriter} to which samples will be written
 */
public static void saveSampleResult(SampleEvent event, PrintWriter out) {
    SampleSaveConfiguration saveConfiguration = event.getResult().getSaveConfig();
    String delimiter = saveConfiguration.getDelimiter();
    String formattedResult = resultToDelimitedString(event, event.getResult(), saveConfiguration, delimiter);
    out.println(formattedResult);
    if (saveConfiguration.saveSubresults()) {
        SampleResult result = event.getResult();
        saveSubResults(event, out, saveConfiguration, delimiter, result, 0);
    }
}
Also used : SampleSaveConfiguration(org.apache.jmeter.samplers.SampleSaveConfiguration) StatisticalSampleResult(org.apache.jmeter.samplers.StatisticalSampleResult) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 19 with SampleSaveConfiguration

use of org.apache.jmeter.samplers.SampleSaveConfiguration in project jmeter by apache.

the class TestCSVSaveService method testSample.

@Test
public // if this test fails, check whether the default was intentionally changed or not
void testSample() throws MalformedURLException {
    final String RESULT = "1,2,3,4,5,6,7,true,,8,9,10,11,https://jmeter.apache.org,12,13,14";
    SampleResult result = new SampleResult();
    result.setSaveConfig(new SampleSaveConfiguration());
    result.setStampAndTime(1, 2);
    result.setSampleLabel("3");
    result.setResponseCode("4");
    result.setResponseMessage("5");
    result.setThreadName("6");
    result.setDataType("7");
    result.setSuccessful(true);
    result.setBytes(8L);
    result.setURL(new URL("https://jmeter.apache.org"));
    result.setSentBytes(9);
    result.setGroupThreads(10);
    result.setAllThreads(11);
    result.setLatency(12);
    result.setIdleTime(13);
    result.setConnectTime(14);
    assertEquals("Result text has changed", RESULT, CSVSaveService.resultToDelimitedString(new SampleEvent(result, "")));
}
Also used : SampleSaveConfiguration(org.apache.jmeter.samplers.SampleSaveConfiguration) SampleResult(org.apache.jmeter.samplers.SampleResult) URL(java.net.URL) SampleEvent(org.apache.jmeter.samplers.SampleEvent) Test(org.junit.jupiter.api.Test)

Aggregations

SampleSaveConfiguration (org.apache.jmeter.samplers.SampleSaveConfiguration)19 SampleResult (org.apache.jmeter.samplers.SampleResult)7 File (java.io.File)4 IOException (java.io.IOException)3 SampleEvent (org.apache.jmeter.samplers.SampleEvent)3 StatisticalSampleResult (org.apache.jmeter.samplers.StatisticalSampleResult)3 FileNotFoundException (java.io.FileNotFoundException)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 Date (java.util.Date)1 CorrectedResultCollector (kg.apc.jmeter.vizualizers.CorrectedResultCollector)1 AssertionResult (org.apache.jmeter.assertions.AssertionResult)1 LoopController (org.apache.jmeter.control.LoopController)1 StandardJMeterEngine (org.apache.jmeter.engine.StandardJMeterEngine)1 HTTPSampleResult (org.apache.jmeter.protocol.http.sampler.HTTPSampleResult)1