多重播放测试错误:"从已关闭的池中获取连接"

时间:2014-03-25 14:35:49

标签: testing playframework-2.2 bonecp

我正在编写启动Play 2.2.2应用程序的集成测试(例如Helpers.running(fakeApplication) {...}。第一个测试完成没有错误,但下一个测试完成了以下(删节)堆栈跟踪:

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)

我目前的解决方法是(根据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() 
  }
}

有更好的方法吗?底层问题是什么?在测试结束时关闭连接池是可以的,但是我认为Play第二次启动应用程序时会启动一个新的连接池吗?

0 个答案:

没有答案