use of javax.jms.Message in project wildfly by wildfly.
the class SendMessagesTestCase method testShutdown.
@Test
public void testShutdown(@ArquillianResource @OperateOnDeployment("singleton") ManagementClient client) throws Exception {
Connection connection = null;
try {
deployer.deploy("mdb");
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
Queue queue = (Queue) ctx.lookup(QUEUE_SEND);
connection = cf.createConnection("guest", "guest");
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue replyQueue = session.createTemporaryQueue();
MessageProducer sender = session.createProducer(queue);
MessageConsumer receiver = session.createConsumer(replyQueue);
connection.start();
// we do not assume message order since the 1st message will be redelivered
// after redeployment (as the MDB is interrupted on 1st delivery)
Set<String> expected = new TreeSet<String>();
sendMessage(session, sender, replyQueue, "await");
expected.add("Reply: await");
// synchronize receiving message
int awaitInt = awaitSingleton("await before undeploy");
log.debug("testsuite: first awaitSingleton() returned: " + awaitInt);
Future<?> undeployed = executor.submit(undeployTask());
for (int i = 1; i <= 50; i++) {
String msg = this.getClass().getSimpleName() + " 50loop: " + i;
// should be bounced by BlockContainerShutdownInterceptor
sendMessage(session, sender, replyQueue, msg);
expected.add("Reply: " + msg);
}
log.debug("Sent 50 messages during MDB is undeploying");
// synchronize with transaction timeout
awaitInt = awaitSingleton("await after undeploy");
log.debug("testsuite: second awaitSingleton() returned: " + awaitInt);
undeployed.get(UNDEPLOYED_WAIT_S, SECONDS);
// deploying via management client, arquillian deployer does not work for some reason
final ModelNode deployAddr = new ModelNode();
deployAddr.get(ClientConstants.OP_ADDR).add("deployment", MESSAGE_DRIVEN_BEAN + ".jar");
deployAddr.get(ClientConstants.OP).set("deploy");
applyUpdate(deployAddr, managementClient.getControllerClient());
for (int i = 1; i <= 10; i++) {
String msg = this.getClass().getSimpleName() + "10loop: " + i;
sendMessage(session, sender, replyQueue, msg);
expected.add("Reply: " + msg);
}
log.debug("Sent 10 more messages");
Set<String> received = new TreeSet<String>();
for (int i = 1; i <= (1 + 50 + 10 + 1); i++) {
Message msg = receiver.receive(SECONDS.toMillis(RECEIVE_WAIT_S));
assertNotNull("did not receive message with ordered number " + i + " in " + SECONDS.toMillis(RECEIVE_WAIT_S) + " seconds", msg);
String text = ((TextMessage) msg).getText();
received.add(text);
log.trace(i + ": " + text);
}
assertNull(receiver.receiveNoWait());
assertEquals(expected, received);
} finally {
if (connection != null) {
connection.close();
}
deployer.undeploy("mdb");
}
}
use of javax.jms.Message in project wildfly by wildfly.
the class ObjectMessageTestCase method testObjectMessage.
/**
* Test that the MDB can process a {@link ObjectMessage} without any classloading issues
*
* @throws Exception
*/
@Test
public void testObjectMessage() throws Exception {
final String goodAfternoon = "Good afternoon!";
// create the message
final SimpleMessageInEarLibJar message = new SimpleMessageInEarLibJar(goodAfternoon);
// send as ObjectMessage
this.jmsUtil.sendObjectMessage(message, this.objectMessageQueue, this.objectMessageReplyQueue);
// wait for an reply
final Message reply = this.jmsUtil.receiveMessage(objectMessageReplyQueue, 5000);
// test the reply
Assert.assertNotNull("Reply message was null on reply queue: " + this.objectMessageReplyQueue, reply);
final SimpleMessageInEarLibJar replyMessage = (SimpleMessageInEarLibJar) ((ObjectMessage) reply).getObject();
Assert.assertEquals("Unexpected reply message on reply queue: " + this.objectMessageReplyQueue, message, replyMessage);
}
use of javax.jms.Message in project wildfly by wildfly.
the class ObjectMessageTestCase method testObjectMessageWithObjectArray.
/**
* Test that the MDB can process a {@link ObjectMessage} which consists of an array of objects,
* without any classloading issues
*
* @throws Exception
*/
@Test
public void testObjectMessageWithObjectArray() throws Exception {
final String goodMorning = "Good morning";
final String goodEvening = "Good evening";
// create the message
final SimpleMessageInEarLibJar[] multipleGreetings = new SimpleMessageInEarLibJar[2];
final SimpleMessageInEarLibJar messageOne = new SimpleMessageInEarLibJar(goodMorning);
final SimpleMessageInEarLibJar messageTwo = new SimpleMessageInEarLibJar(goodEvening);
multipleGreetings[0] = messageOne;
multipleGreetings[1] = messageTwo;
// send as ObjectMessage
this.jmsUtil.sendObjectMessage(multipleGreetings, this.objectMessageOfArrayTypeQueue, this.objectMessageOfArrayTypeReplyQueue);
// wait for an reply
final Message reply = this.jmsUtil.receiveMessage(objectMessageOfArrayTypeReplyQueue, 5000);
// test the reply
Assert.assertNotNull("Reply message was null on reply queue: " + this.objectMessageOfArrayTypeReplyQueue, reply);
final SimpleMessageInEarLibJar[] replyMessage = (SimpleMessageInEarLibJar[]) ((ObjectMessage) reply).getObject();
Assert.assertTrue("Unexpected reply message on reply queue: " + this.objectMessageOfArrayTypeReplyQueue, Arrays.equals(replyMessage, multipleGreetings));
}
use of javax.jms.Message in project wildfly by wildfly.
the class ConfiguredResourceAdapterNameTestCase method testMDBWithOverriddenResourceAdapterName.
@Test
public void testMDBWithOverriddenResourceAdapterName() throws Exception {
final String goodMorning = "Hello World";
// send as TextMessage
this.jmsUtil.sendTextMessage(goodMorning, this.queue, this.replyQueue);
// wait for an reply
final Message reply = this.jmsUtil.receiveMessage(replyQueue, 5000);
// test the reply
final TextMessage textMessage = (TextMessage) reply;
Assert.assertNotNull(textMessage);
Assert.assertEquals("Unexpected reply message on reply queue: " + this.replyQueue, ConfiguredResourceAdapterNameMDB.REPLY, textMessage.getText());
}
use of javax.jms.Message in project wildfly by wildfly.
the class SimpleTimerMDBTestCase method sendMessage.
//the timer is created when the
public void sendMessage() throws Exception {
final InitialContext ctx = new InitialContext();
final TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup("java:/JmsXA");
final TopicConnection connection = factory.createTopicConnection();
connection.start();
try {
final TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
final Message message = session.createTextMessage("Test");
final Destination destination = (Destination) ctx.lookup("topic/myAwesomeTopic");
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
producer.close();
} finally {
connection.close();
}
}
Aggregations