Akka演员测试包

我有以下测试用例:

class MutableStateActorTest extends TestKit(ActorSystem("MutableStateActorTest")) with WordSpecLike with Matchers {

  "A MutableStateActor" must {

    val actRef = TestActorRef[MutableStateActor]

    "mutate state in order" in {
      1 to 5 foreach {
        x => actRef ! Increment
      }
    }
  }
}

这可能不是那么简单,但是当我尝试运行它时出现以下错误:

An exception or error caused a run to abort: Found class akka.actor.ActorPath, but interface was expected 
java.lang.IncompatibleClassChangeError: Found class akka.actor.ActorPath, but interface was expected
    at akka.testkit.TestActorRef.<init>(TestActorRef.scala:47)
    at akka.testkit.TestActorRef$.apply(TestActorRef.scala:141)
    at akka.testkit.TestActorRef$.apply(TestActorRef.scala:137)
    at akka.testkit.TestActorRef$.apply(TestActorRef.scala:146)
    at akka.testkit.TestActorRef$.apply(TestActorRef.scala:144)
    at q31.sandbox.statetest.MutableStateActorTest$$anonfun$1.apply$mcV$sp(MutableStateActorTest.scala:16)
    at q31.sandbox.statetest.MutableStateActorTest$$anonfun$1.apply(MutableStateActorTest.scala:14)
    at q31.sandbox.statetest.MutableStateActorTest$$anonfun$1.apply(MutableStateActorTest.scala:14)

我想这与Actor References有关?

回答(1)

2 years ago

您可能正在运行akka的快照版本 . 在akka 2.4的最新版本中,有些事情已经改变了 ActorRef ,或者更好地说 ActorPath . 您正在使用的库是针对旧版本的akka编译的,因此期望 ActorPath 是一个接口,而不是它在较新版本中的类 .

相互矛盾的变化似乎是这样的:https://github.com/akka/akka/commit/e6aea0b7d1bab7668072e1d92945ebb1865bdd9a

在这个变化中(以下更改了以下内容: -sealed trait ActorPath extends Comparable[ActorPath] with Serializable { +sealed abstract class ActorPath extends Comparable[ActorPath] with Serializable {

要解决此问题,请从您自己项目中可能使用的快照移开,或者从您自己使用的akka(快照)版本重新编译引发错误的项目中的代码 .