3

I have a Route defined using akka-http that uses an actor inside to send messages. 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. 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.

Esildor
  • 169
  • 3
  • 10
  • `ScalaTestWithActorTestKit` and `ScalatestRouteTest` are not compatible. If you do not really need `ScalaTestWithActorTestKit`, maybe you can remove it? – jrudolph Mar 30 '20 at 13:17

1 Answers1

0

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

// 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

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

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

pgn
  • 669
  • 1
  • 6
  • 16