Search in sources :

Example 1 with DistributedTestException

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

the class ControllerJmsDelegate method start.

public void start() {
    try {
        createControllerQueue();
        final MessageConsumer consumer = _controllerQueueListenerSession.createConsumer(_controllerQueue);
        consumer.setMessageListener(new MessageListener() {

            @Override
            public void onMessage(final Message message) {
                try {
                    String jmsMessageID = message.getJMSMessageID();
                    LOGGER.debug("Received message ID {}", jmsMessageID);
                    final Command command = JmsMessageAdaptor.messageToCommand(message);
                    LOGGER.debug("Converted message ID {} into command {}", jmsMessageID, command);
                    processCommandWithFirstSupportingListener(command);
                    LOGGER.debug("Finished processing command for message ID", jmsMessageID);
                } catch (Exception t) {
                    LOGGER.error("Can't handle JMS message", t);
                }
            }
        });
    } catch (final JMSException e) {
        throw new DistributedTestException(e);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Message(javax.jms.Message) Command(org.apache.qpid.disttest.message.Command) RegisterClientCommand(org.apache.qpid.disttest.message.RegisterClientCommand) MessageListener(javax.jms.MessageListener) JMSException(javax.jms.JMSException) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) DistributedTestException(org.apache.qpid.disttest.DistributedTestException)

Example 2 with DistributedTestException

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

the class ControllerJmsDelegate method closeConnections.

/**
 * ensures connections are closed, otherwise the JVM may be prevented from terminating
 */
public void closeConnections() {
    if (_commandSession != null) {
        try {
            _commandSession.close();
        } catch (JMSException e) {
            LOGGER.error("Unable to close command session", e);
        }
    }
    try {
        _controllerQueueListenerSession.close();
    } catch (JMSException e) {
        LOGGER.error("Unable to close controller queue listener session", e);
    }
    LOGGER.debug("Closed sessions");
    try {
        _connection.stop();
    } catch (JMSException e) {
        LOGGER.error("Unable to stop connection", e);
    }
    LOGGER.debug("Stopped connection");
    try {
        _connection.close();
    } catch (JMSException e) {
        throw new DistributedTestException("Unable to close connection", e);
    }
    LOGGER.debug("Closed connection");
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) JMSException(javax.jms.JMSException)

Example 3 with DistributedTestException

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

the class ControllerJmsDelegate method sendCommandToClient.

public void sendCommandToClient(final String clientName, final Command command) {
    final Destination clientQueue = _clientNameToQueueMap.get(clientName);
    if (clientQueue == null) {
        throw new DistributedTestException("Client name " + clientName + " not known. I know about: " + _clientNameToQueueMap.keySet());
    }
    MessageProducer producer = null;
    try {
        producer = _commandSession.createProducer(clientQueue);
        Message message = JmsMessageAdaptor.commandToMessage(_commandSession, command);
        producer.send(message);
    } catch (final JMSException e) {
        throw new DistributedTestException(e);
    } finally {
        if (producer != null) {
            try {
                producer.close();
            } catch (final JMSException e) {
                throw new DistributedTestException(e);
            }
        }
    }
}
Also used : Destination(javax.jms.Destination) DistributedTestException(org.apache.qpid.disttest.DistributedTestException) Message(javax.jms.Message) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer)

Example 4 with DistributedTestException

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

the class JmsMessageAdaptor method messageToCommand.

public static Command messageToCommand(final Message jmsMessage) {
    Command command = null;
    try {
        final CommandType commandType = CommandType.valueOf(jmsMessage.getStringProperty(DistributedTestConstants.MSG_COMMAND_PROPERTY));
        final JsonHandler jsonHandler = new JsonHandler();
        command = jsonHandler.unmarshall(jmsMessage.getStringProperty(DistributedTestConstants.MSG_JSON_PROPERTY), getCommandClassFromType(commandType));
    } catch (final JMSException | IOException e) {
        throw new DistributedTestException("Unable to convert JMS message " + jmsMessage + " to command object", e);
    }
    return command;
}
Also used : DistributedTestException(org.apache.qpid.disttest.DistributedTestException) JsonHandler(org.apache.qpid.disttest.json.JsonHandler) JMSException(javax.jms.JMSException) IOException(java.io.IOException)

Example 5 with DistributedTestException

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

the class JavaScriptConfigEvaluator method evaluateJavaScript.

public String evaluateJavaScript(Reader fileReader) {
    ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine engine = mgr.getEngineByName("JavaScript");
    try (Reader json2Reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("json2.js"));
        Reader testUtilsReader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("test-utils.js"))) {
        engine.eval(json2Reader);
        engine.eval(testUtilsReader);
        engine.eval(fileReader);
        engine.eval("jsonString = JSON.stringify(" + TEST_CONFIG_VARIABLE_NAME + ")");
    } catch (IOException | ScriptException e) {
        throw new DistributedTestException("Exception while evaluating test config", e);
    }
    String result = (String) engine.get("jsonString");
    return result;
}
Also used : ScriptException(javax.script.ScriptException) DistributedTestException(org.apache.qpid.disttest.DistributedTestException) InputStreamReader(java.io.InputStreamReader) ScriptEngineManager(javax.script.ScriptEngineManager) FileReader(java.io.FileReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) ScriptEngine(javax.script.ScriptEngine)

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