作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个使用 Typesafe Slick (v 1.0.1) 的 Play (v 2.2.0) 应用程序,我正在尝试编写一个测试 (specs2) 来为 PostgreSQL 数据库提供种子,然后调用各种 Controller 操作以验证数据的存在。在我的测试中,我有:
"Countries" should {
"initialize" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
AppDB.database.withSession {
implicit session: Session =>
AppDB.dal.create
AppDB.dal.seedForTests
AppDB.dal.Countries.findAll().size must be_>=(1)
}
}
}
"respond to Index()" in {
val result = controllers.Countries.index()(FakeRequest())
status(result) must equalTo(OK)
}
SQLException: Attempting to obtain a connection from a pool that has already been shutdown.
[error] SQLException: Attempting to obtain a connection from a pool that has already been shutdown.
[error] Stack trace of location where pool was shutdown follows:
[error] java.lang.Thread.getStackTrace(Thread.java:1503)
[error] com.jolbox.bonecp.BoneCP.captureStackTrace(BoneCP.java:559)
[error] com.jolbox.bonecp.BoneCP.shutdown(BoneCP.java:161)
[error] com.jolbox.bonecp.BoneCPDataSource.close(BoneCPDataSource.java:143)
[error] play.api.db.BoneCPApi.shutdownPool(DB.scala:414)
[error] play.api.db.BoneCPPlugin$$anonfun$onStop$1.apply(DB.scala:264)
[error] play.api.db.BoneCPPlugin$$anonfun$onStop$1.apply(DB.scala:262)
[error] scala.collection.immutable.List.foreach(List.scala:318)
[error] play.api.db.BoneCPPlugin.onStop(DB.scala:262)
...
FakeApplication(...)
和
AppDB.database.withSession
代码中更高的块,以及包装
val result = controllers.Countries.index(...)
AppDB.database.withSession
中的代码包装,但仍然没有运气。
最佳答案
您可以使用 AroundExample
初始化您的数据库并运行您的测试:
class CountriesSpec extends mutable.Specification with AroundExample {
def around[R : AsResult](r: =>R) =
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
AppDB.database.withSession { implicit session: Session =>
AppDB.dal.create
AppDB.dal.seedForTests
AppDB.dal.Countries.findAll().size must be_>=(1)
// just AsResult(r) with the latest 2.2.3 specs2
AsResult.effectively(r)
}
}
"Countries" should {
"respond to Index()" in {
val result = controllers.Countries.index()(FakeRequest())
status(result) must equalTo(OK)
}
}
}
关于scala - 如何通过 SQLException : Attempting to obtain a connection from a pool that has already been shutdown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19283421/
我是一名优秀的程序员,十分优秀!