3

我有一个Route使用 akka-http 的定义,它使用内部的演员来发送消息。我的路线如下所示:

      path("entity") {
        post {
          entity(as[Enrtity]) {
            entity =>
              val result: Future[Message] = mainActor.ask {
                ref: akka.actor.typed.ActorRef[Message] =>
                  Message(
                    entity = entity,
                    replyRef = ref
                  )
              }
              complete("OK")
          }
        }
      }

我的测试规格:

class APITest
    extends ScalaTestWithActorTestKit(ManualTime.config)
    with ScalatestRouteTest
    with AnyWordSpecLike {
      val manualTime: ManualTime = ManualTime()
     // my tests here ...
}

编译测试失败,因为存在冲突的参与者系统:

class APITest inherits conflicting members:
[error]   implicit def system: akka.actor.typed.ActorSystem[Nothing] (defined in class ActorTestKitBase) and
[error]   implicit val system: akka.actor.ActorSystem (defined in trait RouteTest)

覆盖actor系统也无济于事,因为继承的actor系统既有类型的也有无类型的。我怎样才能轻松解决这个问题?

更新:

这与具有不同类型的冲突继承成员有关,但我们可能能够以不同的方式解决我想要在这种情况下实现的目标。

4

1 回答 1

0

我在这里花了一点时间来打字。对于仍在寻找的人,https://developer.lightbend.com/guides/akka-http-quickstart-scala/testing-routes.html有一个很好的提示

// the Akka HTTP route testkit does not yet support a typed actor system (https://github.com/akka/akka-http/issues/2036)
// so we have to adapt for now
lazy val testKit = ActorTestKit()
implicit def typedSystem = testKit.system
override def createActorSystem(): akka.actor.ActorSystem =
  testKit.system.classicSystem

查看https://github.com/akka/akka-http/issues/2036上的第一条评论,它注意到

也许只是一个文档补充表明您不需要使用来自 Akka Typed 的 ActorTestKit 并且可以使用 TestProbes 例如https://gist.github.com/chbatey/964b80adc2cd124fa4bf4624927b5be0

val probe = TestProbe[Ping]()>val probe = testKit.createTestProbe[Ping]()

于 2021-05-06T23:51:12.650 回答