The reason for the hang is because Spring unit test transaction is separate to 
the camel transaction. The camel transaction is blocked waiting because the 
spring has uncommitted changes to the same table it is trying to read from. 

Either
1. commit the spring transaction first, drop the @Transactional and use a 
TransactionTemplate to do this OR
2. Somehow get the spring and camel to participate in the same transaction 
during the unit test. If they share the same transaction manager and camel 
transaction is set to PROPAGATION_REQUIRED which is the default, this should 
just work. This assumes your unit test and camel execution is running under the 
same thread though. If not then stick to the first method.

On 22 Sep 2014, at 11:51 pm, James Green <james.mk.gr...@gmail.com> wrote:

> We have a Spring project that has a unit test annotated @Transactional.
> This uses a DAO to save a sample Entity before invoking a Camel route that
> accepts a JMS message and sends it to some Processors.
> 
> The problem we have is when the test itself is annotated @Transactional.
> The route stops having received the message and begin performing a database
> query - it literally hangs performing the SELECT. Naturally after 20s the
> time-out is hit.
> 
> If we remove @Transactional from the test the route continues but finds
> nothing in the database as the initial Entity save had no effect (it
> appears).
> 
> So we're clearly missing something here - how should we seed test data if
> @Transactional hangs and without it the data is not committed?
> 
> Thanks,
> 
> James

Reply via email to