March 3, 2008

GigaSpaces Cluster Bootstrapping and Automated Testing

In projects which use GigaSpaces XAP it's often needed to have a set of functional tests which verify the interaction of your code and GigaSpaces cluster. For example, if an application makes initial data loading it's good to have a test that verifies that the client's code really found a space and loaded all necessary data.

To implement such tests we need to bootstrap a cluster with an appropriate configuration and to run a set of tests for this cluster. It can be achieved by following the next steps:

  1. Use a testing framework which allows to run some set up code before running group of tests (looks like TestNG is the most appropriate choice for it cause it allows to group tests and has a sexy @BeforeGroups annotation)

  2. Put all the code which starts a cluster to the set up method (kinda of prerequisites for tests)

  3. Implement a functional test which uses the standard assertion mechanism to verify the cluster's state


This approach looks very useful, but the 2nd point is very tricky cause GigaSpaces (5.* and 6.0*) doesn't provide a mechanism, which will allow to start a cluster from code without black magic and dances with tambourine.

Here is a tricky workaround (which we've used on a Convergence project for testing purposes). It assumes the usage of Maven as a build tool (sorry Maven folks, I know that it's project management framework, but this definition sounds too mysterious :) ) and the project is a multi-module.

The idea behind it is very simple: to perform a cluster bootstrapping via Maven plugin before testing phase. I haven't found the appropriate plugin in Maven's repository so I wrote my own using Gigapult (check the usage and installation instructions on OpenSpaces.org).

Such approach allows to write the functional tests using a testing framework of your choice without putting cluster configuration and bootstrapping code into the setup methods. Moreover, it simplifies the creation of different build configurations on Continuous Integration server, cause it turns the configuration to the simple enumeration of Maven goals.

But putting the cluster bootstrapping to the build lifecycle and a functional tests, which can take much more time, then an impatient developer can wait, leads to the skipping of these phases. To avoid it, all time-consuming tests can be put to the separate module and run on demand using Maven's profiles. To create such configuration add a submodule to the Maven project (it can be done using the Maven Archetype Plugin) and adding the following section to the parent pom.xml:

<profiles>
  <profile>
    <id>functional-tests</id>
    <modules>
      <module>functional-tests</module>
    </modules>
  </profile>
</profiles>

After that, Maven will add the sub-module called "functional-tests" only if -Pfunctinal-tests was specified. Assuming that CI server supports Maven now we can specify goals for two build configurations:

  1. clean install - for running all unit test and packaging

  2. gigapult:gsm gigapult:gsc gigapult:pudeploy install -Pfunctional-tests - for running all unit tests, packaging, bootstrapping cluster and running functional tests (gigapult goals depend on cluster configuration)

Labels: , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home