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);
}
}
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");
}
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);
}
}
}
}
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;
}
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;
}
Aggregations