Now when I look at the logs, I notice that even though Camel reports the route has started, it doesn't actually consume from the topic until after this. This means that potentially the unit test could publish the message to the topic before the route had registered its own consumer to it.
Here's a snippet of the logs showing the consumer being created after the route has declared it has started.
2014-04-11 12:12:46,522 [main] INFO org.apache.camel.spring.SpringCamelContext - Route: route1 started and consuming from: Endpoint[activemq://topic:mytopic?lazyCreateTransactionManager=true&transacted=true]
2014-04-11 12:12:46,522 [main] INFO org.apache.camel.spring.SpringCamelContext - Total 1 routes, of which 1 is started.
2014-04-11 12:12:46,537 [main] DEBUG au.com.winning.camule.route.JmsTopicTest - unit test start
2014-04-11 12:12:46,982 [ActiveMQ VMTransport: vm://localhost#1-1] DEBUG org.apache.activemq.broker.region.AbstractRegion - localhost adding consumer: ID:imacporky.local-57940-1397182366748-3:2:1:1 for destination: topic://mytopic
Important thing to note is that the consumer is created AFTER the route has started and AFTER the unit test has already begun. This is the cause of the race condition. Is this expected behaviour of routes? Shouldn't the consumer be created before declaring the route has started? Btw, this problem only occurs with topics, queues won't see this problem.