Question

I am writing a Junit tests for Amqp Message Listener.This is how the test is written.I send a message to a exchange and introduce a delay of 1s (assuming that the listener will do its job within that time frame).This approach slows down the build process as there 15-20 tests like these which take a minimum of 20 seconds to execute.Is there a way in which I can do this is a non blocking way.For pass a call handler which verifies the tests after the listener does it job.Something like Actors might be internally used

Was it helpful?

Solution

While not a 'non blocking' unit test, you can use Awaitility to create polling intervals, and a maximum wait time within JUnit. Very useful for tests which depend on async results.

You can set the polling time to something small, say 10 milis, and a maximum duration. Every 10 miliseconds your method to evaluate some condition will be fired. It will continue to be invoked until the condition returns true, or the maximum time allowable is hit. At that point it will throw an exception, failing the unit test.

http://code.google.com/p/awaitility/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top