Interface BehaviorTestKit<T>


public interface BehaviorTestKit<T>
Used for synchronous testing pekko.actor.typed.Behaviors. Stores all effects e.g. Spawning of children, watching and offers access to what effects have taken place.

For asynchronous testing of Behaviors running see ActorTestKit

Not for user extension. See BehaviorTestKit.apply factory methods

  • Method Summary

    Modifier and Type
    Method
    Description
    <U> TestInbox<U>
    Get the child inbox for the child with the given name, or fail if there is no child with the given name spawned
    <U> TestInbox<U>
    childInbox(ActorRef<U> child)
    Get the child inbox for the child ActorRef, or fail if there is no such child.
    Get the pekko.actor.typed.Behavior testkit for the given child pekko.actor.typed.ActorRef.
    void
    Clear the log entries
     
    The current behavior, can change any time run is called
    void
    expectEffect(Effect expectedEffect)
    Asserts that the oldest effect is the expectedEffect.
    <R> R
    expectEffectPF(scala.PartialFunction<Effect,R> f)
    Asserts that the oldest effect matches the given partial function.
    <E extends Effect>
    E
    expectEffectType(scala.reflect.ClassTag<E> classTag)
    Asserts that the oldest effect is of type T.
    boolean
    Returns if there have been any effects.
    boolean
    Is the current behavior alive or stopped
    scala.collection.immutable.Seq<CapturedLogEvent>
    Returns all the CapturedLogEvent issued by this behavior(s)
    The receptionist inbox contains messages sent to system.receptionist
    ref()
    The self reference of the actor living inside this testkit.
    scala.collection.immutable.Seq<Effect>
    Requests all the effects.
    Requests the oldest Effect or pekko.actor.testkit.typed.Effect.NoEffects if no effects have taken place.
    Returns the current behavior as it was returned from processing the previous message.
    void
    run(T message)
    Send the message to the behavior and record any Effects
    void
    Send the first message in the selfInbox to the behavior and run it, recording Effects.
    The self inbox contains messages the behavior sent to context.self
    void
    signal(Signal signal)
    Send the signal to the behavior and record any Effects
  • Method Details

    • context

      TypedActorContext<T> context()
    • retrieveEffect

      Effect retrieveEffect()
      Requests the oldest Effect or pekko.actor.testkit.typed.Effect.NoEffects if no effects have taken place. The effect is consumed, subsequent calls won't will not include this effect.
    • childInbox

      <U> TestInbox<U> childInbox(String name)
      Get the child inbox for the child with the given name, or fail if there is no child with the given name spawned
    • childInbox

      <U> TestInbox<U> childInbox(ActorRef<U> child)
      Get the child inbox for the child ActorRef, or fail if there is no such child.
    • childTestKit

      <U> BehaviorTestKit<U> childTestKit(ActorRef<U> child)
      Get the pekko.actor.typed.Behavior testkit for the given child pekko.actor.typed.ActorRef.
    • selfInbox

      TestInbox<T> selfInbox()
      The self inbox contains messages the behavior sent to context.self
    • ref

      ActorRef<T> ref()
      The self reference of the actor living inside this testkit.
    • retrieveAllEffects

      scala.collection.immutable.Seq<Effect> retrieveAllEffects()
      Requests all the effects. The effects are consumed, subsequent calls will only see new effects.
    • hasEffects

      boolean hasEffects()
      Returns if there have been any effects.
    • expectEffect

      void expectEffect(Effect expectedEffect)
      Asserts that the oldest effect is the expectedEffect. Removing it from further assertions.
    • expectEffectType

      <E extends Effect> E expectEffectType(scala.reflect.ClassTag<E> classTag)
      Asserts that the oldest effect is of type T. Consumes and returns the concrete effect for further direct assertions.
    • expectEffectPF

      <R> R expectEffectPF(scala.PartialFunction<Effect,R> f)
      Asserts that the oldest effect matches the given partial function.
    • currentBehavior

      Behavior<T> currentBehavior()
      The current behavior, can change any time run is called
    • returnedBehavior

      Behavior<T> returnedBehavior()
      Returns the current behavior as it was returned from processing the previous message. For example if pekko.actor.typed.scaladsl.Behaviors.unhandled is returned it will be kept here, but not in currentBehavior().
    • isAlive

      boolean isAlive()
      Is the current behavior alive or stopped
    • run

      void run(T message)
      Send the message to the behavior and record any Effects
    • runOne

      void runOne()
      Send the first message in the selfInbox to the behavior and run it, recording Effects.
    • signal

      void signal(Signal signal)
      Send the signal to the behavior and record any Effects
    • logEntries

      scala.collection.immutable.Seq<CapturedLogEvent> logEntries()
      Returns all the CapturedLogEvent issued by this behavior(s)
    • clearLog

      void clearLog()
      Clear the log entries
    • receptionistInbox

      TestInbox<Receptionist.Command> receptionistInbox()
      The receptionist inbox contains messages sent to system.receptionist