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

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

      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 ...
}

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

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 系统既有类型的,也有非类型的。 我怎样才能轻松解决这个问题?

更新:

这与 conflicting inherited members 有关使用不同的类型,但我们可能能够以不同的方式解决我想要在这种情况下实现的目标。

最佳答案

我在转向打字时在这里花了一点时间。对于仍在寻找的人,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 上的第一条评论它指出

Perhaps just a docs addition to show that you don't need to use the ActorTestKit from Akka Typed and can just use TestProbes e.g. https://gist.github.com/chbatey/964b80adc2cd124fa4bf4624927b5be0

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

关于scala - 在同一规范文件中测试 akka-http 和 akka actor 时,如何解决冲突的 actor 系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60912372/

相关文章:

reactjs - 尝试使用 React-Spring 制作动画时出现错误 "TypeError:

javascript - typescript 装饰器 : Add instance field t

javascript - 为什么ioredis客户端开启keep-alive会超时?

ag-grid - 如何在 Ag-Grid 中将相同的相邻行与动态行跨度合并?

python - np.array 到 PIL 图像 --> Typerror : Cannot h

qt - 如何在使用 AUTORCC 的 CMake 项目中使用 qtquick_compiler_

scala - 在 Akka Streams 中模拟源

react-native - 我可以通过 expo 获得在 android 上工作的 webpack

c# - 如何从工作流对话框中删除标题中的问号?

python - 在 OR 工具中使用 IntVar