Hello All,
 
I'm suffering a weird kind of a problem while running my JUnit Test Cases against a database which uses derby as an engine.
Once after each test case gets completed I'm shutting down the database and derby using the following piece of code
 
DriverManager.getConnection("jdbc:derby:;shutdown=true");
 
I'm running a batch of test cases at a fly using the JUnit option available in Apache ANT, from Command Line mode. There are eleven test cases in my Batch. Since my test cases make use of hibernate to boot up derby as well as the database, I don't have to worry about starting it up. It is done in embedded mode. I have to be worried about shutting down the derby instance and db properly. The problem is, the first 3 test cases start up and shutdown the derby and db properly, but when the fourth test case tries to boot up the db I'm getting the following error ,
 
===================================================================================================================
2008-12-06 05:24:47.154 GMT Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main] Cleanup action starting
java.sql.SQLException: Failed to start database <db-name>., see the next exception for details.
 at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
 at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
 at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
 at org.apache.derby.impl.jdbc.EmbedConnection.bootDatabase(Unknown Source)
 at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
 at org.apache.derby.impl.jdbc.EmbedConnection30.<init>(Unknown Source)
 at org.apache.derby.jdbc.Driver30.getNewEmbedConnection(Unknown Source)
 at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
 at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)
 at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:81)
 at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:96)
 at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1.acquireResource(C3P0PooledConnectionPool.java:89)
 at com.mchange.v2.resourcepool.BasicResourcePool.acquireUntil(BasicResourcePool.java:665)
 at com.mchange.v2.resourcepool.BasicResourcePool.access$500(BasicResourcePool.java:32)
 at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1204)
 at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:368)
Caused by: java.sql.SQLException: Another instance of Derby may have already booted the database<db-name>..
 at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
 at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
 ... 13 more
Caused by: ERROR XSDB6: Another instance of Derby may have already booted the database <db-name>.
 at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
 at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.privGetJBMSLockOnDB(Unknown Source)
 at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.getJBMSLockOnDB(Unknown Source)
 at org.apache.derby.impl.store.raw.data.BaseDataFileFactory.boot(Unknown Source)
 at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
 at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
 at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
 at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
 at org.apache.derby.impl.store.raw.RawStore.boot(Unknown Source)
 at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
 at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
 at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
 at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
 at org.apache.derby.impl.store.access.RAMAccessManager.boot(Unknown Source)
 at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
 at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
 at org.apache.derby.impl.services.monitor.BaseMonitor.startModule(Unknown Source)
 at org.apache.derby.iapi.services.monitor.Monitor.bootServiceModule(Unknown Source)
 at org.apache.derby.impl.db.BasicDatabase.bootStore(Unknown Source)
 at org.apache.derby.impl.db.BasicDatabase.boot(Unknown Source)
 at org.apache.derby.impl.services.monitor.BaseMonitor.boot(Unknown Source)
 at org.apache.derby.impl.services.monitor.TopService.bootModule(Unknown Source)
 at org.apache.derby.impl.services.monitor.BaseMonitor.bootService(Unknown Source)
 at org.apache.derby.impl.services.monitor.BaseMonitor.startProviderService(Unknown Source)
 at org.apache.derby.impl.services.monitor.BaseMonitor.findProviderAndStartService(Unknown Source)
 at org.apache.derby.impl.services.monitor.BaseMonitor.startPersistentService(Unknown Source)
 at org.apache.derby.iapi.services.monitor.Monitor.startPersistentService(Unknown Source)
 ... 13 more
 
====================================================================================================================
 
 
 
 
But the third test case has shutdown the db as well as the derby.. The hibernate log shows,
 
2008-12-06 10:55:52,169 ERROR [main] (JDBCExceptionReporter.java:78) - Connections could not be acquired from the underlying database!
 
 
 
I've totally no idea about what is going inside the derby. If it is able to start it up and shut it down for three consecutive times then why its not able to do the same for the upcoming runs. The starting up and shutting down is done internally in the test case , and the test cases are run in a batch mode using JUnit. So no way I'm stopping the tests in the middle. Derby and database have to be started up and shutdown 11 times consecutively since I've 11 cases in my JUnit task. If anyone could shed some lights on the issue it'd be helpful for me to proceed further.
 
 
Thanks in Advance,
 
Kamesh P G.