final int NUM_MESSAGES = 20;
//Send some messages
for (int i = 0; i < NUM_MESSAGES; i++)
{
Message m = producerSess.createMessage();
producer.send(m);
}
assertRemainingMessages(NUM_MESSAGES);
log.trace("Sent messages");
int count = 0;
while (true)
{
Message m = consumer.receive(200);
if (m == null) break;
count++;
}
assertRemainingMessages(NUM_MESSAGES);
log.trace("Received " + count + " messages");
assertEquals(count, NUM_MESSAGES);
consumerSess.recover();
assertRemainingMessages(NUM_MESSAGES);
log.trace("Session recover called");
Message m = null;
int i = 0;
for(; i < NUM_MESSAGES; i++)
{
m = consumer.receive();
log.trace("Received message " + i);
}
assertRemainingMessages(NUM_MESSAGES);
// if I don't receive enough messages, the test will timeout
log.trace("Received " + i + " messages after recover");
m.acknowledge();
assertRemainingMessages(0);
// make sure I don't receive anything else