Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wiping out embedded activemq data during testing

I'm actively using ActiveMQ in my project. Although production use standalone ActiveMQ instance my tests require embedded ActiveMQ instance. After execution of particular test method ActiveMQ holds unprocessed messages in queues. I'd like to wipe out ActiveMQ instance after each test. I tried to use JMX to connect to local ActiveMQ instance and wipe out queues, but it's heavy-weight solution. Could anyone suggest me something more lightweight?

like image 359
Archer Avatar asked Nov 23 '13 22:11

Archer


2 Answers

just turn off broker persistence when you define the broker URL for your unit tests

vm://localhost?broker.persistent=false
like image 192
Ben ODay Avatar answered Sep 19 '22 23:09

Ben ODay


ActiveMQ has an option to delete all message on startup, if you use the XML way of configuring ActiveMQ broker, you can set it on the < activemq > tag,

<activemq:broker .... deleteAllMessagesOnStartup="true">

   ...
</activemq:broker>

Another approach could be to use unique data directories per unit test which is what we do when unit testing camel-jms component with embedded ActiveMQ broker. We have a helper class that setup ActiveMQ for us, depending on we needed persistent queues or not

https://git-wip-us.apache.org/repos/asf?p=camel.git;a=blob;f=components/camel-jms/src/test/java/org/apache/camel/component/jms/CamelJmsTestHelper.java;h=8c81f3e2bed738a75841988fd1239f54a100cd89;hb=HEAD

like image 29
Claus Ibsen Avatar answered Sep 19 '22 23:09

Claus Ibsen