简体   繁体   English

在同一规范文件中测试 akka-http 和 akka actor 时,如何解决冲突的 actor 系统?

[英]How can I resolve conflicting actor systems while testing akka-http and akka actors at the same spec file?

I have a Route defined using akka-http that uses an actor inside to send messages.我有一个使用 akka-http 定义的Route ,它使用内部的 actor 来发送消息。 My route looks like this:我的路线是这样的:

      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")
          }
        }
      }

My test spec:我的测试规范:

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

Compiling the test fails since there are conflicting actor systems:编译测试失败,因为存在冲突的参与者系统:

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)

Overriding the actor system doesn't help either since the inherited actor systems are of both typed and untyped ones.覆盖 actor 系统也无济于事,因为继承的 actor 系统既有类型化的,也有非类型化的。 How can I resolve this easily?我怎样才能轻松解决这个问题?

Update:更新:

This is related to conflicting inherited members with different types, but we might be able to solve what I want to achieve in this context differently.这与具有不同类型的冲突继承成员有关,但我们可能能够以不同的方式解决我在这种情况下想要实现的目标。

I spent a little time here while moving over to typed.我在这里花了一点时间,同时转向打字。 For anyone still looking, there's a nice hint at https://developer.lightbend.com/guides/akka-http-quickstart-scala/testing-routes.html对于仍在寻找的人, 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

Looking at the first comment at https://github.com/akka/akka-http/issues/2036 it notes查看https://github.com/akka/akka-http/issues/2036上的第一条评论,它指出

Perhaps just a docs addition to show that you don't need to use the ActorTestKit from Akka Typed and can just use TestProbes eg https://gist.github.com/chbatey/964b80adc2cd124fa4bf4624927b5be0也许只是一个文档补充,以表明您不需要使用 Akka Typed 的 ActorTestKit 并且可以只使用 TestProbes 例如https://gist.github.com/chbatey/964b80adc2cd124fa4bf4624927b5be0

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM