JMS testing

At work, I am currently building a small framework which behaves like a bridge that carries the requests and their responses between the client and our system. The client sends his requests through a web service call. This request is sent to our bridge framework named, Response Handler,  over RMI. Response Handler takes this request and puts into a JMS queue for processing by the application listening this queue. After the request is processed, the response is put into another JMS queue which Response Handler is polling periodically. Response Handler gets the response from this queue and sends back to web service. The following diagram shows the flow of work:

In order to test Response Handler, I wrote a tiny client which sends requests over RMI similar to the ones that the web service will send in the real environment and also a transaction schedular simulator, that fetches the requests from JMS queue and puts their response back. The web service-Response Handler integration over RMI can be done in the same VM with out any problem. Also since the Weblogic was always up at work, there also no problem with JMS integration. However, if I go to home, my tests for Response Handler was not running since, it requires a running Weblogic server. I didn’t want to be bound to Weblogic, so I installed OpenJMS to my laptop. Everything was fine and my tests were running without any problem on my laptop. When I deployed my application to the CruiseControl, tests were getting failed. There were no OpenJMS instance on Unix ! So I started to look for an alternative. I checked out Mockrunner. I need some integration tests which sends a requests to a JMS queue and listens a queue for a response. I discovered that Mockrunner does not simulate that behavior and directly returns something when it has to wait for a message in a queue. So I looked for an alternative and come up with Somnifugi. It works inside a single JVM and JMS Messages are send between Threads. So, in order to make my tests pass on any machine, all I did was to run each component(web service client, Response Handler, Transaction Scheduler, JMS-Somnifugi) in a seperate thread in the same JVM. I really liked it so my dependcy to Weblogic JMS server is broken and my tests can now work on any machine without requiring a JMS server for run.

I like in memory server solutions, like HSQLDB. Whenever you have a tight coupling to a heavy resource, they come up for rescue to make your tests run without any problem. The only lacking point I would like to state about Somnifugi is its scarce documentation. I come up accidentally how to use it from my application while checking Javadocs. It would be better if the author prepare a  seperate how-to doc for it. 

Leave a Comment