Intellij idea Scalatest/Sbt/Akka TestKit在测试持久参与者时出现问题
我正在一个持久演员身上运行Akka TestKit测试 我面临的一个奇怪问题是,尽管我在每次测试之前或之后清理了持久性文件夹,但当我使用sbt运行完整的测试套件时,持久性文件夹似乎没有被删除。这是一个问题,因为从一个测试场景到下一个测试场景,都会携带持久化的数据。当下一个场景开始时,参与者从上一个场景中恢复数据,从而伪造其测试 只有在我使用sbt跑步时才会发生这种情况。如果我用Intellij运行它,我就没有问题了,我所有的测试场景都运行得很好 请参阅下面我在测试中加入的PersistenceSpecIntellij idea Scalatest/Sbt/Akka TestKit在测试持久参与者时出现问题,intellij-idea,sbt,akka,scalatest,akka-testkit,Intellij Idea,Sbt,Akka,Scalatest,Akka Testkit,我正在一个持久演员身上运行Akka TestKit测试 我面临的一个奇怪问题是,尽管我在每次测试之前或之后清理了持久性文件夹,但当我使用sbt运行完整的测试套件时,持久性文件夹似乎没有被删除。这是一个问题,因为从一个测试场景到下一个测试场景,都会携带持久化的数据。当下一个场景开始时,参与者从上一个场景中恢复数据,从而伪造其测试 只有在我使用sbt跑步时才会发生这种情况。如果我用Intellij运行它,我就没有问题了,我所有的测试场景都运行得很好 请参阅下面我在测试中加入的PersistenceS
abstract class PersistenceSpec(system: ActorSystem) extends TestKit(system)
with ImplicitSender
with FeatureSpecLike
with Matchers
with GivenWhenThen
with BeforeAndAfterAll
with BeforeAndAfterEach
with PersistenceCleanup {
def this(name: String, config: Config) = this(ActorSystem(name, config))
override protected def beforeAll() = deleteStorageLocations()
override protected def afterAll() = {
deleteStorageLocations()
TestKit.shutdownActorSystem(system)
}
override protected def beforeEach() : Unit = {
deleteStorageLocations()
super.beforeEach()
}
override protected def afterEach(): Unit = {
super.afterEach()
deleteStorageLocations()
}
def killActors(actors: ActorRef*) = {
actors.foreach { actor =>
watch(actor)
system.stop(actor)
expectTerminated(actor)
}
}
}
trait PersistenceCleanup {
def system: ActorSystem
val storageLocations = List(
"akka.persistence.journal.leveldb.dir",
"akka.persistence.journal.leveldb-shared.store.dir",
"akka.persistence.snapshot-store.local.dir").map { s =>
new File(system.settings.config.getString(s))
}
def deleteStorageLocations(): Unit = {
storageLocations.foreach{
dir => Try(FileUtils.deleteDirectory(dir)) match {
case Success(e) => system.log.debug(s"Deleting: ${dir.getName} was a success: ${e} ")
case Failure(e) => system.log.debug(s"Deleting: ${dir.getName} was a failure: ${e} ")
}
}
}
}
对我来说,不起作用的是每次之前或之后
有什么问题吗?Intellij runs没有任何功能,这不是很奇怪吗
问题有人知道吗?请分享经验,
解决方案或想法
我不确定是什么导致了这个问题,但我发现在测试持久参与者时它是有用的。内存中的后端避免了必须清除持久性目录的整个问题。我不确定是什么导致了这个问题,但我发现在测试持久性参与者时非常有用。内存中的后端避免了必须清除持久性目录的整个问题。