Search in sources :

Example 21 with ParticipantResult

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;
}
Also used : ParticipantResult(org.apache.qpid.disttest.message.ParticipantResult) ParticipantAttribute(org.apache.qpid.disttest.message.ParticipantAttribute) ITestResult(org.apache.qpid.disttest.results.aggregation.ITestResult) TestResult(org.apache.qpid.disttest.controller.TestResult) ResultsForAllTests(org.apache.qpid.disttest.controller.ResultsForAllTests)

Example 22 with ParticipantResult

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;
}
Also used : ConsumerParticipantResult(org.apache.qpid.disttest.message.ConsumerParticipantResult) ParticipantResult(org.apache.qpid.disttest.message.ParticipantResult) ProducerParticipantResult(org.apache.qpid.disttest.message.ProducerParticipantResult) ConsumerParticipantResult(org.apache.qpid.disttest.message.ConsumerParticipantResult)

Example 23 with ParticipantResult

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());
}
Also used : ConsumerParticipantResult(org.apache.qpid.disttest.message.ConsumerParticipantResult) ParticipantResult(org.apache.qpid.disttest.message.ParticipantResult) ProducerParticipantResult(org.apache.qpid.disttest.message.ProducerParticipantResult) Test(org.junit.Test)

Example 24 with ParticipantResult

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));
}
Also used : ParticipantResult(org.apache.qpid.disttest.message.ParticipantResult) ITestResult(org.apache.qpid.disttest.results.aggregation.ITestResult) File(java.io.File) ResultsForAllTests(org.apache.qpid.disttest.controller.ResultsForAllTests) Test(org.junit.Test)

Example 25 with ParticipantResult

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);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Transformer(javax.xml.transform.Transformer) ITestResult(org.apache.qpid.disttest.results.aggregation.ITestResult) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) ParticipantResult(org.apache.qpid.disttest.message.ParticipantResult) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Aggregations

ParticipantResult (org.apache.qpid.disttest.message.ParticipantResult)38 Test (org.junit.Test)25 ConsumerParticipantResult (org.apache.qpid.disttest.message.ConsumerParticipantResult)9 ProducerParticipantResult (org.apache.qpid.disttest.message.ProducerParticipantResult)9 ITestResult (org.apache.qpid.disttest.results.aggregation.ITestResult)6 Date (java.util.Date)5 TestResult (org.apache.qpid.disttest.controller.TestResult)4 ResultsForAllTests (org.apache.qpid.disttest.controller.ResultsForAllTests)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Message (javax.jms.Message)2 ParticipantAttribute (org.apache.qpid.disttest.message.ParticipantAttribute)2 TreeSet (java.util.TreeSet)1 MessageListener (javax.jms.MessageListener)1 Context (javax.naming.Context)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Transformer (javax.xml.transform.Transformer)1 TransformerException (javax.xml.transform.TransformerException)1 DOMSource (javax.xml.transform.dom.DOMSource)1