Play Slick exception in Specs “Task slick.backend.DatabaseComponent rejected from java.util.concurrent.ThreadPoolExecutor”

£可爱£侵袭症+ 提交于 2019-12-06 06:29:30

The problem is likely caused by the play app being re-created for every test suite (spec), as described here. In short, objects don't get re-created, and thus dbConfig inside your Groups remains, but is "stale" during the second test.

A quick and dirty workaround is to not get dbConfig once initially, but re-grab it for every operation:

object Groups {
  val groups = TableQuery[GroupTableDef]

  // note this is a function now
  def dbConfig() = DatabaseConfigProvider.get[JdbcProfile](Play.current)

  def add(group: Group): Future[Int] = {
    dbConfig().db.run(groups += group)
  }
}

This is obviously not ideal performance-wise, but since database operations tend to be expensive anyway, this re-grabbing cost might not carry too much weight.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!