3

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?

user3364825
  • 1,541
  • 1
  • 15
  • 23
  • Could it be that you take a reference to the pool and keep as a field inside of an object? Objects live with the jvm so then the connection pool from the first test would be kept across the rest of the tests. – johanandren Apr 03 '14 at 11:24
  • Have the same problem and I opened a Play issue: https://github.com/playframework/playframework/issues/3867 – Sebastien Lorber Jan 29 '15 at 11:35

0 Answers0