Search in sources :

Example 6 with DistributedTestException

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

the class ClientJmsDelegate method createConnection.

public void createConnection(final CreateConnectionCommand command) {
    try {
        final ConnectionFactory connectionFactory = (ConnectionFactory) _context.lookup(command.getConnectionFactoryName());
        final Connection newConnection = connectionFactory.createConnection();
        addConnection(command.getConnectionName(), newConnection);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Connection " + command.getConnectionName() + " is created " + metaDataToString(newConnection.getMetaData()));
        }
    } catch (final NamingException ne) {
        throw new DistributedTestException("Unable to lookup factoryName: " + command.getConnectionFactoryName(), ne);
    } catch (final JMSException jmse) {
        throw new DistributedTestException("Unable to create connection: " + command.getConnectionName() + " (using factory name: " + command.getConnectionFactoryName() + ")", jmse);
    }
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Connection(javax.jms.Connection) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException)

Example 7 with DistributedTestException

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

the class ClientJmsDelegate method tearDownTest.

public void tearDownTest() {
    StringBuilder jmsErrorMessages = new StringBuilder();
    int failureCounter = 0;
    for (String subscription : _testSubscriptions.keySet()) {
        Session session = _testSubscriptions.get(subscription);
        try {
            session.unsubscribe(subscription);
        } catch (JMSException e) {
            LOGGER.error("Failed to unsubscribe '" + subscription + "' :" + e.getLocalizedMessage(), e);
            failureCounter++;
            appendErrorMessage(jmsErrorMessages, e);
        }
    }
    for (Map.Entry<String, Connection> entry : _testConnections.entrySet()) {
        Connection connection = entry.getValue();
        try {
            connection.close();
        } catch (JMSException e) {
            LOGGER.error("Failed to close connection '" + entry.getKey() + "' :" + e.getLocalizedMessage(), e);
            failureCounter++;
            appendErrorMessage(jmsErrorMessages, e);
        }
    }
    _testConnections.clear();
    _testSubscriptions.clear();
    _testSessions.clear();
    _testProducers.clear();
    _testConsumers.clear();
    _testSessionToConnections.clear();
    if (failureCounter > 0) {
        throw new DistributedTestException("Tear down test encountered " + failureCounter + " failures with the following errors: " + jmsErrorMessages.toString());
    }
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Session(javax.jms.Session)

Example 8 with DistributedTestException

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

the class ResultsCsvWriter method writeResultsToOutputFile.

private void writeResultsToOutputFile(List<ITestResult> resultsForAllTests, String outputFile) {
    try (FileWriter writer = new FileWriter(outputFile)) {
        final String outputCsv = _csvFormater.format(resultsForAllTests);
        writer.write(outputCsv);
        LOGGER.info("Wrote {} test result(s) to output file {}", resultsForAllTests.size(), outputFile);
    } catch (IOException e) {
        throw new DistributedTestException("Unable to write output file " + outputFile, e);
    }
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) FileWriter(java.io.FileWriter) IOException(java.io.IOException)

Example 9 with DistributedTestException

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

the class TestInstance method createCommands.

public List<CommandForClient> createCommands() {
    List<CommandForClient> commands = _testConfig.createCommands();
    List<CommandForClient> newCommands = new ArrayList<CommandForClient>(commands.size());
    double ratePerProducer = calculateRatePerProducer(_producerRate, commands);
    for (CommandForClient commandForClient : commands) {
        String clientName = commandForClient.getClientName();
        Command command = commandForClient.getCommand();
        _iterationValue.applyToCommand(command);
        if (command instanceof CreateProducerCommand) {
            CreateProducerCommand producerCommand = (CreateProducerCommand) command;
            producerCommand.setRate(ratePerProducer);
        }
        if (command instanceof CreateParticipantCommand) {
            CreateParticipantCommand participantCommand = (CreateParticipantCommand) command;
            if ((participantCommand.getNumberOfMessages() <= 0 && participantCommand.getMaximumDuration() <= 0)) {
                throw new DistributedTestException("Test '" + getName() + "' must specify a positive integer value for numberOfMessages or maximumDuration");
            }
        }
        newCommands.add(new CommandForClient(clientName, command));
    }
    return newCommands;
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) CreateParticipantCommand(org.apache.qpid.disttest.message.CreateParticipantCommand) CreateProducerCommand(org.apache.qpid.disttest.message.CreateProducerCommand) Command(org.apache.qpid.disttest.message.Command) CreateProducerCommand(org.apache.qpid.disttest.message.CreateProducerCommand) ArrayList(java.util.ArrayList) CommandForClient(org.apache.qpid.disttest.controller.CommandForClient) CreateParticipantCommand(org.apache.qpid.disttest.message.CreateParticipantCommand)

Example 10 with DistributedTestException

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

the class ClientJmsDelegate method sendCommand.

private void sendCommand(final Command command) {
    try {
        final Message message = JmsMessageAdaptor.commandToMessage(_controllerSession, command);
        _controlQueueProducer.send(message);
        LOGGER.debug("Sent message for " + command.getType() + ". message id: " + message.getJMSMessageID());
    } catch (final JMSException jmse) {
        throw new DistributedTestException("Unable to send command: " + command, jmse);
    }
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JMSException(javax.jms.JMSException)

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