Search in sources :

Example 21 with DistributedTestException

use of org.apache.qpid.disttest.DistributedTestException in project qpid-broker-j by apache.

the class AbstractTestRunner method awaitTestResults.

private void awaitTestResults() {
    long timeout = _testResultTimeout;
    DistributedTestException lastException = null;
    boolean waitForever = _testResultTimeout == WAIT_FOREVER;
    final long interval = waitForever ? PARTICIPANT_RESULTS_LOG_INTERVAL : Math.min(PARTICIPANT_RESULTS_LOG_INTERVAL, _testResultTimeout);
    while (_testResultsLatch.getCount() > 0 && (waitForever || timeout > 0)) {
        try {
            awaitLatch(_testResultsLatch, interval, "still waiting for participant results");
        } catch (DistributedTestException e) {
            lastException = e;
            LOGGER.info(e.getMessage());
        }
        if (!waitForever) {
            timeout = -interval;
        }
    }
    if (_testResultsLatch.getCount() > 0) {
        throw lastException;
    }
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException)

Example 22 with DistributedTestException

use of org.apache.qpid.disttest.DistributedTestException 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)

Example 23 with DistributedTestException

use of org.apache.qpid.disttest.DistributedTestException in project qpid-broker-j by apache.

the class JmsMessageAdaptor method commandToMessage.

public static Message commandToMessage(final Session session, final Command command) {
    Message jmsMessage = null;
    try {
        jmsMessage = session.createMessage();
        jmsMessage.setStringProperty(DistributedTestConstants.MSG_COMMAND_PROPERTY, command.getType().name());
        final JsonHandler jsonHandler = new JsonHandler();
        jmsMessage.setStringProperty(DistributedTestConstants.MSG_JSON_PROPERTY, jsonHandler.marshall(command));
    } catch (final JMSException | IOException e) {
        throw new DistributedTestException("Unable to convert command " + command + " to JMS Message", e);
    }
    return jmsMessage;
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Message(javax.jms.Message) JsonHandler(org.apache.qpid.disttest.json.JsonHandler) JMSException(javax.jms.JMSException) IOException(java.io.IOException)

Example 24 with DistributedTestException

use of org.apache.qpid.disttest.DistributedTestException in project qpid-broker-j by apache.

the class ControllerTest method testControllerRejectsEmptyConfiguration.

@Test
public void testControllerRejectsEmptyConfiguration() {
    Config configWithZeroClients = createMockConfig(0);
    try {
        _controller.setConfig(configWithZeroClients);
        fail("Exception not thrown");
    } catch (DistributedTestException e) {
    // PASS
    }
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Config(org.apache.qpid.disttest.controller.config.Config) Test(org.junit.Test)

Example 25 with DistributedTestException

use of org.apache.qpid.disttest.DistributedTestException in project qpid-broker-j by apache.

the class OrdinaryTestRunnerTest method testClientRespondingWithErrorResponseStopsTest.

@Test
public void testClientRespondingWithErrorResponseStopsTest() {
    Response errorResponse = new Response(CLIENT1_REGISTERED_NAME, CommandType.CREATE_CONNECTION, "error occurred");
    configureMockToReturnResponseTo(CreateConnectionCommand.class, errorResponse, null);
    _testInstance = createTestInstanceWithConnection();
    _testRunner = new OrdinaryTestRunner(_participatingClients, _testInstance, _respondingJmsDelegate, COMMAND_RESPONSE_TIMEOUT, TEST_RESULT_TIMEOUT);
    try {
        _testRunner.run();
        fail("Exception not thrown");
    } catch (DistributedTestException e) {
        assertEquals("One or more clients were unable to successfully process commands. " + "1 command(s) generated an error response.", e.getMessage());
    }
}
Also used : Response(org.apache.qpid.disttest.message.Response) DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Test(org.junit.Test)

Aggregations

DistributedTestException (org.apache.qpid.disttest.DistributedTestException)25 JMSException (javax.jms.JMSException)18 Message (javax.jms.Message)7 MessageConsumer (javax.jms.MessageConsumer)5 Session (javax.jms.Session)5 IOException (java.io.IOException)4 TextMessage (javax.jms.TextMessage)4 Connection (javax.jms.Connection)3 Destination (javax.jms.Destination)3 MessageProducer (javax.jms.MessageProducer)3 Command (org.apache.qpid.disttest.message.Command)3 MessageListener (javax.jms.MessageListener)2 NamingException (javax.naming.NamingException)2 JsonHandler (org.apache.qpid.disttest.json.JsonHandler)2 CreateProducerCommand (org.apache.qpid.disttest.message.CreateProducerCommand)2 RegisterClientCommand (org.apache.qpid.disttest.message.RegisterClientCommand)2 Test (org.junit.Test)2 IntrospectionException (java.beans.IntrospectionException)1 File (java.io.File)1 FileReader (java.io.FileReader)1