a peek into my MIND

December 31, 2009

Installing Ubuntu on Windows

Filed under: General — Bharat Kondeti @ 3:22 am

There are different ways of installing multiple operating systems on a single machine. One way is to use a virtualization software. One can have a host operating system running multiple guest operating system as virtual machines. For ex. Windows XP can be running Ubuntu, Windows 7 as virtual machines. This will effectively give access to multiple operating systems with out an actual reboot of entire machine.

There are number of commercial as well as free virtualization software’s available (Extensive list), but my favorite is Virtual Box from sun micro-systems. VirtualBox is a powerful virtualization tool available for free to download and easy to use.

To install Ubuntu as a guest operating system on Windows XP one has to first download and install VirtualBox on windows. Then one has to download Ubuntu ISO in to a hard disk or burn into a CD. One’s VirtualBox is installed, using virtual machine wizard one can install Ubuntu on the windows. Installation and configuration of new OS is quite self explanatory.


December 7, 2009

Unit testing Log4j log statements.

Filed under: Java, Testing — Tags: , , — Bharat Kondeti @ 6:15 pm

Logging is an important aspect in writing any software application. Logs properly utilized provide valuable information related to code flow. Mining logs is a way to gather data related to performance of the application and to debug the application.

As part of our current application we wrote tools in Perl and Groovy to mine the logs to collect statistics related to the application. In these tools, we primarily look for string patterns and if some one unintentionally changes the log statements inside the code it breaks our tools also. It’s always beneficial to surround SOME of the log statements with Junit test.

Extending AppenderSkeleton to create a custom append-er.

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;

public class TestingAppender extends AppenderSkeleton {

  //We are collecting all the log messages in to a list
  private static List messages = new ArrayList();

  // This method is called when ever any logging happens
  // We are simply taking the log message and adding to our list
  protected void append(LoggingEvent event) {

  //This method is called when the appender is closed.
  //Gives an opportunity to clean up resources
  public void close() {

  public boolean requiresLayout() {
    return false;

  public static String[] getMessages() {
    return (String[]) messages.toArray(new String[messages.size()]);

  public static void clear() {

Then we need to write couple of methods to setup the custom append-er and remove it. As part of setUp and tearDown methods of JUnit tests appropriate methods can be called.

private void setupLog4j(TestingAppender appender) {
  //Get the root logger for the
  Logger root = Logger.getRootLogger();

  //If there are no appenders, means Log4j is not initialized properly
  if (!root.getAllAppenders().hasMoreElements()) {
    System.out.println("*******Log4j is not initilized**********");
  } else {

   //Set to appropriate log level and add custom appender

private void resetLog4j(TestingAppender appender) {
  Logger root = Logger.getRootLogger();

As part of tests we can call TestingAppender.getMessages() to get the list of messages and assert for the appropriate log message. This way we can have unit tests for log statements also.

Create a free website or blog at WordPress.com.