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();
}
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);
}
}
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);
}
}
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, "")));
}
Aggregations