Order Matters – When Unit Tests Develop Unwanted Relationships

Wednesday, March 14, 2012

Good unit tests are supposed to be self-contained so that they can be run in a stand-alone fashion independent from other tests. So much for theory. In practice, unit tests sometimes develop unwanted relationships with each other that cause one test to unknowingly depend on another test’s prior execution or lack thereof. This article will shed some light on possible causes of such dependencies, strategies for early detection and mitigations using the example of JUnit tests executed through Maven’s popular Surefire test runner plugin.
Read the rest of this entry »

Caching Hibernate Entity Collections Considered Evil

Tuesday, March 13, 2012

Performance is hard, i.e., when tuning a client-server application for speedy response times and handling a sufficient number of concurrent users, expect pitfalls. One of these pitfalls will be outlined in this article: The attempt to use caching through Ehcache with Hibernate entities.
Read the rest of this entry »

“Java Concurrency” Talk – Slides Available

Sunday, August 14, 2011

The slides of the “Java Concurrency” talk by Thilo-Alexander Ginkel at the majug² – Java User Group Mannheim are now available for download.

Building Android Maven Projects With Eclipse

Friday, July 1, 2011

Using Maven for your Java build needs is generally a good idea as it provides automatic dependency management and self-contained, reproducible builds. For builds of Java EE applications, this has already become a de facto standard.

However, Maven is a command-line based technology, which does not provide any out-of-the-box integration with modern IDEs such as Eclipse. Fortunately, there is the m2e project, which adds Maven project support to Eclipse.

To build Android projects, a special Android Maven plugin is required. Unfortunately, using this build plugin does not yet provide support for importing the resulting project into Eclipse using m2e. Fortunately, there is the m2eclipse-android-integration plugin, which fills this gap and integrates the mavenized Android build with Google’s ADT for Eclipse.

Due to the recent transition of m2e from Sonatype to the Eclipse foundation, the current (as of 2011-07-01) m2eclipse-android-integration plugin is, however, not compatible with the Eclipse m2e 1.x plugin. Instead, it requires an older version (0.12.x), which is fortunately still available at Sonatype’s update site. Follow these instructions to set up your Eclipse environment:

Prerequisites: Eclipse 3.6.2 (Eclipse 3.7 is untested and supposedly already ships with m2e pre-installed, so you may have to wait for a compatible m2eclipse-android-integration version) with a current version of Google’s ADT installed.

  1. In Eclipse, go to “Help” | “Install New Software…”
  2. In the “Work with” dropdown, add the Sonatype m2e update site: http://m2eclipse.sonatype.org/sites/m2e
  3. Select the “Maven Integration for Eclipse (Required) – 0.12.1.20110112-1712″ entry for installation
  4. When prompted, restart Eclipse
  5. Open “Help” | “Install New Software…” again
  6. Enter the m2eclipse-android-integration update site: https://svn.codespot.com/a/eclipselabs.org/m2eclipse-android-integration/updates/m2eclipse-android-integration/
  7. Select the “Maven Integration for Android Development Tools – 0.2.5″ entry for installation
  8. When prompted, restart Eclipse a second time

The Android Maven integration for Eclipse should now be operational. Next, go ahead and import your Android project into Eclipse by Choosing “File” | “Import…” | “Maven” | “Existing Maven Projects”. Note that this will only work if you have already defined a pom.xml for your Android project. Instructions on setting this up are available in the maven-android-plugin documentation.

That’s basically it. In some cases the imported project may be created with incorrect Java Compiler settings, which will cause ADT to emit an error message such as:

Android requires compiler compliance level 5.0. Please fix project properties.

To fix this, right-click on the project node in the Project Explorer and select “Android Tools” | “Fix Project Properties” from the context menu or manually set the JDK Compliance of the project to 1.5 or 1.6.

That’s it, have fun!

Talk: “Java Concurrency” in Mannheim (in German)

Thursday, June 16, 2011

Sorry, this entry is only available in Deutsch.

Developer Productivity: Git / Bash Integration

Friday, June 10, 2011

Git, a distributed revision control system, is steadily gaining momentum. For beginners, Git typically comes with its unique challenges, which we will probably address in a separate post. On the other side, Git comes with plenty of customization and integration options due to its excellent scriptability, which are a major plus in terms of developer productivity.

This post will outline how to activate one of those gimmicks: Tweaking the bash prompt to enable displaying information about the current Git repository, such as the current branch or whether there are any dirty (or untracked) files. These instructions are based on the assumption that you are running a recent Ubuntu release, such as the current Ubuntu 11.04. Ubuntu 10.10 will also do the trick, while the status of Ubuntu 10.04 is currently unknown to the author. The procedure for other Linux distributions (especially Debian) should be similar.

First, make sure that you have the git package (which may be named git-core for your distribution version) installed and also install the basic bash-completion package. While bash-completion is active on Ubuntu by default, you need to manually enable it on Debian by adding the following snippet to /etc/bash.bashrc, which is used by bash to initialize interactive shell sessions (in contrast to /etc/profile for non-login shells):

# Check for interactive shell.
if [ -n "$PS1" ]; then
  if [ $bmajor -eq 2 -a $bminor '>' 04 ] || [ $bmajor -gt 2 ]; then
    if [ -r /etc/bash_completion ]; then
      # Source completion code.
      . /etc/bash_completion
    fi
  fi
fi
unset bash bminor bmajor

Once this is in place, we are ready to enable Git integration. First, you will need to decide if you would like to enable that tweak just for the current user or whether you would like to enable it globally (chances are good that you will not notice any difference for a single-user system). In this configuration example, we will take the local route. If you would like to activate the tweak globally, just make the changes in /etc/bash.bashrc instead.

So, let’s get started: What is displayed as the bash prompt is determined by the current setting of the PS1 variable. On a stock system that may read:

PS1='\u@\h:\w\$ '

To figure out your system’s default, type

echo ${PS1}

at the prompt.

To enable Git integration, we will override the default setting by adding the following line to ~/.bashrc:

PS1='\u@\h:\W$(__git_ps1 " (%s)")$'

If you would like to get an indicator (“*”) for dirty changes, set the GIT_PS1_SHOWDIRTYSTATE variable as in:

GIT_PS1_SHOWDIRTYSTATE=1

Further available options are:

  • GIT_PS1_SHOWSTASHSTATE: Shows an indicator (“$”) for a non-empty stash
  • GIT_PS1_SHOWUNTRACKEDFILES: Shows an indicator (“%”) for a untracked files

That’s basically it. Save your changes to .bashrc and open a new shell. When changing into a directory hosting a Git repository, you should see the enhanced prompt as in (note the branch specification in braces):

user@host:dir (master)$

If you like things a bit more colorful, you may prefer this variant:

PS1='\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\W\[\033[01;33m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ '

Enjoy!