Thursday, May 20, 2010

Create or update?

A couple of days ago a bunch of sectors of my hard disk decided to vanish into the blue, bringing with them some files of my local repository (no worry about that) and some files of my NetBeans installation, configuration files included (no worry about that too, but a little more work required). While my colleagues are providing me with a new hard disk, on which I asked for a fresh installation (before you ask: it is a company policy that we only use operating systems from Redmond on our personal computers) I am working on the laptop. Which, by chance, happens to be a fresh installation too as it is the replacement for my old one (who can nowadays use NetBeans AND Firefox AND SQLServer AND all the rest, antivirus included, on 1GB? Maybe 2GB is not that much, but at least it doubles my previous supply)

Ok, so after reinstalling and reconfiguring my stuff I checked out a group of three projects we're working on. Projects that our Hudson guarantees as healthy (see one below).


Open the group of projects, set as main, fix the configurations for my local databases (for each database we have one instance for manual and acceptance tests and one for the automated ones) configurations clean and build, test (just to be sure).

91% passed. What? That means fail! but... what's wrong? mmm... it seems there's a row in the User table that causes Hibernate to complain about constraint violations. That is strange, as - as far as I know, but I obviously might be wrong - all our automated persistence tests run with HibernateOpenViewSession, a simple Runner that before each test opens a Session and rollbacks everything after the invocation (nothing new under the sun, but quite handy):

@Override
protected void invokeTestMethod(Method method, RunNotifier notifier) {
try {
final Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();

super.invokeTestMethod(method, notifier);

if (session.isOpen()) {
session.clear();
session.getTransaction().rollback();
}

if (session.isOpen()) {
session.close();
}
} catch (Throwable t) {
System.err.println("HibernateOpenViewSession RUNNER FAILURE");
notifier.fireTestFailure(new Failure(Description.EMPTY, t));
}
}

Yet, that row is still there. Well, maybe one of our tests doesn't use our favourite runner. So, why doesn't Hudson complain? After a little investigation it turned out that the Hibernate configuration for our CI server has a hibernate.hbm2ddl.auto=create property, where my local file had update. That fixed, all my local files ran smoothly and gave me a green bar.

Now the hunt for Red October will start. Ehm... I meant the hunt for the culprit test, of course... I'll keep my eyes on the ball.

By the way, we almost reached our 1000th test on the project :-) and it is only part of a group of three... it may sound a little to many out there, but for us it is a great success.

As a parting note, let me stress again the importance of a CI server to avoid the "it runs on my machine" syndrome - which in this case was "it doesn't work on my machine" :-)

No comments: