I am running an integration test using Arquillian in an EAR file that uses CDI and JMS where I am dependent on the results of JMS eventing for the integration tests. I found that I cannot control when the JMS eventing occurs. Sometimes, JMS eventing occurs before a particular test starts which is the result I want. But sometimes I find the JMS eventing occurs after the test. Is there any way to tell JMS that it should begin at a particular time or to complete by a particular time? Is there any way to ask JMS whether a particular event has occurred or not? Is there any way to tell a test in Arquillian to wait for JMS to complete before starting?
The way I solved the issue was to add the following call after sending my JMS event:
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
With the above code, the JMS eventing is able to complete before the start of the next test. This works consistently.