Purge the queue before performing the test in order to avoid consuming previously published events such as the ones coming from the acceptance tests.
Since the MessagePublisher publishes out the messages asynchronously, we were validating that the queue was empty even before publishing the message, so we were not really waiting for the message to be consumed before asserting that the consumed message was the expected one. Now we wait until the queue has messages before starting to consume.
The previous assertion was running in another thread and, since the default exception handler used by the RabbitMQ library is an implementation which catches the exceptions and traduce them into a log error (https://github.com/rabbitmq/rabbitmq-java-client/pull/74), the test was never failing (only logging errors). Now we inject from the test to the messages consumer a handler which extracts the event into a synchronized mutable.Buffer in order to perform the assertions proving that the consumed messages are the ones we're really expecting. Since that assertion is performed outside the consumer, the test will fail in case the expected messages doesn't match the consumed ones.
Extract RabbitMQ connection instantiation to RabbitMqChannelFactory in order to share the same connection between all the different services (RabbitMqMessagePublisher, RabbitMqMessageConsumer and RabbitMqMessagePurger)
⚠️ Dependent PR: #6, #7, #8, #9 & #10 ⚠️
RabbitMqMessagePublisherShould
test.MessagePublisher
publishes out the messages asynchronously, we were validating that the queue was empty even before publishing the message, so we were not really waiting for the message to be consumed before asserting that the consumed message was the expected one. Now we wait until the queue has messages before starting to consume.mutable.Buffer
in order to perform the assertions proving that the consumed messages are the ones we're really expecting. Since that assertion is performed outside the consumer, the test will fail in case the expected messages doesn't match the consumed ones.RabbitMqChannelFactory
in order to share the same connection between all the different services (RabbitMqMessagePublisher
,RabbitMqMessageConsumer
andRabbitMqMessagePurger
)