@SuppressWarnings("unchecked") protected List<String> assertReceivedObjectMessageWithListBody(Message message) throws JMSException { assertNotNull("Should have received a message!", message); assertEquals("foo header", "abc", message.getStringProperty("foo")); assertTrue("Should be an object message but was: " + message, message instanceof ObjectMessage); ObjectMessage objectMessage = (ObjectMessage)message; List<String> body = (List<String>)objectMessage.getObject(); LOG.info("Received body: " + body); assertEquals("Size of list should be 1", 1, body.size()); assertEquals("element 0 of list", "First", body.get(0)); return body; }
/** * Sends a batch of messages and validates that the rollbacked message was * not consumed. * * @throws Exception */ public void testSendReceiveWithPrefetchOne() throws Exception { setPrefetchToOne(); Message[] outbound = new Message[] {session.createTextMessage("First Message"), session.createTextMessage("Second Message"), session.createTextMessage("Third Message"), session.createTextMessage("Fourth Message")}; beginTx(); for (int i = 0; i < outbound.length; i++) { // sends a message producer.send(outbound[i]); } commitTx(); // receives the first message beginTx(); for (int i = 0; i < outbound.length; i++) { LOG.info("About to consume message 1"); Message message = consumer.receive(1000); assertNotNull(message); LOG.info("Received: " + message); } // validates that the rollbacked was not consumed commitTx(); }
/** * Sends a batch of messages and validates that the messages are received. * * @throws Exception */ public void testSendReceiveTransactedBatches() throws Exception { TextMessage message = session.createTextMessage("Batch Message"); for (int j = 0; j < batchCount; j++) { LOG.info("Producing bacth " + j + " of " + batchSize + " messages"); beginTx(); for (int i = 0; i < batchSize; i++) { producer.send(message); } messageSent(); commitTx(); LOG.info("Consuming bacth " + j + " of " + batchSize + " messages"); beginTx(); for (int i = 0; i < batchSize; i++) { message = (TextMessage)consumer.receive(1000 * 5); assertNotNull("Received only " + i + " messages in batch " + j, message); assertEquals("Batch Message", message.getText()); } commitTx(); } }
assertNotNull(message); assertEquals(outbound[1], message); rollbackTx(); assertNotNull("Should have re-received the message again!", message); messages.add(message); commitTx();
assertNotNull(message); assertEquals(outbound[1], message); rollbackTx(); assertNotNull("Should have re-received the first message again!", message); messages.add(message); assertEquals(outbound[0], message); message = consumer.receive(5000); assertNotNull("Should have re-received the second message again!", message); messages.add(message); assertEquals(outbound[1], message);