public void testSendRollback() throws Exception {
  Message[] outbound=new Message[]{session.createTextMessage("First Message"),session.createTextMessage("Second Message")};
  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<>();
  LOG.info("About to consume message 1");
  Message message=consumer.receive(1000);
  messages.add(message);
  LOG.info("Received: " + message);
  LOG.info("About to consume message 2");
  message=consumer.receive(4000);
  messages.add(message);
  LOG.info("Received: " + message);
  commitTx();
  Message inbound[]=new Message[messages.size()];
  messages.toArray(inbound);
  assertTextMessagesEqual("Rollback did not work.",outbound,inbound);
}

public void testSendRollback ( ) throws Exception { Message [ ] outbound = new Message [ ] { session . createTextMessage ( "First Message" ) , session . createTextMessage ( "Second Message" ) } ; 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 < > ( ) ; LOG . info ( "About to consume message 1" ) ; Message message = consumer . receive ( 1000 ) ; messages . add ( message ) ; LOG . info ( "Received: " + message ) ; LOG . info ( "About to consume message 2" ) ; message = consumer . receive ( 4000 ) ; messages . add ( message ) ; LOG . info ( "Received: " + message ) ; commitTx ( ) ; Message inbound [ ] = new Message [ messages . size ( ) ] ; messages . toArray ( inbound ) ; assertTextMessagesEqual ( "Rollback did not work." , outbound , inbound ) ; }
sends a batch of messages and validates that the rollbacked message was not consumed .
