public void testConcurrentConsumersWithReply() throws Exception {
// latch for the 5 exchanges we expect
final CountDownLatch latch = new CountDownLatch(5);
// setup a task executor to be able send the messages in parallel
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(5);
executor.afterPropertiesSet();
for (int i = 0; i < 5; i++) {
final int count = i;
executor.execute(new Runnable() {
public void run() {
// request body is InOut pattern and thus we expect a reply (JMSReply)
Object response = template.requestBody("activemq:a", "World #" + count);
assertEquals("Bye World #" + count, response);
latch.countDown();
}
});
}
long start = System.currentTimeMillis();
// wait for test completion, timeout after 30 sec to let other unit test run to not wait forever
latch.await(30000L, TimeUnit.MILLISECONDS);
assertEquals("Latch should be zero", 0, latch.getCount());
long delta = System.currentTimeMillis() - start;
assertTrue("Should be faster than 20000 millis, took " + delta + " millis", delta < 20000L);
executor.shutdown();
}