beginTx(); producer.send(outbound[0]); commitTx(); beginTx(); producer.send(session.createTextMessage("I'm going to get rolled back.")); rollbackTx(); beginTx(); producer.send(outbound[1]); commitTx(); beginTx(); ArrayList<Message> messages = new ArrayList<Message>(); LOG.info("About to consume message 1");
/** * spec section 3.6 acking a message with automation acks has no effect. * @throws Exception */ public void testAckMessageInTx() throws Exception { Message[] outbound = new Message[] {session.createTextMessage("First Message")}; // sends a message beginTx(); producer.send(outbound[0]); outbound[0].acknowledge(); commitTx(); outbound[0].acknowledge(); // receives the first message beginTx(); ArrayList<Message> messages = new ArrayList<Message>(); LOG.info("About to consume message 1"); Message message = consumer.receive(1000); messages.add(message); LOG.info("Received: " + message); // validates that the rollbacked was not consumed commitTx(); Message inbound[] = new Message[messages.size()]; messages.toArray(inbound); assertTextMessagesEqual("Message not delivered.", outbound, inbound); }
/** * 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(); } }
beginTx(); while (consumer.receiveNoWait() != null) { beginTx(); producer.send(outbound[0]); producer.send(outbound[1]); LOG.info("Sent 1: " + outbound[1]); beginTx(); TextMessage message = (TextMessage)consumer.receive(1000); assertEquals(outbound[0].getText(), message.getText()); LOG.info("Created consumer: " + consumer); beginTx(); message = (TextMessage)consumer.receive(1000); assertEquals(outbound[1].getText(), message.getText());
beginTx(); while (consumer.receive(1000) != null) { beginTx(); producer.send(outbound[0]); producer.send(outbound[1]); beginTx(); Message message = consumer.receive(1000); messages.add(message); beginTx(); message = consumer.receive(1000); assertNotNull(message); beginTx(); message = consumer.receive(5000); assertNotNull("Should have re-received the message again!", message);
public void testChangeMutableObjectInObjectMessageThenRollback() throws Exception { ArrayList<String> list = new ArrayList<String>(); list.add("First"); Message outbound = session.createObjectMessage(list); outbound.setStringProperty("foo", "abc"); beginTx(); producer.send(outbound); commitTx(); LOG.info("About to consume message 1"); beginTx(); Message message = consumer.receive(5000); List<String> body = assertReceivedObjectMessageWithListBody(message); // now lets try mutate it try { message.setStringProperty("foo", "def"); fail("Cannot change properties of the object!"); } catch (JMSException e) { LOG.info("Caught expected exception: " + e, e); } body.clear(); body.add("This should never be seen!"); rollbackTx(); beginTx(); message = consumer.receive(5000); List<String> secondBody = assertReceivedObjectMessageWithListBody(message); assertNotSame("Second call should return a different body", secondBody, body); commitTx(); }
beginTx(); while (consumer.receive(1000) != null) { beginTx(); producer.send(outbound[0]); producer.send(outbound[1]); beginTx(); Message message = consumer.receive(1000); assertEquals(outbound[0], message); beginTx(); message = consumer.receive(5000); assertNotNull("Should have re-received the first message again!", message);