Interface TestProbe<M>
-
- All Superinterfaces:
RecipientRef<M>
public interface TestProbe<M> extends RecipientRef<M>
Create instances through the factories in theTestProbecompanion.A test probe is essentially a queryable mailbox which can be used in place of an actor and the received messages can then be asserted
Not for user extension
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface akka.actor.typed.RecipientRef
RecipientRef.RecipientRefOps<T>, RecipientRef.RecipientRefOps$
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description TestProbe<M>asJava()INTERNAL API<A> AawaitAssert(scala.Function0<A> a)Evaluate the given assert every 100 ms until it does not throw an exception and return the result.<A> AawaitAssert(scala.Function0<A> a, scala.concurrent.duration.FiniteDuration max)Evaluate the given assert every 100 ms until it does not throw an exception and return the result.<A> AawaitAssert(scala.Function0<A> a, scala.concurrent.duration.FiniteDuration max, scala.concurrent.duration.FiniteDuration interval)Evaluate the given assert everyintervaluntil it does not throw an exception and return the result.<T extends M>
TexpectMessage(scala.concurrent.duration.FiniteDuration max, java.lang.String hint, T obj)Receive one message from the test actor and assert that it equals the given object.<T extends M>
TexpectMessage(scala.concurrent.duration.FiniteDuration max, T obj)Receive one message from the test actor and assert that it equals the given object.<T extends M>
TexpectMessage(T obj)Same asexpectMessage(remainingOrDefault, obj), but using the default timeout as deadline.<T extends M>
TexpectMessageType(scala.concurrent.duration.FiniteDuration max, scala.reflect.ClassTag<T> t)Expect a message of type T to arrive withinmaxor fail.<T extends M>
TexpectMessageType(scala.reflect.ClassTag<T> t)Same asexpectMessageType[T](remainingOrDefault), but using the default timeout as deadline.voidexpectNoMessage()Assert that no message is received.voidexpectNoMessage(scala.concurrent.duration.FiniteDuration max)Assert that no message is received for the specified time.<U> voidexpectTerminated(ActorRef<U> actorRef)Expect the given actor to be stopped or stop within the default timeout.<U> voidexpectTerminated(ActorRef<U> actorRef, scala.concurrent.duration.FiniteDuration max)Expect the given actor to be stopped or stop within the given timeout or throw anAssertionError.scala.collection.immutable.Seq<M>fishForMessage(scala.concurrent.duration.FiniteDuration max, java.lang.String hint, scala.Function1<M,FishingOutcome> fisher)Allows for flexible matching of multiple messages within a timeout, the fisher function is fed each incoming message, and returns one of the following effects to decide on what happens next:scala.collection.immutable.Seq<M>fishForMessage(scala.concurrent.duration.FiniteDuration max, scala.Function1<M,FishingOutcome> fisher)Same as the otherfishForMessagebut with no hintscala.collection.immutable.Seq<M>fishForMessagePF(scala.concurrent.duration.FiniteDuration max, java.lang.String hint, scala.PartialFunction<M,FishingOutcome> fisher)Same asfishForMessagebut accepting a partial function and failing for non-matchesscala.collection.immutable.Seq<M>fishForMessagePF(scala.concurrent.duration.FiniteDuration max, scala.PartialFunction<M,FishingOutcome> fisher)Same asfishForMessagebut with no hint, accepting a partial function and failing for non-matchesMreceiveMessage()Receive one message of typeMwithin the default timeout as deadline.MreceiveMessage(scala.concurrent.duration.FiniteDuration max)Receive one message of typeM.scala.collection.immutable.Seq<M>receiveMessages(int n)Same asreceiveMessages(n, remaining)but using the default timeout as deadline.scala.collection.immutable.Seq<M>receiveMessages(int n, scala.concurrent.duration.FiniteDuration max)Receivenmessages in a row before the given deadline.ActorRef<M>ref()ActorRef for this TestProbescala.concurrent.duration.FiniteDurationremaining()Obtain time remaining for execution of the innermost enclosingwithinblock or throw anAssertionErrorif nowithinblock surrounds this call.scala.concurrent.duration.FiniteDurationremainingOr(scala.concurrent.duration.FiniteDuration duration)Obtain time remaining for execution of the innermost enclosingwithinblock or missing that it returns the given duration.scala.concurrent.duration.FiniteDurationremainingOrDefault()Obtain time remaining for execution of the innermost enclosingwithinblock or missing that it returns the properly dilated default for this case from settings (key "akka.actor.testkit.typed.single-expect-default").TestKitSettingssettings()voidstop()Stops theTestProbe.ref, which is useful when testing watch and termination.<T> Twithin(scala.concurrent.duration.FiniteDuration min, scala.concurrent.duration.FiniteDuration max, scala.Function0<T> f)Execute code block while bounding its execution time betweenminandmax.<T> Twithin(scala.concurrent.duration.FiniteDuration max, scala.Function0<T> f)Same as callingwithin(0 seconds, max)(f).-
Methods inherited from interface akka.actor.typed.RecipientRef
tell
-
-
-
-
Method Detail
-
settings
TestKitSettings settings()
-
remainingOrDefault
scala.concurrent.duration.FiniteDuration remainingOrDefault()
Obtain time remaining for execution of the innermost enclosingwithinblock or missing that it returns the properly dilated default for this case from settings (key "akka.actor.testkit.typed.single-expect-default").
-
remaining
scala.concurrent.duration.FiniteDuration remaining()
Obtain time remaining for execution of the innermost enclosingwithinblock or throw anAssertionErrorif nowithinblock surrounds this call.
-
remainingOr
scala.concurrent.duration.FiniteDuration remainingOr(scala.concurrent.duration.FiniteDuration duration)
Obtain time remaining for execution of the innermost enclosingwithinblock or missing that it returns the given duration.
-
within
<T> T within(scala.concurrent.duration.FiniteDuration min, scala.concurrent.duration.FiniteDuration max, scala.Function0<T> f)Execute code block while bounding its execution time betweenminandmax.withinblocks may be nested. All methods in this trait which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosingwithinblock.Note that the max timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor", while the min Duration is not.
val ret = within(50 millis) { test ! Ping expectMessageType[Pong] }
-
within
<T> T within(scala.concurrent.duration.FiniteDuration max, scala.Function0<T> f)Same as callingwithin(0 seconds, max)(f).
-
expectMessage
<T extends M> T expectMessage(T obj)
Same asexpectMessage(remainingOrDefault, obj), but using the default timeout as deadline.
-
expectMessage
<T extends M> T expectMessage(scala.concurrent.duration.FiniteDuration max, T obj)
Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with anAssertionErrorbeing thrown in case of timeout.- Returns:
- the received object
-
expectMessage
<T extends M> T expectMessage(scala.concurrent.duration.FiniteDuration max, java.lang.String hint, T obj)
Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with anAssertionErrorbeing thrown in case of timeout.- Returns:
- the received object
-
expectNoMessage
void expectNoMessage(scala.concurrent.duration.FiniteDuration max)
Assert that no message is received for the specified time. Supplied value is not dilated.
-
expectNoMessage
void expectNoMessage()
Assert that no message is received. Waits for the default period configured asakka.actor.testkit.typed.expect-no-message-default. That timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".
-
expectMessageType
<T extends M> T expectMessageType(scala.reflect.ClassTag<T> t)
Same asexpectMessageType[T](remainingOrDefault), but using the default timeout as deadline.
-
expectMessageType
<T extends M> T expectMessageType(scala.concurrent.duration.FiniteDuration max, scala.reflect.ClassTag<T> t)
Expect a message of type T to arrive withinmaxor fail.maxis dilated.
-
receiveMessage
M receiveMessage()
Receive one message of typeMwithin the default timeout as deadline.
-
receiveMessage
M receiveMessage(scala.concurrent.duration.FiniteDuration max)
Receive one message of typeM. Wait time is bounded by themaxduration, with anAssertionErrorraised in case of timeout.
-
receiveMessages
scala.collection.immutable.Seq<M> receiveMessages(int n)
Same asreceiveMessages(n, remaining)but using the default timeout as deadline.
-
receiveMessages
scala.collection.immutable.Seq<M> receiveMessages(int n, scala.concurrent.duration.FiniteDuration max)
Receivenmessages in a row before the given deadline.Note that the timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".
-
fishForMessage
scala.collection.immutable.Seq<M> fishForMessage(scala.concurrent.duration.FiniteDuration max, java.lang.String hint, scala.Function1<M,FishingOutcome> fisher)
Allows for flexible matching of multiple messages within a timeout, the fisher function is fed each incoming message, and returns one of the following effects to decide on what happens next:* {@link FishingOutcomes.continue} - continue with the next message given that the timeout has not been reached *
FishingOutcomes.continueAndIgnore- continue and do not save the message in the returned list *FishingOutcomes.complete- successfully complete and return the message *FishingOutcomes.fail- fail the test with a custom messageAdditionally failures includes the list of messages consumed. If the
fisherfunction throws a match error the error is decorated with some fishing details and the test is failed (making it convenient to use this method with a partial function).- Parameters:
max- Max total time without the fisher function returningCompleteFishingbefore failing. The timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".- Returns:
- The messages accepted in the order they arrived
-
fishForMessagePF
scala.collection.immutable.Seq<M> fishForMessagePF(scala.concurrent.duration.FiniteDuration max, java.lang.String hint, scala.PartialFunction<M,FishingOutcome> fisher)
Same asfishForMessagebut accepting a partial function and failing for non-matches
-
fishForMessage
scala.collection.immutable.Seq<M> fishForMessage(scala.concurrent.duration.FiniteDuration max, scala.Function1<M,FishingOutcome> fisher)
Same as the otherfishForMessagebut with no hint
-
fishForMessagePF
scala.collection.immutable.Seq<M> fishForMessagePF(scala.concurrent.duration.FiniteDuration max, scala.PartialFunction<M,FishingOutcome> fisher)
Same asfishForMessagebut with no hint, accepting a partial function and failing for non-matches
-
expectTerminated
<U> void expectTerminated(ActorRef<U> actorRef, scala.concurrent.duration.FiniteDuration max)
Expect the given actor to be stopped or stop within the given timeout or throw anAssertionError.
-
expectTerminated
<U> void expectTerminated(ActorRef<U> actorRef)
Expect the given actor to be stopped or stop within the default timeout.
-
awaitAssert
<A> A awaitAssert(scala.Function0<A> a, scala.concurrent.duration.FiniteDuration max, scala.concurrent.duration.FiniteDuration interval)Evaluate the given assert everyintervaluntil it does not throw an exception and return the result.If the
maxtimeout expires the last exception is thrown.Note that the timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".
-
awaitAssert
<A> A awaitAssert(scala.Function0<A> a, scala.concurrent.duration.FiniteDuration max)Evaluate the given assert every 100 ms until it does not throw an exception and return the result.If the
maxtimeout expires the last exception is thrown.
-
awaitAssert
<A> A awaitAssert(scala.Function0<A> a)
Evaluate the given assert every 100 ms until it does not throw an exception and return the result.If the default timeout expires the last exception is thrown.
-
stop
void stop()
Stops theTestProbe.ref, which is useful when testing watch and termination.
-
-