Package akka.actor.testkit.typed.javadsl
Class BehaviorTestKit<T>
- java.lang.Object
-
- akka.actor.testkit.typed.javadsl.BehaviorTestKit<T>
-
public abstract class BehaviorTestKit<T> extends java.lang.ObjectUsed for synchronous testingBehaviors. Stores all effects e.g. Spawning of children, watching and offers access to what effects have taken place.Not for user extension or instantiation. See
BehaviorTestKit.createfactory methodsFor asynchronous testing of
Behaviors running seeActorTestKit
-
-
Constructor Summary
Constructors Constructor Description BehaviorTestKit()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static com.typesafe.config.ConfigapplicationTestConfig()JAVA APIabstract <U> TestInbox<U>childInbox(ActorRef<U> child)Get the child inbox for the child with the given name, or fail if there is no child with the given name spawnedabstract <U> TestInbox<U>childInbox(java.lang.String name)Get the child inbox for the child with the given name, or fail if there is no child with the given name spawnedabstract <U> BehaviorTestKit<U>childTestKit(ActorRef<U> child)abstract voidclearLog()Clear the log entriesstatic <T> BehaviorTestKit<T>create(Behavior<T> initialBehavior)JAVA APIstatic <T> BehaviorTestKit<T>create(Behavior<T> initialBehavior, java.lang.String name)JAVA APIstatic <T> BehaviorTestKit<T>create(Behavior<T> initialBehavior, java.lang.String name, com.typesafe.config.Config config)JAVA APIabstract Behavior<T>currentBehavior()The current behavior, can change any timerunis calledabstract voidexpectEffect(Effect expectedEffect)Asserts that the oldest effect is the expectedEffect.abstract <U extends Effect>
UexpectEffectClass(java.lang.Class<U> effectClass)Asserts that the oldest effect is an instance of of class T.abstract java.util.List<Effect>getAllEffects()Requests all the effects.abstract java.util.List<CapturedLogEvent>getAllLogEntries()Returns all theCapturedLogEventissued by this behavior(s)abstract EffectgetEffect()Requests the oldestEffectorakka.actor.testkit.typed.javadsl.Effects.noEffectsif no effects have taken place.ActorRef<T>getRef()The self reference of the actor living inside this testkit.abstract booleanhasEffects()Returns if there have been any effects.abstract booleanisAlive()Is the current behavior alive or stoppedabstract TestInbox<Receptionist.Command>receptionistInbox()The receptionist inbox contains messages sent tosystem.receptionistabstract Behavior<T>returnedBehavior()Returns the current behavior as it was returned from processing the previous message.abstract voidrun(T message)Send the message to the behavior and record anyEffectsabstract <Res> ReplyInbox<Res>runAsk(Function<ActorRef<Res>,T> messageFactory)Constructs a message using the provided 'messageFactory' to inject a single-use "reply to"ActorRef, and sends the constructed message to the behavior, recording anyEffects.<Res> ReplyInbox<Res>runAsk(java.lang.Class<Res> responseClass, Function<ActorRef<Res>,T> messageFactory)The same as<Res>runAsk(akka.japi.function.Function<akka.actor.typed.ActorRef<Res>,T>), but with the response class specified.abstract <Res> StatusReplyInbox<Res>runAskWithStatus(Function<ActorRef<StatusReply<Res>>,T> messageFactory)The same as<Res>runAsk(akka.japi.function.Function<akka.actor.typed.ActorRef<Res>,T>)but only for requests that result in a response of typeStatusReply.<Res> StatusReplyInbox<Res>runAskWithStatus(java.lang.Class<Res> responseClass, Function<ActorRef<StatusReply<Res>>,T> messageFactory)The same as<Res>runAskWithStatus(akka.japi.function.Function<akka.actor.typed.ActorRef<akka.pattern.StatusReply<Res>>,T>), but with the response class specified.abstract voidrunOne()Send the first message in the selfInbox to the behavior and run it, recordingEffects.abstract TestInbox<T>selfInbox()The self inbox contains messages the behavior sent tocontext.selfabstract voidsignal(Signal signal)Send the signal to the beheavior and record anyEffects
-
-
-
Method Detail
-
applicationTestConfig
public static com.typesafe.config.Config applicationTestConfig()
JAVA API
-
create
public static <T> BehaviorTestKit<T> create(Behavior<T> initialBehavior, java.lang.String name, com.typesafe.config.Config config)
JAVA API
-
create
public static <T> BehaviorTestKit<T> create(Behavior<T> initialBehavior, java.lang.String name)
JAVA API
-
create
public static <T> BehaviorTestKit<T> create(Behavior<T> initialBehavior)
JAVA API
-
runAsk
public abstract <Res> ReplyInbox<Res> runAsk(Function<ActorRef<Res>,T> messageFactory)
Constructs a message using the provided 'messageFactory' to inject a single-use "reply to"ActorRef, and sends the constructed message to the behavior, recording anyEffects.The returned
ReplyInboxallows the message sent to the "reply to"ActorRefto be asserted on.
-
runAsk
public <Res> ReplyInbox<Res> runAsk(java.lang.Class<Res> responseClass, Function<ActorRef<Res>,T> messageFactory)
The same as<Res>runAsk(akka.japi.function.Function<akka.actor.typed.ActorRef<Res>,T>), but with the response class specified. This improves type inference in Java when asserting on the reply in the same statement as therunAskas in:testkit.runAsk(Done.class, DoSomethingCommand::new).expectReply(Done.getInstance());If explicitly saving the
ReplyInboxin a variable, the version without the class may be preferred.
-
runAskWithStatus
public abstract <Res> StatusReplyInbox<Res> runAskWithStatus(Function<ActorRef<StatusReply<Res>>,T> messageFactory)
The same as<Res>runAsk(akka.japi.function.Function<akka.actor.typed.ActorRef<Res>,T>)but only for requests that result in a response of typeStatusReply.
-
runAskWithStatus
public <Res> StatusReplyInbox<Res> runAskWithStatus(java.lang.Class<Res> responseClass, Function<ActorRef<StatusReply<Res>>,T> messageFactory)
The same as<Res>runAskWithStatus(akka.japi.function.Function<akka.actor.typed.ActorRef<akka.pattern.StatusReply<Res>>,T>), but with the response class specified. This improves type inference in Java when asserting on the reply in the same statement as therunAskWithStatusas in:testkit.runAskWithStatus(Done.class, DoSomethingWithStatusCommand::new).expectValue(Done.getInstance());If explicitly saving the
StatusReplyInboxin a variable, the version without the class may be preferred.
-
getEffect
public abstract Effect getEffect()
Requests the oldestEffectorakka.actor.testkit.typed.javadsl.Effects.noEffectsif no effects have taken place. The effect is consumed, subsequent calls won't will not include this effect.
-
childInbox
public abstract <U> TestInbox<U> childInbox(java.lang.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
public abstract <U> TestInbox<U> childInbox(ActorRef<U> child)
Get the child inbox for the child with the given name, or fail if there is no child with the given name spawned
-
childTestKit
public abstract <U> BehaviorTestKit<U> childTestKit(ActorRef<U> child)
-
selfInbox
public abstract TestInbox<T> selfInbox()
The self inbox contains messages the behavior sent tocontext.self
-
getAllEffects
public abstract java.util.List<Effect> getAllEffects()
Requests all the effects. The effects are consumed, subsequent calls will only see new effects.
-
hasEffects
public abstract boolean hasEffects()
Returns if there have been any effects.
-
expectEffect
public abstract void expectEffect(Effect expectedEffect)
Asserts that the oldest effect is the expectedEffect. Removing it from further assertions.
-
expectEffectClass
public abstract <U extends Effect> U expectEffectClass(java.lang.Class<U> effectClass)
Asserts that the oldest effect is an instance of of class T. Consumes and returns the concrete effect for further direct assertions.
-
currentBehavior
public abstract Behavior<T> currentBehavior()
The current behavior, can change any timerunis called
-
returnedBehavior
public abstract Behavior<T> returnedBehavior()
Returns the current behavior as it was returned from processing the previous message. For example ifBehaviors.unhandledis returned it will be kept here, but not incurrentBehavior().
-
isAlive
public abstract boolean isAlive()
Is the current behavior alive or stopped
-
run
public abstract void run(T message)
Send the message to the behavior and record anyEffects
-
runOne
public abstract void runOne()
Send the first message in the selfInbox to the behavior and run it, recordingEffects.
-
signal
public abstract void signal(Signal signal)
Send the signal to the beheavior and record anyEffects
-
getAllLogEntries
public abstract java.util.List<CapturedLogEvent> getAllLogEntries()
Returns all theCapturedLogEventissued by this behavior(s)
-
clearLog
public abstract void clearLog()
Clear the log entries
-
receptionistInbox
public abstract TestInbox<Receptionist.Command> receptionistInbox()
The receptionist inbox contains messages sent tosystem.receptionist
-
-