簡體   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?

我有一個使用 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 ...
}

編譯測試失敗,因為存在沖突的參與者系統:

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 系統既有類型化的,也有非類型化的。 我怎樣才能輕松解決這個問題?

更新:

這與具有不同類型的沖突繼承成員有關,但我們可能能夠以不同的方式解決我在這種情況下想要實現的目標。

我在這里花了一點時間,同時轉向打字。 對於仍在尋找的人, 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]()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM