Class TestProbeImpl<M>
- java.lang.Object
-
- akka.actor.testkit.typed.javadsl.TestProbe<M>
-
- akka.actor.testkit.typed.internal.TestProbeImpl<M>
-
-
Constructor Summary
Constructors Constructor Description TestProbeImpl(java.lang.String name, ActorSystem<?> system)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TestProbe<M>
asJava()
INTERNAL API<A> A
awaitAssert(java.time.Duration max, java.time.Duration interval, java.util.function.Supplier<A> supplier)
Evaluate the given assert everyinterval
until it does not throw an exception and return the result.<A> A
awaitAssert(java.time.Duration max, java.util.function.Supplier<A> supplier)
Evaluate the given assert every 100 milliseconds until it does not throw an exception and return the result.<A> A
awaitAssert(java.util.function.Supplier<A> supplier)
Evaluate the given assert every 100 milliseconds until it does not throw an exception and return the result.<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.<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.<A> A
awaitAssert(scala.Function0<A> a, scala.concurrent.duration.FiniteDuration max, scala.concurrent.duration.FiniteDuration interval)
Evaluate the given assert everyinterval
until it does not throw an exception and return the result.<T extends M>
TexpectMessage(java.time.Duration 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(java.time.Duration max, 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, 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>
TexpectMessageClass(java.lang.Class<T> clazz)
Same asexpectMessageType(clazz, remainingOrDefault)
,but using the default timeout as deadline.<T extends M>
TexpectMessageClass(java.lang.Class<T> clazz, java.time.Duration max)
Wait for a message of type M and return it when it arrives, or fail if themax
timeout is hit.<T extends M>
TexpectMessageType(scala.concurrent.duration.FiniteDuration max, scala.reflect.ClassTag<T> t)
Expect a message of type T to arrive withinmax
or fail.<T extends M>
TexpectMessageType(scala.reflect.ClassTag<T> t)
Same asexpectMessageType[T](remainingOrDefault)
, but using the default timeout as deadline.void
expectNoMessage()
Assert that no message is received.void
expectNoMessage(java.time.Duration max)
Assert that no message is received for the specified time.void
expectNoMessage(scala.concurrent.duration.FiniteDuration max)
Assert that no message is received for the specified time.<U> void
expectTerminated(ActorRef<U> actorRef)
Expect the given actor to be stopped or stop within the default timeout.<U> void
expectTerminated(ActorRef<U> actorRef, java.time.Duration max)
Expect the given actor to be stopped or stop within the given timeout or throw anAssertionError
.<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
.java.util.List<M>
fishForMessage(java.time.Duration max, java.lang.String hint, java.util.function.Function<M,FishingOutcome> fisher)
Same as the otherfishForMessage
but includes the provided hint in all error messagesjava.util.List<M>
fishForMessage(java.time.Duration max, java.util.function.Function<M,FishingOutcome> fisher)
Java API: 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, 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 otherfishForMessage
but with no hintjava.time.Duration
getRemaining()
Obtain time remaining for execution of the innermost enclosingwithin
block or throw anAssertionError
if nowithin
block surrounds this call.java.time.Duration
getRemainingOr(java.time.Duration duration)
Obtain time remaining for execution of the innermost enclosingwithin
block or missing that it returns the given duration.java.time.Duration
getRemainingOrDefault()
Obtain time remaining for execution of the innermost enclosingwithin
block or missing that it returns the properly dilated default for this case from settings (key "akka.actor.testkit.typed.single-expect-default").M
receiveMessage()
Receive one message of typeM
within the default timeout as deadline.M
receiveMessage(java.time.Duration max)
Receive one message of typeM
.M
receiveMessage(scala.concurrent.duration.FiniteDuration max)
Receive one message of typeM
.M
receiveMessage_internal(scala.concurrent.duration.FiniteDuration max)
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)
Receiven
messages in a row before the given deadline.java.util.List<M>
receiveSeveralMessages(int n)
Same asreceiveSeveralMessages(n, remaining)
but using the default timeout as deadline.java.util.List<M>
receiveSeveralMessages(int n, java.time.Duration max)
Receiven
messages in a row before the given deadline.ActorRef<M>
ref()
ActorRef for this TestProbescala.concurrent.duration.FiniteDuration
remaining()
Obtain time remaining for execution of the innermost enclosingwithin
block or throw anAssertionError
if nowithin
block surrounds this call.scala.concurrent.duration.FiniteDuration
remainingOr(scala.concurrent.duration.FiniteDuration duration)
Obtain time remaining for execution of the innermost enclosingwithin
block or missing that it returns the given duration.scala.concurrent.duration.FiniteDuration
remainingOrDefault()
Obtain time remaining for execution of the innermost enclosingwithin
block or missing that it returns the properly dilated default for this case from settings (key "akka.actor.testkit.typed.single-expect-default").protected TestKitSettings
settings()
void
stop()
Stops theTestProbe.getRef
, which is useful when testing watch and termination.<T> T
within(java.time.Duration min, java.time.Duration max, java.util.function.Supplier<T> f)
Execute code block while bounding its execution time betweenmin
andmax
.<T> T
within(java.time.Duration max, java.util.function.Supplier<T> f)
Same as callingwithin(0 seconds, max)(f)
.<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 betweenmin
andmax
.<T> T
within(scala.concurrent.duration.FiniteDuration max, scala.Function0<T> f)
Same as callingwithin(0 seconds, max)(f)
.
-
-
-
Constructor Detail
-
TestProbeImpl
public TestProbeImpl(java.lang.String name, ActorSystem<?> system)
-
-
Method Detail
-
settings
protected TestKitSettings settings()
-
remainingOrDefault
public scala.concurrent.duration.FiniteDuration remainingOrDefault()
Description copied from interface:TestProbe
Obtain time remaining for execution of the innermost enclosingwithin
block or missing that it returns the properly dilated default for this case from settings (key "akka.actor.testkit.typed.single-expect-default").- Specified by:
remainingOrDefault
in interfaceTestProbe<M>
-
getRemainingOrDefault
public java.time.Duration getRemainingOrDefault()
Description copied from class:TestProbe
Obtain time remaining for execution of the innermost enclosingwithin
block or missing that it returns the properly dilated default for this case from settings (key "akka.actor.testkit.typed.single-expect-default").- Specified by:
getRemainingOrDefault
in classTestProbe<M>
-
remaining
public scala.concurrent.duration.FiniteDuration remaining()
Description copied from interface:TestProbe
Obtain time remaining for execution of the innermost enclosingwithin
block or throw anAssertionError
if nowithin
block surrounds this call.
-
getRemaining
public java.time.Duration getRemaining()
Description copied from class:TestProbe
Obtain time remaining for execution of the innermost enclosingwithin
block or throw anAssertionError
if nowithin
block surrounds this call.- Specified by:
getRemaining
in classTestProbe<M>
-
remainingOr
public scala.concurrent.duration.FiniteDuration remainingOr(scala.concurrent.duration.FiniteDuration duration)
Description copied from interface:TestProbe
Obtain time remaining for execution of the innermost enclosingwithin
block or missing that it returns the given duration.- Specified by:
remainingOr
in interfaceTestProbe<M>
-
getRemainingOr
public java.time.Duration getRemainingOr(java.time.Duration duration)
Description copied from class:TestProbe
Obtain time remaining for execution of the innermost enclosingwithin
block or missing that it returns the given duration.- Specified by:
getRemainingOr
in classTestProbe<M>
-
within
public <T> T within(scala.concurrent.duration.FiniteDuration min, scala.concurrent.duration.FiniteDuration max, scala.Function0<T> f)
Description copied from interface:TestProbe
Execute code block while bounding its execution time betweenmin
andmax
.within
blocks 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 enclosingwithin
block.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
public <T> T within(scala.concurrent.duration.FiniteDuration max, scala.Function0<T> f)
Description copied from interface:TestProbe
Same as callingwithin(0 seconds, max)(f)
.
-
within
public <T> T within(java.time.Duration min, java.time.Duration max, java.util.function.Supplier<T> f)
Description copied from class:TestProbe
Execute code block while bounding its execution time betweenmin
andmax
.within
blocks 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 enclosingwithin
block.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
public <T> T within(java.time.Duration max, java.util.function.Supplier<T> f)
Description copied from class:TestProbe
Same as callingwithin(0 seconds, max)(f)
.
-
expectMessage
public <T extends M> T expectMessage(T obj)
Description copied from class:TestProbe
Same asexpectMessage(remainingOrDefault, obj)
, but using the default timeout as deadline.- Specified by:
expectMessage
in interfaceTestProbe<M>
- Specified by:
expectMessage
in classTestProbe<M>
-
expectMessage
public <T extends M> T expectMessage(scala.concurrent.duration.FiniteDuration max, T obj)
Description copied from interface:TestProbe
Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with anAssertionError
being thrown in case of timeout.- Specified by:
expectMessage
in interfaceTestProbe<M>
- Returns:
- the received object
-
expectMessage
public <T extends M> T expectMessage(java.time.Duration max, T obj)
Description copied from class:TestProbe
Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with anAssertionError
being thrown in case of timeout.- Specified by:
expectMessage
in classTestProbe<M>
- Returns:
- the received object
-
expectMessage
public <T extends M> T expectMessage(scala.concurrent.duration.FiniteDuration max, java.lang.String hint, T obj)
Description copied from interface:TestProbe
Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with anAssertionError
being thrown in case of timeout.- Specified by:
expectMessage
in interfaceTestProbe<M>
- Returns:
- the received object
-
expectMessage
public <T extends M> T expectMessage(java.time.Duration max, java.lang.String hint, T obj)
Description copied from class:TestProbe
Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with anAssertionError
being thrown in case of timeout.- Specified by:
expectMessage
in classTestProbe<M>
- Returns:
- the received object
-
receiveMessage
public M receiveMessage()
Description copied from class:TestProbe
Receive one message of typeM
within the default timeout as deadline.- Specified by:
receiveMessage
in interfaceTestProbe<M>
- Specified by:
receiveMessage
in classTestProbe<M>
-
receiveMessage
public M receiveMessage(java.time.Duration max)
Description copied from class:TestProbe
Receive one message of typeM
. Wait time is bounded by themax
duration, with anAssertionError
raised in case of timeout.- Specified by:
receiveMessage
in classTestProbe<M>
-
receiveMessage
public M receiveMessage(scala.concurrent.duration.FiniteDuration max)
Description copied from interface:TestProbe
Receive one message of typeM
. Wait time is bounded by themax
duration, with anAssertionError
raised in case of timeout.- Specified by:
receiveMessage
in interfaceTestProbe<M>
-
receiveMessage_internal
public M receiveMessage_internal(scala.concurrent.duration.FiniteDuration max)
-
expectNoMessage
public void expectNoMessage(scala.concurrent.duration.FiniteDuration max)
Description copied from interface:TestProbe
Assert that no message is received for the specified time. Supplied value is not dilated.- Specified by:
expectNoMessage
in interfaceTestProbe<M>
-
expectNoMessage
public void expectNoMessage(java.time.Duration max)
Description copied from class:TestProbe
Assert that no message is received for the specified time. Supplied value is not dilated.- Specified by:
expectNoMessage
in classTestProbe<M>
-
expectNoMessage
public void expectNoMessage()
Description copied from class:TestProbe
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".- Specified by:
expectNoMessage
in interfaceTestProbe<M>
- Specified by:
expectNoMessage
in classTestProbe<M>
-
expectMessageType
public <T extends M> T expectMessageType(scala.reflect.ClassTag<T> t)
Description copied from interface:TestProbe
Same asexpectMessageType[T](remainingOrDefault)
, but using the default timeout as deadline.- Specified by:
expectMessageType
in interfaceTestProbe<M>
-
expectMessageType
public <T extends M> T expectMessageType(scala.concurrent.duration.FiniteDuration max, scala.reflect.ClassTag<T> t)
Description copied from interface:TestProbe
Expect a message of type T to arrive withinmax
or fail.max
is dilated.- Specified by:
expectMessageType
in interfaceTestProbe<M>
-
expectMessageClass
public <T extends M> T expectMessageClass(java.lang.Class<T> clazz)
Description copied from class:TestProbe
Same asexpectMessageType(clazz, remainingOrDefault)
,but using the default timeout as deadline.- Specified by:
expectMessageClass
in classTestProbe<M>
-
expectMessageClass
public <T extends M> T expectMessageClass(java.lang.Class<T> clazz, java.time.Duration max)
Description copied from class:TestProbe
Wait for a message of type M and return it when it arrives, or fail if themax
timeout is hit.Note that the timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".
- Specified by:
expectMessageClass
in classTestProbe<M>
-
receiveMessages
public scala.collection.immutable.Seq<M> receiveMessages(int n)
Description copied from interface:TestProbe
Same asreceiveMessages(n, remaining)
but using the default timeout as deadline.- Specified by:
receiveMessages
in interfaceTestProbe<M>
-
receiveMessages
public scala.collection.immutable.Seq<M> receiveMessages(int n, scala.concurrent.duration.FiniteDuration max)
Description copied from interface:TestProbe
Receiven
messages in a row before the given deadline.Note that the timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".
- Specified by:
receiveMessages
in interfaceTestProbe<M>
-
receiveSeveralMessages
public java.util.List<M> receiveSeveralMessages(int n)
Description copied from class:TestProbe
Same asreceiveSeveralMessages(n, remaining)
but using the default timeout as deadline.- Specified by:
receiveSeveralMessages
in classTestProbe<M>
-
receiveSeveralMessages
public java.util.List<M> receiveSeveralMessages(int n, java.time.Duration max)
Description copied from class:TestProbe
Receiven
messages in a row before the given deadline.Note that the timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".
- Specified by:
receiveSeveralMessages
in classTestProbe<M>
-
fishForMessage
public scala.collection.immutable.Seq<M> fishForMessage(scala.concurrent.duration.FiniteDuration max, java.lang.String hint, scala.Function1<M,FishingOutcome> fisher)
Description copied from interface:TestProbe
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
fisher
function 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).- Specified by:
fishForMessage
in interfaceTestProbe<M>
- Parameters:
max
- Max total time without the fisher function returningCompleteFishing
before failing. The timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".- Returns:
- The messages accepted in the order they arrived
-
fishForMessage
public scala.collection.immutable.Seq<M> fishForMessage(scala.concurrent.duration.FiniteDuration max, scala.Function1<M,FishingOutcome> fisher)
Description copied from interface:TestProbe
Same as the otherfishForMessage
but with no hint- Specified by:
fishForMessage
in interfaceTestProbe<M>
-
fishForMessage
public java.util.List<M> fishForMessage(java.time.Duration max, java.util.function.Function<M,FishingOutcome> fisher)
Description copied from class:TestProbe
Java API: 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.complete
- successfully complete and return the message *FishingOutcomes.fail
- fail the test with a custom messageAdditionally failures includes the list of messages consumed. If a message of type
M
but not of typeT
is received this will also fail the test, additionally if thefisher
function 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).- Specified by:
fishForMessage
in classTestProbe<M>
- Parameters:
max
- Max total time without the fisher function returningCompleteFishing
before failing. The timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".- Returns:
- The messages accepted in the order they arrived
-
fishForMessage
public java.util.List<M> fishForMessage(java.time.Duration max, java.lang.String hint, java.util.function.Function<M,FishingOutcome> fisher)
Description copied from class:TestProbe
Same as the otherfishForMessage
but includes the provided hint in all error messages- Specified by:
fishForMessage
in classTestProbe<M>
-
expectTerminated
public <U> void expectTerminated(ActorRef<U> actorRef, scala.concurrent.duration.FiniteDuration max)
Description copied from interface:TestProbe
Expect the given actor to be stopped or stop within the given timeout or throw anAssertionError
.- Specified by:
expectTerminated
in interfaceTestProbe<M>
-
expectTerminated
public <U> void expectTerminated(ActorRef<U> actorRef)
Description copied from class:TestProbe
Expect the given actor to be stopped or stop within the default timeout.- Specified by:
expectTerminated
in interfaceTestProbe<M>
- Specified by:
expectTerminated
in classTestProbe<M>
-
expectTerminated
public <U> void expectTerminated(ActorRef<U> actorRef, java.time.Duration max)
Description copied from class:TestProbe
Expect the given actor to be stopped or stop within the given timeout or throw anAssertionError
.Note that the timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".
- Specified by:
expectTerminated
in classTestProbe<M>
-
awaitAssert
public <A> A awaitAssert(scala.Function0<A> a, scala.concurrent.duration.FiniteDuration max, scala.concurrent.duration.FiniteDuration interval)
Description copied from interface:TestProbe
Evaluate the given assert everyinterval
until it does not throw an exception and return the result.If the
max
timeout expires the last exception is thrown.Note that the timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".
- Specified by:
awaitAssert
in interfaceTestProbe<M>
-
awaitAssert
public <A> A awaitAssert(scala.Function0<A> a, scala.concurrent.duration.FiniteDuration max)
Description copied from interface:TestProbe
Evaluate the given assert every 100 ms until it does not throw an exception and return the result.If the
max
timeout expires the last exception is thrown.- Specified by:
awaitAssert
in interfaceTestProbe<M>
-
awaitAssert
public <A> A awaitAssert(scala.Function0<A> a)
Description copied from interface:TestProbe
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.
- Specified by:
awaitAssert
in interfaceTestProbe<M>
-
awaitAssert
public <A> A awaitAssert(java.time.Duration max, java.time.Duration interval, java.util.function.Supplier<A> supplier)
Description copied from class:TestProbe
Evaluate the given assert everyinterval
until it does not throw an exception and return the result.If the
max
timeout expires the last exception is thrown.Note that the timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".
- Specified by:
awaitAssert
in classTestProbe<M>
-
awaitAssert
public <A> A awaitAssert(java.time.Duration max, java.util.function.Supplier<A> supplier)
Description copied from class:TestProbe
Evaluate the given assert every 100 milliseconds until it does not throw an exception and return the result.If the
max
timeout expires the last exception is thrown.Note that the timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".
- Specified by:
awaitAssert
in classTestProbe<M>
-
awaitAssert
public <A> A awaitAssert(java.util.function.Supplier<A> supplier)
Description copied from class:TestProbe
Evaluate the given assert every 100 milliseconds until it does not throw an exception and return the result. A max time is taken it from the innermost enclosingwithin
block.- Specified by:
awaitAssert
in classTestProbe<M>
-
stop
public void stop()
Description copied from class:TestProbe
Stops theTestProbe.getRef
, which is useful when testing watch and termination.
-
-