* A rollback will cause the first message to be re-delivered.
* A commit will cause the second message to be available for delivery.
*/
public void testRollbackCommit() throws Exception
{
QueueConnection conn = null;
try
{
conn = cf.createQueueConnection();
QueueSession sess = conn.createQueueSession(true, 0);
JBossMessageProducer producer = (JBossMessageProducer)sess.createProducer(queue1);
producer.enableOrderingGroup(null);
QueueReceiver cons = sess.createReceiver(queue1);
conn.start();
Message m1 = sess.createTextMessage("testing1");
Message m2 = sess.createTextMessage("testing2");
producer.send(m1);
producer.send(m2);
sess.commit();
TextMessage mr = (TextMessage)cons.receive(3000);
assertNotNull(mr);
assertEquals("testing1", mr.getText());
sess.rollback();
mr = (TextMessage)cons.receive(3000);
assertNotNull(mr);
assertEquals("testing1", mr.getText());
// second message cannot be received
// if the first message is not committed.
mr = (TextMessage)cons.receive(3000);
assertNull(mr);
sess.commit();
mr = (TextMessage)cons.receive(3000);
assertNotNull(mr);
assertEquals("testing2", mr.getText());
sess.commit();
checkEmpty(queue1);
}
finally
{
if (conn != null)
{
conn.close();
}
}
}