Saturday, August 28, 2010

Cargo, Maven and the benefits of integrated functional testing

I little while back an ex-colleague mentioned that I should have a look at an open source project called Cargo. So what is Cargo, their mission statement states "Cargo is a thin wrapper that allows you to manipulate Java EE containers in a standard way." and that is exactly what they do.

In 2 of my previous posts:
Some useful Maven configurations
and
Your POM is quite nice

I went through some maven configurations and practices along with the concept of continuous integration. This article and Cargo make a logical "Part 3". In the above 2 articles there is a lot of emphasis on continuous testing, but with some very large / legacy systems total unit test coverage is something of a luxury and quite often neglected. Depending on the size, type and deployment of the application there will be certain circumstances where to quickly gain, promote and gauge system stability, integration or functional testing will be a much faster and more beneficial practice than retro fitting unit test coverage.

Tools like Selenium, QTP (QuickTestPro) a number of others, allow you to simply record, playback and validate the application. In my current environment and I am sure in a lot of other places, these types of tests are run by people outside the development team, namely testing teams, clients or even business analysts. I personally feel to gain the most benefit out of functional testing and automation tools these need to happen at build time. Having these tests run outside of the standard development environment add extra unneeded iterations, and more external dependencies that can delay a software project. Bringing these type of tests into you build process allow you detect, maintain and repair system issues before influencing the world outside the development environment.

Like everything else surrounding the "continuous integration" philosophy, automation is key. This is were Cargo helps you out. If you already have the other tools like Maven and Hudson setup it is very quick to integrate and benefit from Cargo.

My environment runs on Weblogic, so that is what I will be using as my example, but Cargo supports about all the major web and application servers used. So this should work for anyone.

Maven has the concept of phases which can be thought of like a collection of goals. A full list of the phases of Maven is available here: Lifecycle Reference

The 3 we are interesting in with regards to Cargo are:
pre-integration-test
perform actions required before integration tests are executed. This may involve things such as setting up the required environment.
integration-test
Process and deploy the package if necessary into an environment where integration tests can be run.
post-integration-test
Perform actions required after integration tests have been executed. This may including cleaning up the environment.

So any phase higher than ’pre-integration-test’ will trigger the deployment to your application server.

Cargo can only stop and start local application servers, deployments can take place remotely, not all application servers have "deployers", detail for these are on the Cargo site. The one feature I am very happy with is the server properties. You can from within you POM configure all the required, JDBC, JMS, and JVM settings you require for your application server to function, which is awesome. In my examples I just needed JVM and JDBC settings, but theoretically you should be able to configure most things you may require.

You could integrate the Cargo plugin into your existing POMs, I prefer to keep it separate. I am not including any Selenium configuration to keep this post about Cargo. However here is a very nice Maven Selenium Guide.

So for the local server configuration, this will startup the application server, create the JDBC configuration and deploy the war.

Tuesday, August 17, 2010

Pimp your Eclipse, a collection of darker colour schemes

Since my recent disappointment with NetBeans, I figured I would make myself feel a bit better by customizing my Eclipse to almost look a little like one of the themes that come with Netbeans. Now Eclipse doesn't really cater for "Themes", more just colour schemes that you can import. There are 2 basic ways to import bulk settings...

Firstly, make a backup! (I don't wanna be blamed for lost hours :))
To do that in Eclipse, go to File > Export > Preferences and export all the preferences. This will export all your settings so you can quickly roll back.

Now the 2 ways to update (besides changing every setting manually) are:
1. Import.
If you have or download a *.epf file you can import. In Eclipse through File > Import > Preferences.

Or
2. Manual.
The settings for the basic and java editors are stored in the following 2 files:
[workspace]\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.ui.prefs
[workspace]\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.ui.editors.prefs

The problem with the import is that it can contain ALL the settings of the person that exported it, there is no option to only export the UI bits, so I personally prefer the Manual route, but both work fine.

So to begin, my theme, Dark Blue Eclipse:


The 2 perfs files can be downloaded from, and copied the manual way:
Download List

I tried the following theme, and quite liked it, however I did miss blue:
Prabir's Blog


I also came across the following collection of themes and what is nice with the links here is that srand did it the manual way, and the other is a clean *.epf import ( I checked the files, no unrelated settings):
srand's blog
Which actually come from:
Eclipse color themes

Inkpot:


Sula:


Vibrant Ink:


Wombat:


I have not actually tried the following site but it should be very useful if you are looking to create your own colour scheme:
Edwards research Eclipse Gen

Monday, August 16, 2010

Spring, JMS, Weblogic, and FizzBuzz

There are 2 reasons for me posting this example:
I have not looked at anything Spring related for about a month, and last week I got to show someone new to Spring all the joy that it can bring, I couldn't shut up for about a hour. One of the reasons he is looking into using Spring happens to involve JMS, something I had not yet covered in my blog.
The other reason is:
I was challenged by a work colleague to come up with a more complex FizzBuzz implementation than his monster rule implementation and not being a person to back down on a challenge.

Here it is. Spring, JMS, Weblogic and FizzBuzz

All the code for this example will be available --Here--

There are a couple JMS examples out there using ActiveMQ, and either JMS "client type" implementations or Message Driven POJOs but not together. For this example I will show both methods and will use Weblogic, those that have worked with Weblogic know there are always little nuances. The first thing is to have a standalone client for Weblogic, you need the weblogic.jar (Full Client), I have uploaded this into my local maven repo so that I can just place this within my POM.


In the Weblogic admin console I set up the JMS modules as follows (5 Queues and a Connection Factory):


Now for what this example does:
* It creates 100 messages...
* It reads 100 messages... while reading, it checks the content, depending on the value it creates a message to a fizz queue or a buzz queue or a fizzbuzz queue and a result queue.
* There is message driven POJO on the result queue that prints out the content.

How it does this:
The Spring application context below is pretty straight forward but it does have a couple things to note:
1. The jndiTemplate, jmsQueueConnectionFactory, jmsDestinationResolver, jmsTemplate are all used in combination to get to the application server, and connect to the actual JMS queues.
2. The "messageDrivenListener" and "queue" beans are the configuration for the message driven POJO. In that config is "concurrentConsumers", this allows you to specify how many listeners will be created to process the messages on the queue. For this example I only require 1.



I have created just a simple example message structure for this, with a generic content which looks like:






The message driven POJO is just the standard javax.jms.MessageListener interface implementation:



The client classes to read and create messages, make use of Springs JMSTemplate to simplify your interaction with the JMS server:



And the finally the Main class, that creates the 100 messages, then reads them, publishing messages to 4 different queues. The reading of the results queue is triggered by the application server and handled by Springs "DefaultMessageListenerContainer"



Note: if you constantly run this example, you will end up with a ton of messages on the Fizz, Buzz and FizzBuzz queues as there is nothing reading those messages to clean it up.

Wednesday, August 11, 2010

NetBeans 6.9 and 6.9.1 find usages not working.

Yesterday I was investigating an issue, during my investigation I started following the code trail, I finally get to a place where the when calling "Find Usages" on a method returns me nothing... I think great... Delete, Delete, Delete... cleaning up unused code always takes me to a happy place, so after this I just check with someone that had originally worked on this bit of functionality which goes a bit pale, stating that there has to be something wrong and that code must run...

I quickly revert back to local history, do the "Find Usages" again, and yip still no reference. We go to the code where we think it should be called... and surprisingly it is there... go delete the code, do a "mvn clean install" and it fails correctly...

Off to Google... "netbeans find usages not working" leads me to the following logged bug: Bug 186314

As I commented there, I installed the latest 6.9.1 version and the issue still occurs.

This is such a nasty bug in my opinion that I will probably have to go back to Eclipse until it is sorted. I have just recently changed teams and have roughly 14000 java files that I know nothing about, life without "Find Usages" will be painful.

Tuesday, August 10, 2010

Maven Remote Windows Scheduled Task

Just a quick Maven / Windows config I came across the other day, I have recently switched teams and they are using Maven and Hudson to control some of their server tasks. I figure it could come in handy sometime.

To start and stop a Windows Scheduled task from a Maven pom, actually using the ant run plugin

Replace the [Server Name] and [Task Name] obviously.

Saturday, August 7, 2010

Domain Name Change

Since I am now quite addicted to this whole blogging thing, I decided to "move" my blog to new url: www.briandupreez.net... it's just a lot simpler to tell someone my name + .net than java hyphen it hypen zen . blogspot.com... which will still work anyways.


www.briandupreez.co.za should also be routing to the .net address, I say should as I played and broke a couple DNS settings trying to get everything pointing to the right place and found a pretty useful site if you ever have to check out what your DNA settings look like to the rest of the world Pingability... There is a link to instantly check your domains relative mappings Quick Check.

Tuesday, August 3, 2010

Glassfish ESB, easier than you think. Part II

To continue from Part I, which simply just went in and out of the BPEL process, I will now add a couple EJBs to show a nice little Glassfish ESB structured activity, namely: Flow

Since this is now getting a little larger, I have made all the demo source available ... here.

So using the EJB project Wizard I create 2 EJB projects: DemoEJB1, DemoEJB2
once you have the project, Add a webservice:



For demo purposes I am going to have 2 web services with 2 methods, gatherAppData and gatherHistoryData, these 2 functions can happen concurrently and cause you no pain as long as you change different data in your object model.
Once that is done, from the project menu select the web service, drag it over to the right hand side of the BPEL editor, on the orange circle.



Then update the Partner Link information that pops up.


To execute the 2 web service calls concurrently you will need a "flow", grab that from the structured activities.



From the web service palette grab 2 invoke objects and place them in the flow.

Edit the invoke objects, choosing the different webservices.


Create variables for both, in and out. Try stick to a naming convention of some sorts as when you get to 20ish components it can get very messy.



So now the BPEL will look something like the following.


You can add as many concurrent steps to a flow as you like or as many different values you have within your object model.
To get these 2 invokes to function we need to assign the input and output variables and then assign the result of both to the output variable of the BPEL process. For each assign, map the input variable of the BPEL to the input variable of the relevant data for the service that is being called. In the 3rd assign map the relevant part of the each output variable to the output variable of the BPEL.

just for clarity here is the last assign in the mapper view.



And that is it... 2 concurrent web service requests within a Glassfish ESB process



The final steps are to add the newly created EJBs to the "Service Assembly" in the composite application, you can just drag the EJB project directly onto the middle JBI section, build, deploy and test.

Monday, August 2, 2010

Eclipse -clean

I am sure most Eclipse users have run into some "funny" (as in, this milk tastes funny, not funny haha) issues from time to time, namely:

Extremely slow start up times.
Unable to open any editor.
A resource already exists on disk when building.
etc.
etc.

These will probably be more of an issue for users that install a large amount of plugins or products like MyEclipseIDE.

I was having some of the issues I mentioned above, went searching for a bit and found and Eclipse option:
-clean

It looks like this tells Eclipse to erase and rebuild it's internal plugin cache which in turn sorts out some versioning / state issues. You only need to run it once so the option can be removed after the workspace restart.

So for MyEclipseIDE I added it to myeclipse.ini just before the -vm option.
Closed and opened Eclipse... and both issues were solved. /cheer

If you are just using standard Eclipse, you can place it in your eclipse.ini

Popular Posts

Followers