Ok, I solved the problem myself. BTW thanks jkysam for your comments.
The problem arose because loading the Context application more than once. Thus, when the applicationContext application loads, a new instance of kaha db is created, and this leads to blocking.
What I did was that I shared the jms configuration related to applicationContext. So, I created a new XML context file jmsContext.xml and moved the associated jms (and activemq) related configuration lines to this file. Then in my test classes I loaded different xml objects depending on whether it is jmsTest or not.
For instance; I have two GenericUnitTest classes to share context configuration. First:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"/jmsContext.xml"}) public abstract class GenericJmsUnitTest { }
Second:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"/applicationContext.xml"}) public abstract class GenericUnitTest { }
And then I extend these classes depending on the test case. Here is an example:
public class ProductQueueTest extends GenericJmsUnitTest{ @Autowired private ProductQueueService productQueueService; @Test public void productTest() { productQueueService.sendProduct(); } }
Sample non-jms test class:
public class SchedularTest extends GenericUnitTest { @Autowired private Processor schedulerProcessor; @Test public void scheduleForProduct() { schedulerProcessor.processForProducts(); } }
BTW, I exclude scanning filters for components that are queued in applicationContext.xml and include them in jmsContext.xml. Here is an example:
applicationContext xml below
<context:component-scan base-package="com.project"> <context:exclude-filter type="regex" expression="com.project.queue.*"/> <context:exclude-filter type="regex" expression="com.project.test.queue.*"/> </context:component-scan>
jmsContext xml is below
<context:component-scan base-package="com.project.queue"/> <context:component-scan base-package="com.project.test.queue"/>