Wednesday, October 22, 2008

Eclipse - Bringing Back Run Last Launched

If you upgraded to the Eclipse 3.4, you may have noticed that the shortcut key for Running the Last Launched does not work properly. In older versions of Eclipse, CTRL+F11 used to run the last launched application or Junit test. By default, in Eclipse 3.4, this is used to run the *.java file that currently has focus.

If you would like to change this functionality back, just follow these instructions:

1. Open Eclipse Preferences by Navigating to Window -> Preferences
2. Using the Tree, Navigate to Run/Debug -> Launching
3. Here you will find the group called Launch Operation
4. Choose the option that says Always launch the previously launched application

Enjoy and pay it forward!!!

Thursday, September 11, 2008

PuttyCS...You rock

Have you ever wished that there was a way to open many putty sessions, and be able to send the same command to all of the putty sessions at once? I have, and looks like I am not the only one.

PuttyCS is a tool that you can use to send the same command to many different telnet / ssh clients. This little tool has come in handy many times recently.

I had a situation where I had to simulate 200 instances of a command line application running on a server, in order to determine the performance of the application and the load that it would put on the server. Using this tool, I was able to open 200 putty sessions, start the application, and exercise it.

Another situation that I have is ongoing. Working within a cluster environment provides many benefits, but also, it can be a headache. In my circumstance, I have to tail the logs on each node from time to time. Using this tool, it becomes very easy to connect to different servers, and tail the logs on each node.

Once again, I highly recommend this tool, it is sure to save a lot of time and effort.

Monday, August 11, 2008

EasyMock Tip

EasyMock is a light weight Mock library used for mocking interfaces in Unit Tests. Here is a little tip on what I believe to be an undocumented best practice.

Let's say you have a Unit Test that is testing an object called CustomerController. CustomerController has a dependency on Interface CustomerDao Typically, you may see in the unit test, code that looks similar to the following:

protected void setUp() throws Exception {
    controller = new CustomerController();
    custDao = createMock(CustomerDao.class);
    controller.setCustDao(custDao);
}

public void testFindCustomers() throws Exception {
    expect(custDao.getCustomers()).andReturn(new ArrayList());
    replay(custDao);
    controller.findCustomers();
    verify(custDao);
}

As you will notice, I am specifying one mock custDao, and the system under test is the controller. This is pretty standard and straightforward use of EasyMock. Now let's see what happens when we have to add an additional dependency on the controller:

protected void setUp() throws Exception {
    controller = new CustomerController();
    custDao = createMock(CustomerDao.class);
    invoiceController = createMock(InvoiceController.class);
    controller.setCustDao(custDao);
    controller.setInvoiceController(invoiceController);
}

public void testFindCustomers() throws Exception {
    expect(custDao.getCustomers()).andReturn(new ArrayList());
    replay(custDao);
    controller.findCustomers();
    verify(custDao);
}

public void testApplyCustomerPayment() throws Exception {
    Customer customer = new Customer();
    BigDecimal paymentAmt = new BigDecimal(100);
    invoiceController.applyPayment(customer, paymentAmt);
    replay(invoiceController);
    controller.applyPayment(customer, paymentAmt);
    verify(invoiceController);
}

This also seems to be a very valid test. I would argue though that it is not complete. You are verifying that the appropriate methods are called on the objects / interfaces that you set expectations for. However, if a method is called on the custDao in the controller.applyPayment or a method is called on the invoiceController during the controller.findCustomers, without an expectation / verification the test will still pass. This may not be the desired behavior and therefore I would argue that the test is incomplete.

On my team, someone determined that a way to handle these types of situations is to create a private method on the test called replayAll and verifyAll. This included the maintaining of an array list of all of the mocks that is used within the test. While this is a valid solution, I wanted to see what other EasyMock users were doing. Here is what I found:

protected void setUp() throws Exception {
    controller = new CustomerController();
    mockControl = createControl();
    custDao = mockControl.createMock(CustomerDao.class);
    invoiceController= mockControl.createMock(InvoiceController.class);
    controller.setCustDao(custDao);
    controller.setInvoiceController(invoiceController);
}

public void testFindCustomers() throws Exception {
    expect(custDao.getCustomers()).andReturn(new ArrayList());
    mockControl.replay();
    controller.findCustomers();
    mockControl.verify();
}

public void testApplyCustomerPayment() throws Exception {
    Customer customer = new Customer();
    BigDecimal paymentAmt = new BigDecimal(100);
    invoiceController.applyPayment(customer, paymentAmt);
    mockControl.replay();
    controller.applyPayment(customer, paymentAmt);
    mockControl.verify();
}

The subtle difference to look at between these two scenarios is that the latest one uses what is known as a IMocksControl object. This IMocksControl object keeps track of what mocks were created on it so that all you would need to do in order to make sure that you are replaying and verifying all of the mocks is to call the replay and verify methods on the IMocksControl object. This ensures that all of the expectations, whether explicit or implied, are met. Thanks Tammo Freese for your help in finding this great golden nugget within the EasyMock framework.

Thursday, August 7, 2008

Barcamp Grand Rapids Episode 3 :- Revenge of the Unconference

Barcamp Grand Rapids 3 is almost here!!!

After attending the first two BarCampGR(s), I have to say that I am most excited about attending this one. Not only does each one seems to get better and better, but this year, we have had a huge amount of support from the local businesses and we have surpassed expectation of registered attendees. I am very excited to see friends that I have made from the past events, as well as making new ones.

If you are new to the BarCamp concept, please take the time to investigate it further. I will say that is unlike any other commercial conference that you have ever attended. First and foremost, the event is 100% free. Now don't get the wrong impression, since the event is going to last for two days and it is free, please don't expect that you will be forced to brown bag it for the weekend. Thanks to generous donations from local area businesses, this event will also be catered and we will be handing out schwag to boot.

This will be a great time, and I hope to see you there.....

Friday, July 11, 2008

Eclipse Tip: Static Imports

One of the great features of Java 1.5 is Static Imports. In order to configure Eclipse to search for static imports in a particular class, you have to perform the following steps:

  1. Navigate to Preferences by clicking on the Window -> Preferences Menu Item
  2. Navigate to Java -> Editor -> Content Assist -> Favorites using the menu tree (or search for Favorites using the search bar at the top)
  3. Click the New Type button
  4. Type in the name of the Class that has static methods that you would like to be used when using Eclipse's Content Assist / Code Completion (eg Assert)
  5. Click on the Browse button which will bring up the Open Type Dialog using what you entered previously as the search criteria
  6. Find the class that you would like to add, and then click Okay on the Open Type Dialog
  7. Then Click Okay on the New Type Favorite Dialog.
Now when you are editing Java code, instead of typing Assert.assertEquals, you only need to type assertEquals, with Ctrl-Space, and the Assert Type will be searched for in order to resolve the static import.

If this helps, pay it forward....

Friday, July 4, 2008

Goodbye P2, Welcome Back Update Manager

Well, I gave it a good go. I tried my best to wrap my arms and my head around P2. It wasn't until I read this blog, that I finally understood how to get P2 to work the way that I wanted it to work - complete with bundle pooling. However, I felt that there were just too many steps necessary in order to get it up and running in that fashion. Combine that with the limited documentation, I have reverted Ganymede to use the old Update Manager using these instructions.

I still do believe that P2 is a step in the right direction, however the learning curve is just too steep for me at this point. I hope to see improvement in P2's user experience in the future, at which time, I will give it another try.

Thursday, June 26, 2008

Fixing Eclipse Ganymede Startup Problems

If by chance, you are like me, and the first time that you ran Eclipse Ganymede, you were greeted with an exception screen like this one:



Here are the steps necessary to resolve that issue:

1.) Navigate to your $ECLIPSE_HOME directory (the directory where you installed Eclipse)
2.) Copy your eclipse.ini file, for backup purposes
3.) Open your eclipse.ini file and modify it to look similar to this:




4.) Try to start up Eclipse again, and hopefully your problem should be solved

The main problem seems to be that the initial settings does not allocate enough memory for Eclipse to run. By adjusting the memory settings, by using the example eclipse.ini file that I have shown, you are giving Eclipse enough memory to start up.

This interesting thing is that this issue does not seem to affect all installations. The "vanilla" Eclipse Ganymede that I obtained from Eclipse worked on one of my machines, but not on another.

If this helps, please pay it forward.

Thanks