}
// wait long enough so the first batch times out.
TimeUnit.SECONDS.sleep(5);
final QueueViewMBean queueView = getProxyToQueueViewMBean();
assertEquals(200, queueView.getInFlightCount());
final AtomicInteger msgCount = new AtomicInteger();
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
try {
if (msgCount.incrementAndGet() == 100) {
LOG.debug("Acking message: {}", message);
message.acknowledge();
}
} catch (JMSException e) {
}
}
});
TimeUnit.SECONDS.sleep(5);
assertTrue("Inflight count should reach zero, currently: " + queueView.getInFlightCount(), Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return queueView.getInFlightCount() == 0;
}
}));
// Now we just ack each and see if our counters come out right in the end.
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
try {
LOG.debug("Acking message: {}", message);
message.acknowledge();
} catch (JMSException e) {
}
}
});
for (int i = 0; i < 200; i++) {
producer.send(session.createTextMessage());
}
assertTrue("Inflight count should reach zero, currently: " + queueView.getInFlightCount(), Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return queueView.getInFlightCount() == 0;
}
}));
LOG.info("Dequeued Count: {}", queueView.getDequeueCount());
LOG.info("Dispatch Count: {}", queueView.getDispatchCount());
LOG.info("Enqueue Count: {}", queueView.getEnqueueCount());
LOG.info("Expired Count: {}", queueView.getExpiredCount());
LOG.info("InFlight Count: {}", queueView.getInFlightCount());
}