lshift/diffa — pull request #30 by aprescott (2012-02-07 16:14:07+00:00)
Title: Fix failing HibernateSystemConfigStore tests

The following 7 tests from this class fail on a clean install with `mvn test`.

* shouldBeAbleToSetSystemProperty
* shouldGetExceptionWhenRetrievingMissingUser
* shouldBeAbleToAddUserAndSeeItByGet
* shouldBeAbleToAddUserAndSeeItInList
* shouldGetExceptionWhenRetrievingDeletedUser
* shouldNotSeeDeletedUsersInList
* shouldBeAbleToUpdateUser

These tests pass if `HibernateSystemConfigStoreTest` is tested in isolation with `mvn test -Dtest=HibernateSystemConfigStoreTest`.

The interesting part of the stack trace from the surefire report is below. It seems that perhaps when multiple tests run, the same location in memory (for the in-memory database) is used which causes the constraint violation.

All tests pass with this change.

```
-------------------------------------------------------------------------------
Test set: net.lshift.diffa.kernel.config.system.HibernateSystemConfigStoreTest
-------------------------------------------------------------------------------
Tests run: 7, Failures: 0, Errors: 7, Skipped: 0, Time elapsed: 0.097 sec <<< FAILURE!
shouldBeAbleToSetSystemProperty(net.lshift.diffa.kernel.config.system.HibernateSystemConfigStoreTest) Time elapsed: 0.011 sec <<< ERROR!
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2666)
at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2911)
at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:97)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:189)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at net.lshift.diffa.kernel.config.system.HibernateSystemConfigStore$$anonfun$deleteDomain$1.apply(HibernateSystemConfigStore.scala:52)
at net.lshift.diffa.kernel.config.system.HibernateSystemConfigStore$$anonfun$deleteDomain$1.apply(HibernateSystemConfigStore.scala:38)
at net.lshift.diffa.kernel.util.SessionHelper.withSession(SessionHelper.scala:32)
at net.lshift.diffa.kernel.config.system.HibernateSystemConfigStore.deleteDomain(HibernateSystemConfigStore.scala:38)
at net.lshift.diffa.kernel.config.system.HibernateSystemConfigStoreTest.setup(HibernateSystemConfigStoreTest.scala:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:115)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:102)
at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
Caused by: java.sql.BatchUpdateException: integrity constraint violation: foreign key no action; FK50EE698D3FEF99C0 table: STORE_CHECKPOINTS
at org.hsqldb.jdbc.JDBCPreparedStatement.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 44 more
```