Class TestActorRef<T extends Actor>

java.lang.Object
org.apache.pekko.actor.LocalActorRef
org.apache.pekko.testkit.TestActorRef<T>
Direct Known Subclasses:
TestFSMRef

public class TestActorRef<T extends Actor> extends org.apache.pekko.actor.LocalActorRef
This special ActorRef is exclusively for use during unit testing in a single-threaded environment. Therefore, it overrides the dispatcher to CallingThreadDispatcher and sets the receiveTimeout to None. Otherwise, it acts just like a normal ActorRef. You may retrieve a reference to the underlying actor to test internal logic.
  • Constructor Details

  • Method Details

    • apply

      public static <T extends Actor> TestActorRef<T> apply(scala.Function0<T> factory, scala.reflect.ClassTag<T> evidence$1, ActorSystem system)
    • apply

      public static <T extends Actor> TestActorRef<T> apply(scala.Function0<T> factory, String name, scala.reflect.ClassTag<T> evidence$2, ActorSystem system)
    • apply

      public static <T extends Actor> TestActorRef<T> apply(Props props, ActorSystem system)
    • apply

      public static <T extends Actor> TestActorRef<T> apply(Props props, String name, ActorSystem system)
    • apply

      public static <T extends Actor> TestActorRef<T> apply(Props props, ActorRef supervisor, ActorSystem system)
    • apply

      public static <T extends Actor> TestActorRef<T> apply(Props props, ActorRef supervisor, String name, ActorSystem system)
    • apply

      public static <T extends Actor> TestActorRef<T> apply(scala.reflect.ClassTag<T> t, ActorSystem system)
    • apply

      public static <T extends Actor> TestActorRef<T> apply(String name, scala.reflect.ClassTag<T> t, ActorSystem system)
    • apply

      public static <T extends Actor> TestActorRef<T> apply(ActorRef supervisor, scala.reflect.ClassTag<T> t, ActorSystem system)
    • apply

      public static <T extends Actor> TestActorRef<T> apply(ActorRef supervisor, String name, scala.reflect.ClassTag<T> t, ActorSystem system)
    • create

      public static <T extends Actor> TestActorRef<T> create(ActorSystem system, Props props, ActorRef supervisor, String name)
      Java API: create a TestActorRef in the given system for the given props, with the given supervisor and name.
    • create

      public static <T extends Actor> TestActorRef<T> create(ActorSystem system, Props props, ActorRef supervisor)
      Java API: create a TestActorRef in the given system for the given props, with the given supervisor and a random name.
    • create

      public static <T extends Actor> TestActorRef<T> create(ActorSystem system, Props props, String name)
      Java API: create a TestActorRef in the given system for the given props, with the given name.
    • create

      public static <T extends Actor> TestActorRef<T> create(ActorSystem system, Props props)
      Java API: create a TestActorRef in the given system for the given props, with a random name.
    • props

      public Props props()
    • dispatcher

      public MessageDispatcher dispatcher()
    • newActorCell

      protected org.apache.pekko.actor.ActorCell newActorCell(org.apache.pekko.actor.ActorSystemImpl system, org.apache.pekko.actor.InternalActorRef ref, Props props, MessageDispatcher dispatcher, org.apache.pekko.actor.InternalActorRef supervisor)
    • receive

      public void receive(Object o)
      Directly inject messages into actor receive behavior. Any exceptions thrown will be available to you, while still being able to use become/unbecome.
    • receive

      public void receive(Object o, ActorRef sender)
      Directly inject messages into actor receive behavior. Any exceptions thrown will be available to you, while still being able to use become/unbecome.
    • underlyingActor

      public T underlyingActor()
      Retrieve reference to the underlying actor, where the static type matches the factory used inside the constructor. Beware that this reference is discarded by the ActorRef upon restarting the actor (should this reference be linked to a supervisor). The old Actor may of course still be used in post-mortem assertions.
    • watch

      public ActorRef watch(ActorRef subject)
      Registers this actor to be a death monitor of the provided ActorRef This means that this actor will get a Terminated()-message when the provided actor is permanently terminated.

      Returns:
      the same ActorRef that is provided to it, to allow for cleaner invocations
    • unwatch

      public ActorRef unwatch(ActorRef subject)
      Unregisters this actor from being a death monitor of the provided ActorRef This means that this actor will not get a Terminated()-message when the provided actor is permanently terminated.

      Returns:
      the same ActorRef that is provided to it, to allow for cleaner invocations
    • toString

      public String toString()