* Close the connection
* Create a new connection, session and consumer - verify messages are not redelivered
*/
public void testAckCommitQueue() throws Exception
{
Connection conn = null;
try
{
conn = cf.createConnection();
Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = producerSess.createProducer(queue);
Session consumerSess = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
MessageConsumer consumer = consumerSess.createConsumer(queue);
conn.start();
final int NUM_MESSAGES = 10;
//Send some messages
for (int i = 0; i < NUM_MESSAGES; i++)
{
Message m = producerSess.createMessage();
producer.send(m);
}
log.trace("Sent messages");
int count = 0;
while (true)
{
Message m = consumer.receive(500);
if (m == null) break;
count++;
}
log.trace("Received " + count + " messages");
assertEquals(NUM_MESSAGES, count);
consumerSess.commit();
log.trace("Committed session");
conn.stop();
consumer.close();
conn.close();
conn = cf.createConnection();
consumerSess = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
consumer = consumerSess.createConsumer(queue);
conn.start();
Message m = consumer.receive(2000);
log.trace("Message is " + m);
assertNull(m);
}
finally
{
if (conn != null)
{
conn.close();
}
}
}