Java

Conditionally ignoring JUnit tests

Barend Garvelink

A useful technique that I reinvent every once in a while is conditionally ignoring JUnit tests. Unit tests are supposed to be isolated, but occasionally you hit something that makes assumptions about the environment, such as code that executes a platform-specific shell command or (more commonly) an integration test that assumes the presence of a database. To keep such a test from breaking unsuspecting builds, you can @Ignore it, but that means you have to edit the code to run the test in a supported environment.

Proper Maven projects put their integration tests in a separate source folder called src/it/java and put an extra execution of the maven-surefire-plugin into their pom.xml, tied to the integration-test phase of the Maven build lifecycle. This is Maven's recommended way of setting these up. It ties in beautifully with the pre-integration-test and post-integration-test phases that can be used to set up and tear down the environmental dependencies of the integration test suite, such as initializing a database to a known state. There is nothing wrong with this approach, but it's a bit heavy handed for the simplest of cases.

In these simple situations it's easier to just keep the integration tests in the src/test/java directory and run them along with all your other tests. However, you still need a way to trigger them only when the right environment is present. This is easily dealt with by writing your own JUnit TestRunner and some custom annotations, as shown below.

 Read more

Play! 2.0 and Jenkins

Arjan Wulder

Lately I am doing a lot of coding with Play! 2.0 in my spare time and I must say it is a really nice framework that makes web application development easier. I am also trying to figure out if I can do all the stuff with a Play! 2.0 project like I can do with a Java EE project. An important aspect for me is adding the project in Jenkins. Since there is not a Jenkins plugin (yet) that supports Play! 2.0 does not mean that it is not possible!

 Read more

Jongo, query in Java as in Mongo shell

yamsellem

Mongo — the document oriented NoSQL database supported by 10gen — offers a compact, easy to learn and well documented query language. Unfortunately, using Mongo with its Java driver can be tricky: querying, mapping results and handling polymorphism require lots of code. Some libraries aim to simplify this (like Morphia), but none allows to query in a shell fashion. Jongo tries to fill that need, querying with the use of strings and unmarshalling results into Java objects.

 Read more

JavaFX 2.0 beta

Gerbrand van Dieijen

Last weekend the public beta of JavaFX 2.0 came out. I've much anticipated this release, as you might guess from my previous posting on JavaFX 2.0. I've downloaded the JavaFX-runtime, SDK and Netbeans-plugins the following evening from Oracle's JavaFX page and started trying out JavaFX by viewing and running the examples from the SDK from Netbeans.
I'm quite enthusiastic, read on the learn more!
 Read more

Making the bootstrap loader "just another ClassLoader"

Recently, I was tweaking MultiSPI to add the following class loading fallback logic:

if (threadContextLoader != null) {
  loadFromContextLoader(className);
} else if (systemLoader != null) {
  loadFromSystemLoader(className);
} else {
  loadFromBootstrapLoader(className);
}

and realized that it's not immediately evident how to do this in a uniform way. But actually, it's quite simple...getting a ClassLoader object for the bootstrap loader is just a couple of lines of code.
 Read more

Making the bootstrap loader "just another ClassLoader"

Recently, I was tweaking MultiSPI to add the following class loading fallback logic:

if (threadContextLoader != null) {
  loadFromContextLoader(className);
} else if (systemLoader != null) {
  loadFromSystemLoader(className);
} else {
  loadFromBootstrapLoader(className);
}

and realized that it's not immediately evident how to do this in a uniform way. But actually, it's quite simple...getting a ClassLoader object for the bootstrap loader is just a couple of lines of code.
 Read more

How the quest for transaction timeout’s did cost me money

Kris Geusebroek

At our project the focus is at making the application stable and controllable. So instead of building cool new features
we are spending our time making sure the application is able to run stable in the production environment.

After the first few issues the so called 'Transaction timeout' issue raised it's ugly head.
Every now and then the application threw an exception due to a transaction timeout.
This was very strange since the timeout was set to 30 seconds and the complete processing of the whole
application was done in less than 2 seconds (spread over more than 1 transaction).
 Read more

MultiSPI - consuming service provider interfaces in 2011

Implementing a Java SPI isn't a particularly 2011 experience1. Creating a correctly-named text file in META-INF/services, making sure it is correctly packaged and remembering to keep it up to date when you refactor is sufficiently annoying and error-prone that there are at least a couple of utils that aim to make this easier.

At XebiaLabs, however, we're not just the implementors of our plugin SPI. We also write the deployment engine that consumes these plugins. And unfortunately, there isn't much out there to help you read, load and verify services. Hence MultiSPI.
 Read more

You have just been deconfluenced

Wilfred Springer

Before you start wondering, 'deconfluencing' is not a word you can lookup in Merriam Webster. Perhaps it should be. It certainly is something I needed, and eventually ended up creating myself.

 Read more

Which Generic Swallow

Scene opens...
An idyllic landscape unfolds before our eyes, in yonder distance we see a figure approaching us. He goes by the name of Arthur, King of the Britons...
 Read more