use of org.apache.qpid.disttest.message.ParticipantResult in project qpid-broker-j by apache.
the class ResultsTestFixture method createResultsForAllTests.
public ResultsForAllTests createResultsForAllTests() {
ParticipantResult participantResult = mock(ParticipantResult.class);
Map<ParticipantAttribute, Object> participantAttributes = getParticipantAttributes();
when(participantResult.getAttributes()).thenReturn(participantAttributes);
when(participantResult.getParticipantName()).thenReturn(PARTICIPANT);
when(participantResult.getTestName()).thenReturn(TEST1);
when(participantResult.getIterationNumber()).thenReturn(0);
when(participantResult.getThroughput()).thenReturn(THROUGHPUT_VALUE);
TestResult testResult = new TestResult(TEST1);
testResult.addParticipantResult(participantResult);
ResultsForAllTests resultsForAllTests = new ResultsForAllTests();
resultsForAllTests.add(testResult);
return resultsForAllTests;
}
use of org.apache.qpid.disttest.message.ParticipantResult in project qpid-broker-j by apache.
the class ParticipantResultAggregator method getAggregatedResult.
public ParticipantResult getAggregatedResult() {
ParticipantResult aggregatedResult;
if (_targetClass == ConsumerParticipantResult.class) {
ConsumerParticipantResult consumerParticipantResult = new ConsumerParticipantResult(_aggregatedResultName);
consumerParticipantResult.setAverageLatency(_latencyStatistics.getAverage());
consumerParticipantResult.setMinLatency(_latencyStatistics.getMinimum());
consumerParticipantResult.setMaxLatency(_latencyStatistics.getMaximum());
consumerParticipantResult.setLatencyStandardDeviation(_latencyStatistics.getStandardDeviation());
aggregatedResult = consumerParticipantResult;
} else {
aggregatedResult = new ParticipantResult(_aggregatedResultName);
}
setRolledUpConstantAttributes(aggregatedResult);
setComputedVariableAttributes(aggregatedResult);
return aggregatedResult;
}
use of org.apache.qpid.disttest.message.ParticipantResult in project qpid-broker-j by apache.
the class ParticipantResultFactoryTest method testCreateForError.
@Test
public void testCreateForError() {
String errorMessage = "error";
ParticipantResult result = _participantResultFactory.createForError(PARTICIPANT_NAME, REGISTERED_CLIENT_NAME, errorMessage);
assertEquals(PARTICIPANT_NAME, result.getParticipantName());
assertEquals(REGISTERED_CLIENT_NAME, result.getRegisteredClientName());
}
use of org.apache.qpid.disttest.message.ParticipantResult in project qpid-broker-j by apache.
the class ResultsXmlWriterTest method testResultForOneTestWithError.
@Test
public void testResultForOneTestWithError() throws Exception {
ParticipantResult resultWithError = mock(ParticipantResult.class);
when(resultWithError.hasError()).thenReturn(true);
when(resultWithError.getErrorMessage()).thenReturn("something went wrong");
ITestResult test = mock(ITestResult.class);
when(test.getName()).thenReturn("mytest");
when(test.hasErrors()).thenReturn(true);
when(test.getParticipantResults()).thenReturn(Collections.singletonList(resultWithError));
ResultsForAllTests resultsForAllTests = mock(ResultsForAllTests.class);
when(resultsForAllTests.getTestResults()).thenReturn(Collections.singletonList(test));
String expectedXmlContent = String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n" + "<testsuite tests=\"1\">%n" + " <testcase classname=\"config.json\" name=\"mytest\">%n" + " <error message=\"something went wrong\"/>%n" + " </testcase>%n" + "</testsuite>%n");
_resultsFileWriter.writeResults(resultsForAllTests, "config.json");
File resultsFile = new File(_outputDir, "config.xml");
assertEquals(expectedXmlContent, Resources.toString(resultsFile.toURI().toURL(), StandardCharsets.UTF_8));
}
use of org.apache.qpid.disttest.message.ParticipantResult in project qpid-broker-j by apache.
the class ResultsXmlWriter method writeResultsToOutputFile.
private void writeResultsToOutputFile(final ResultsForAllTests resultsForAllTests, final String inputFile, final String outputFile) {
try {
DocumentBuilder docBuilder = _docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
doc.setXmlStandalone(true);
Element root = doc.createElement("testsuite");
root.setAttribute("tests", Integer.toString(resultsForAllTests.getTestResults().size()));
doc.appendChild(root);
for (ITestResult testResult : resultsForAllTests.getTestResults()) {
Element testcase = doc.createElement("testcase");
testcase.setAttribute("classname", inputFile);
testcase.setAttribute("name", testResult.getName());
long timeTaken = getTimeTaken(testResult);
if (timeTaken > 0) {
testcase.setAttribute("time", String.valueOf(timeTaken / 1000));
}
if (testResult.hasErrors()) {
for (ParticipantResult result : testResult.getParticipantResults()) {
if (result.hasError()) {
Element error = doc.createElement("error");
error.setAttribute("message", result.getErrorMessage());
testcase.appendChild(error);
}
}
}
root.appendChild(testcase);
}
Transformer transformer = _transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(outputFile));
transformer.transform(source, result);
} catch (ParserConfigurationException | TransformerException e) {
throw new DistributedTestException("Failed to create xml file : " + outputFile, e);
}
}
Aggregations