}
public void testRedel3() throws Exception
{
Connection conn = null;
try
{
conn = cf.createConnection();
conn.start();
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer prod = sess.createProducer(queue);
TextMessage tm1 = sess.createTextMessage("hello1");
log.trace(tm1.getJMSMessageID());
TextMessage tm2 = sess.createTextMessage("hello2");
TextMessage tm3 = sess.createTextMessage("hello3");
prod.send(tm1);
prod.send(tm2);
prod.send(tm3);
sess.commit();
MessageConsumer cons1 = sess.createConsumer(queue);
TextMessage rm1 = (TextMessage)cons1.receive(1500);
assertNotNull(rm1);
assertEquals("hello1", rm1.getText());
log.trace(rm1.getJMSMessageID());
log.trace("rolling back");
//rollback should cause redelivery of messages not acked
sess.rollback();
log.trace("rolled back");
TextMessage rm2 = (TextMessage)cons1.receive(1500);
assertEquals("hello1", rm2.getText());
log.trace(rm1.getJMSMessageID());
TextMessage rm3 = (TextMessage)cons1.receive(1500);
assertEquals("hello2", rm3.getText());
TextMessage rm4 = (TextMessage)cons1.receive(1500);
assertEquals("hello3", rm4.getText());
//This last step is important - there shouldn't be any more messages to receive
TextMessage rm5 = (TextMessage)cons1.receive(1500);
assertNull(rm5);
}
finally
{
if (conn != null)
{
conn.close();
}
}
}