我如何测试是否调用了 akka-streams 接收器?

How can I test that an akka-streams sink was called?

我有一个用例,我将接收器传递给某个演员 - 所以我也可以传递 TestSink

当那个 actor 收到消息时,我使用

将消息传递给那个接收器
case class SomeActor[T, U](sink: Sink[U, NotUsed] {
  def behavior: Behavior[T] = Behavors.receive[T] { (ctx, msg) =>
    msg match {
      case MessageT =>
        ref = sink.runWith(ActorSource.actorRef[U](PartialFunction.empty, PartialFunction.empty, 0, OverflowStrategy.fail)
        ref ! MessageU
        Behaviors.same
    }
  }
}

如何测试接收器是否已收到 MessageU

尝试使用 akka-stream-testkit (https://doc.akka.io/docs/akka/current/stream/stream-testkit.html)。示例的测试代码(省略类型以保持简洁):

val probe = TestProbe()
val sink = Sink.actorRef(probe.ref, onCompleteMessage = "completed", onFailureMessage = _ => "failed"))
val someActor = SomeActor(sink)

// use someActor.behavior

probe.expectMsg(1.second, MessageU)