I'm writing integration tests that start up a Play 2.2.2 application (e.g. Helpers.running(fakeApplication) {...}
. The first test completes without error, but the next gives the following (abridged) stack trace:
java.sql.SQLException: Attempting to obtain a connection from a pool that has already been shutdown.
Stack trace of location where pool was shutdown follows:
java.lang.Thread.getStackTrace(Thread.java:1588)
com.jolbox.bonecp.BoneCP.captureStackTrace(BoneCP.java:572)
com.jolbox.bonecp.BoneCP.shutdown(BoneCP.java:161)
com.jolbox.bonecp.BoneCPDataSource.close(BoneCPDataSource.java:143)
play.api.db.BoneCPApi.shutdownPool(DB.scala:411)
myApp.ApplicationTest$$anonfun$1.apply(ApplicationTest.scala:31)
at com.jolbox.bonecp.BoneCP.getConnection(BoneCP.java:553)
at controllers.Application$$anonfun$tests$1.apply(Application.scala:149)
at play.api.mvc.ActionBuilder$$anonfun$apply$10.apply(Action.scala:221)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
My current workaround is (as per this post):
class MyBoneCPPlugin(app: play.api.Application) extends BoneCPPlugin(app) {
override def onStop() {
// Prevent stopping the plug-in to avoid "Attempting to obtain a connection from a pool that has already been
// shutdown" exceptions
// super.onStop()
}
}
Is there a better way of doing this? What's the underlying problem? Shutting down the connection pool at the end of the test is fine, but I would have thought a new connection pool would be started the second time Play brought up the application?