imIn = new CountDownLatch(0);
dispatcher.latch = new CountDownLatch(10 * NTHREADS);
SendMessageThread.latch = new CountDownLatch(NTHREADS * 4);
for (int i = 0; i < (NTHREADS * 4); i++)
sendMessage(container, new MockInputMessage("key" + i),false);
assertTrue("Timeout on initial messages", finishLatch.await(4, TimeUnit.SECONDS));
Thread.yield(); // cover any deltas between mp decrementing latch and returning
assertTrue("Timeout waiting on message to be sent",SendMessageThread.latch.await(2, TimeUnit.SECONDS));
checkStat(stats);
assertEquals(NTHREADS * 4, stats.getProcessedMessageCount());
startLatch = new CountDownLatch(1);
finishLatch = new CountDownLatch(6 * NTHREADS); // (4 output + 2 msg) * nthreads
// Generate an output message but force a failure.
forceOutputException = true;
container.outputPass(); // this should be ok inline.
forceOutputException = false;
assertEquals(0, stats.getDiscardedMessageCount()); // no discarded messages
assertEquals(NTHREADS * 4, stats.getMessageFailedCount()); // all output messages should have failed.
// run it again without the null pointer exception
finishOutputLatch = new CountDownLatch(NTHREADS * 4);
container.outputPass(); // this should be ok inline.
assertEquals(0, stats.getDiscardedMessageCount()); // no discarded messages
assertEquals(NTHREADS * 4, stats.getMessageFailedCount()); // all output messages should have failed.
assertEquals(2 * (NTHREADS * 4), stats.getProcessedMessageCount());
checkStat(stats);
imIn = new CountDownLatch(2 * NTHREADS);
finishLatch = new CountDownLatch(2 * NTHREADS);
SendMessageThread.latch = new CountDownLatch(NTHREADS * 2);
// put 2 * nthreads messages on the queue, expect no discards
for (int i = 0; i < (2 * NTHREADS); i++)
{
sendMessage(container, new MockInputMessage("key" + i),false);
assertEquals(0, stats.getDiscardedMessageCount());
}
assertTrue("Timeout on initial messages", imIn.await(4, TimeUnit.SECONDS));
assertEquals(0, stats.getDiscardedMessageCount());