TextMessage tm3 = sess.createTextMessage("hello3");
prod.send(tm1);
prod.send(tm2);
prod.send(tm3);
MessageConsumer cons1 = sess.createConsumer(queue);
TextMessage rm1 = (TextMessage)cons1.receive(1500);
assertNotNull(rm1);
assertEquals("hello1", rm1.getText());
cons1.close();
//Give time for asynch cancel to happen
Thread.sleep(500);
log.debug("sess.recover()");
//redeliver
sess.recover();
MessageConsumer cons2 = sess.createConsumer(queue);
log.debug("receiving ...");
TextMessage rm2 = (TextMessage)cons2.receive(1500);
assertNotNull(rm2);
assertEquals("hello1", rm2.getText());
TextMessage rm3 = (TextMessage)cons2.receive(1500);
assertNotNull(rm3);
assertEquals("hello2", rm3.getText());
TextMessage rm4 = (TextMessage)cons2.receive(1500);
assertNotNull(rm4);
assertEquals("hello3", rm4.getText());
//This last step is important - there shouldn't be any more messages to receive
TextMessage rm5 = (TextMessage)cons2.receive(1500);
assertNull(rm5);
}
finally