Monday, February 13, 2006

Refreshable log4j configuration files

Friday, February 10, 2006

XML Schema

Good/Bad thing about technology is it is an endless journey. I wanted to blog the little things I learned daily so that overtime, the knowledge will accumulate. And it has been hard to keep up simply because I found myself kind of dipping into different topics and directions all the time. Just when I got comfortable with something, the next challenge comes along. This world is nothing but full of dynamics.

Okay, now comes to the topic of XML Schema. I have written a XML driven test automation tool. I kind of come up the format of those XML data without very carefully define its schema at the first place, and now in order to make this tool actually usable, it means that I need to have a clearly defined format for the test cases my system would require. And that comes my needs for some kind of format definition schema. Evaluating between DTD vs. XML Schema, I have gathered these links below.

http://www.sitepoint.com/article/xml-dtds-xml-schema

Thursday, February 09, 2006

Starting a separate process from inside a Java Application

The short answer is to use Runtime.getRuntime().exec(). But there is a catch. You have to handle the input and output from this newly created process to avoid process hangings.

A good article can be found at http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html.

The best practice here is to have something like the StreamGobbler which creates a separate thread and it will consume the stdout and stderr. You use Runtime.getRuntime().exec() to start the process, use the Process object it returns and get the ErrorStream and InputStream and pass it to the StreamGobber. Remember not to omit the error stream, because if your newly created process generate errors, and not being consumed in time, it will also hang.

I can successfully start processes which generate lots of output from this standalone application. But I have failed to do that from inside a J2ee container. I haven't figured out what's causing the problems yet. It seems that the process will be generated for a short period of time then got killed. Something that I can keep in mind for further investigation in the future.

Solution to the previous post

After some evalution, I have come to a set of solutions -
1. Implement everything in some kind of scripting language, be it Perl or Python or even Jython.
2. Figure out a way so that the in-container piece of the framework can start an outside container java process as the clients.
3. Create a separate web application server to take HTTP requests, and use HTTP requests as the way to communicate with the in-container piece.

Neither of the above solution looks simple enough for me since I don't have much scripting experiences. The second solution doesn't look very 'clean'. And the third approach is also kind of "heavy", since as the minium, I have to somehow set up another webserver as part of the test infrastructure which only does very simple communications.

In the end, I was suggested to use JMS as the solution and it does wonders. It is simple, elegant, and very light weight. Everything can be written in POJO.

Basically i create an additional topic in my J2EE environment, and have the in-container piece send "commands" to this topic. I have a small standalone java application which I call a controller, it will subscribe to this JMS topic, receive and process the commands. Any parameters needed by those commands can be sent through the JMS messages. This controller will be in charge of starting and stopping those clients at the right time. In the next post, I will collect some useful information about starting a process from a java application.

But in short, I implemented this solution in a week, and it beautifully hooked up the two pieces of my automation framework.