ScalaTest运行时Scala播放Slick RejectedExecutionException [英] Scala Play Slick RejectedExecutionException on ScalaTest runs
问题描述
我的FlatSpec测试正在抛出:
My FlatSpec tests are throwing:
java.util.concurrent.RejectedExecutionException: Task slick.backend.DatabaseComponent$DatabaseDef$$anon$2@dda460e rejected from java.util.concurrent.ThreadPoolExecutor@4f489ebd[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 2]
但是只有当我运行多个套件时,才在第二个套件上运行;似乎有些测试之间没有重置.我正在使用OneAppPerSuite
提供应用上下文.每当我使用OneAppPerTest
时,它在第一个测试/套件之后都会再次失败.
But only when I run more than one suite, on the second suite forward; it seems there's something that isn't reset between tests. I'm using OneAppPerSuite
to provide the app context. Whenever I use OneAppPerTest
, it fails again after the first test/Suite.
我设置了override def beforeEach = tables.foreach ( _.truncate )
来清除表,其中truncate
只是从表中删除所有内容:Await.result (db.run (q.delete), Timeout.Inf)
I have a override def beforeEach = tables.foreach ( _.truncate )
set up to clear the tables, where truncate
just deletes all from a table: Await.result (db.run (q.delete), Timeout.Inf)
我的DAO层具有以下设置:
I have the following setup for my DAO layer:
SomeMappedDaoClass extends SomeCrudBase with HasDatabaseConfig
其中
trait SomeCrudBase { self: HasDatabaseConfig =>
override lazy val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)
implicit lazy val context = Akka.system.dispatchers.lookup("db-context")
}
在application.conf
db-context {
fork-join-executor {
parallelism-factor = 5
parallelism-max = 100
}
}
我正在重构代码,使其脱离Play的Guice DI.以前,当它具有@Inject() (val dbConfigProvider: DatabaseConfigProvider)
并扩展了HasDatabaseConfigProvider
而不是在DAO类上时,一切都运行良好.现在不知道了,我也不知道为什么.
I was refactoring the code to move away from Play's Guice DI. Before, when it had @Inject() (val dbConfigProvider: DatabaseConfigProvider)
and extended HasDatabaseConfigProvider
instead on the DAO classes, everything worked perfectly. Now it doesn't, and I don't know why.
提前谢谢!
推荐答案
SomeMappedDaoClass
和object
只是出于兴趣? (我知道它说的是课程,但是...).
Just out of interest is SomeMappedDaoClass
an object
? (I know it says class but...).
当测试Play框架时,在处理object
建立与Play框架各部分的连接的问题时,我遇到了此类问题.
When testing the Play framework I have run into this kind of issue when dealing with object
s that setup connections to parts of the Play Framework.
在测试之间和测试文件之间,播放app
被终止并重新启动,但是,创建的object
仍然存在(因为它们是object
,因此它们在JVM上下文中被初始化过一次-我认为)
Between tests and between test files the Play app
is killed and restarted, however, the object
s created persist (because they are object
s, they are initialised once within a JVM context--I think).
这可能导致object
具有连接(用于测试,演员,其他任何东西),该连接引用测试中使用的app
的第一个实例.当app
终止并且新的测试开始新的app
时,该连接现在没有指向任何对象.
This can result in an object
with a connection (be it for slick, an actor, anything...) that is referencing the first instance of the app
used in a test. When the app
is terminated and a new test starts a new app
, that connection is now pointing to nothing.
这篇关于ScalaTest运行时Scala播放Slick RejectedExecutionException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!