|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface TestKitBase
Implementation trait behind the TestKit
class: you may use
this if inheriting from a concrete class is not possible.
Use of the trait is discouraged because of potential issues with binary backwards compatibility in the future, use at own risk.
This trait requires the concrete class mixing it in to provide an
ActorSystem
which is available before this traits’s
constructor is run. The recommended way is this:
class MyTest extends TestKitBase {
implicit lazy val system = ActorSystem() // may add arguments here
...
}
Method Summary | ||
---|---|---|
void |
awaitAssert(scala.Function0<java.lang.Object> a,
scala.concurrent.duration.Duration max,
scala.concurrent.duration.Duration interval)
Await until the given assert does not throw an exception or the timeout expires, whichever comes first. |
|
void |
awaitCond(scala.Function0<java.lang.Object> p,
scala.concurrent.duration.Duration max,
scala.concurrent.duration.Duration interval,
java.lang.String message)
Await until the given condition evaluates to true or the timeout
expires, whichever comes first. |
|
void |
checkMissingAndUnexpected(scala.collection.Seq<java.lang.Object> missing,
scala.collection.Seq<java.lang.Object> unexpected,
java.lang.String missingMessage,
java.lang.String unexpectedMessage)
|
|
scala.concurrent.duration.Duration |
end()
|
|
|
expectMsg_internal(scala.concurrent.duration.Duration max,
T obj,
scala.Option<java.lang.String> hint)
|
|
|
expectMsg(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. |
|
|
expectMsg(scala.concurrent.duration.FiniteDuration max,
T obj)
Receive one message from the test actor and assert that it equals the given object. |
|
|
expectMsg(T obj)
Same as expectMsg(remaining, obj) , but correctly treating the timeFactor. |
|
|
expectMsgAllClassOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<java.lang.Class<? extends T>> obj)
Receive a number of messages from the test actor matching the given number of classes and assert that for each given class one is received which is of that class (equality, not conformance). |
|
|
expectMsgAllClassOf(scala.collection.Seq<java.lang.Class<? extends T>> obj)
Same as expectMsgAllClassOf(remaining, obj...) , but correctly treating the timeFactor. |
|
|
expectMsgAllConformingOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<java.lang.Class<? extends T>> obj)
Receive a number of messages from the test actor matching the given number of classes and assert that for each given class one is received which conforms to that class (and vice versa). |
|
|
expectMsgAllConformingOf(scala.collection.Seq<java.lang.Class<? extends T>> obj)
Same as expectMsgAllConformingOf(remaining, obj...) , but correctly treating the timeFactor. |
|
|
expectMsgAllOf_internal(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<T> obj)
|
|
|
expectMsgAllOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<T> obj)
Receive a number of messages from the test actor matching the given number of objects and assert that for each given object one is received which equals it and vice versa. |
|
|
expectMsgAllOf(scala.collection.Seq<T> obj)
Same as expectMsgAllOf(remaining, obj...) , but correctly treating the timeFactor. |
|
|
expectMsgAnyClassOf_internal(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<java.lang.Class<? extends C>> obj)
|
|
|
expectMsgAnyClassOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<java.lang.Class<? extends C>> obj)
Receive one message from the test actor and assert that it conforms to one of the given classes. |
|
|
expectMsgAnyClassOf(scala.collection.Seq<java.lang.Class<? extends C>> obj)
Same as expectMsgAnyClassOf(remaining, obj...) , but correctly treating the timeFactor. |
|
|
expectMsgAnyOf_internal(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<T> obj)
|
|
|
expectMsgAnyOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<T> obj)
Receive one message from the test actor and assert that it equals one of the given objects. |
|
|
expectMsgAnyOf(scala.collection.Seq<T> obj)
Same as expectMsgAnyOf(remaining, obj...) , but correctly treating the timeFactor. |
|
|
expectMsgClass_internal(scala.concurrent.duration.FiniteDuration max,
java.lang.Class<C> c)
|
|
|
expectMsgClass(java.lang.Class<C> c)
Same as expectMsgClass(remaining, c) , but correctly treating the timeFactor. |
|
|
expectMsgClass(scala.concurrent.duration.FiniteDuration max,
java.lang.Class<C> c)
Receive one message from the test actor and assert that it conforms to the given class. |
|
|
expectMsgPF(scala.concurrent.duration.Duration max,
java.lang.String hint,
scala.PartialFunction<java.lang.Object,T> f)
Receive one message from the test actor and assert that the given partial function accepts it. |
|
|
expectMsgType(scala.reflect.ClassTag<T> t)
Same as expectMsgType[T](remaining) , but correctly treating the timeFactor. |
|
|
expectMsgType(scala.concurrent.duration.FiniteDuration max,
scala.reflect.ClassTag<T> t)
Receive one message from the test actor and assert that it conforms to the given type (after erasure). |
|
void |
expectNoMsg_internal(scala.concurrent.duration.FiniteDuration max)
|
|
void |
expectNoMsg()
Same as expectNoMsg(remaining) , but correctly treating the timeFactor. |
|
void |
expectNoMsg(scala.concurrent.duration.FiniteDuration max)
Assert that no message is received for the specified time. |
|
Terminated |
expectTerminated(ActorRef target,
scala.concurrent.duration.Duration max)
Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef. |
|
java.lang.Object |
fishForMessage(scala.concurrent.duration.Duration max,
java.lang.String hint,
scala.PartialFunction<java.lang.Object,java.lang.Object> f)
Hybrid of expectMsgPF and receiveWhile: receive messages while the partial function matches and returns false. |
|
java.lang.String |
format(java.util.concurrent.TimeUnit u,
scala.concurrent.duration.Duration d)
|
|
void |
ignoreMsg(scala.PartialFunction<java.lang.Object,java.lang.Object> f)
Ignore all messages in the test actor for which the given partial function returns true. |
|
void |
ignoreNoMsg()
Stop ignoring messages in the test actor. |
|
|
internalExpectMsgAllClassOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<java.lang.Class<? extends T>> obj)
|
|
|
internalExpectMsgAllConformingOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<java.lang.Class<? extends T>> obj)
|
|
TestActor.Message |
lastMessage()
|
|
ActorRef |
lastSender()
|
|
boolean |
lastWasNoMsg()
if last assertion was expectNoMsg, disable timing failure upon within() block end. |
|
boolean |
msgAvailable()
Query queue status. |
|
scala.concurrent.duration.FiniteDuration |
now()
Obtain current time ( System.nanoTime ) as Duration. |
|
java.util.concurrent.LinkedBlockingDeque<TestActor.Message> |
queue()
|
|
scala.collection.immutable.Seq<java.lang.Object> |
receiveN_internal(int n,
scala.concurrent.duration.Duration max)
|
|
scala.collection.immutable.Seq<java.lang.Object> |
receiveN(int n)
Same as receiveN(n, remaining) but correctly taking into account
Duration.timeFactor. |
|
scala.collection.immutable.Seq<java.lang.Object> |
receiveN(int n,
scala.concurrent.duration.FiniteDuration max)
Receive N messages in a row before the given deadline. |
|
java.lang.Object |
receiveOne(scala.concurrent.duration.Duration max)
Receive one message from the internal queue of the TestActor. |
|
|
receiveWhile(scala.concurrent.duration.Duration max,
scala.concurrent.duration.Duration idle,
int messages,
scala.PartialFunction<java.lang.Object,T> f)
Receive a series of messages until one does not match the given partial function or the idle timeout is met (disabled by default) or the overall maximum duration is elapsed. |
|
scala.concurrent.duration.FiniteDuration |
remaining()
Obtain time remaining for execution of the innermost enclosing within
block or missing that it returns the properly dilated default for this
case from settings (key "akka.test.single-expect-default"). |
|
scala.concurrent.duration.FiniteDuration |
remainingOr(scala.concurrent.duration.FiniteDuration duration)
Obtain time remaining for execution of the innermost enclosing within
block or missing that it returns the given duration. |
|
scala.concurrent.duration.FiniteDuration |
remainingOrDilated(scala.concurrent.duration.Duration max)
|
|
void |
setAutoPilot(TestActor.AutoPilot pilot)
Install an AutoPilot to drive the testActor: the AutoPilot will be run for each received message and can be used to send or forward messages, etc. |
|
void |
shutdown(ActorSystem actorSystem,
scala.concurrent.duration.Duration duration,
boolean verifySystemShutdown)
Shut down an actor system and wait for termination. |
|
ActorSystem |
system()
|
|
ActorRef |
testActor()
ActorRef of the test actor. |
|
TestKitSettings |
testKitSettings()
|
|
ActorRef |
unwatch(ActorRef ref)
Have the testActor stop watching someone (i.e. |
|
ActorRef |
watch(ActorRef ref)
Have the testActor watch someone (i.e. |
|
|
within(scala.concurrent.duration.FiniteDuration min,
scala.concurrent.duration.FiniteDuration max,
scala.Function0<T> f)
Execute code block while bounding its execution time between min and
max . |
|
|
within(scala.concurrent.duration.FiniteDuration max,
scala.Function0<T> f)
Same as calling within(0 seconds, max)(f) . |
Method Detail |
---|
ActorSystem system()
TestKitSettings testKitSettings()
java.util.concurrent.LinkedBlockingDeque<TestActor.Message> queue()
TestActor.Message lastMessage()
ActorRef lastSender()
ActorRef testActor()
scala.concurrent.duration.Duration end()
boolean lastWasNoMsg()
void ignoreMsg(scala.PartialFunction<java.lang.Object,java.lang.Object> f)
f
- (undocumented)void ignoreNoMsg()
ActorRef watch(ActorRef ref)
context.watch(...)
).
ref
- (undocumented)
ActorRef unwatch(ActorRef ref)
context.unwatch(...)
).
ref
- (undocumented)
void setAutoPilot(TestActor.AutoPilot pilot)
pilot
- (undocumented)scala.concurrent.duration.FiniteDuration now()
System.nanoTime
) as Duration.
scala.concurrent.duration.FiniteDuration remaining()
within
block or missing that it returns the properly dilated default for this
case from settings (key "akka.test.single-expect-default").
scala.concurrent.duration.FiniteDuration remainingOr(scala.concurrent.duration.FiniteDuration duration)
within
block or missing that it returns the given duration.
duration
- (undocumented)
scala.concurrent.duration.FiniteDuration remainingOrDilated(scala.concurrent.duration.Duration max)
boolean msgAvailable()
void awaitCond(scala.Function0<java.lang.Object> p, scala.concurrent.duration.Duration max, scala.concurrent.duration.Duration interval, java.lang.String message)
true
or the timeout
expires, whichever comes first.
If no timeout is given, take it from the innermost enclosing within
block.
Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "akka.test.timefactor".
p
- (undocumented)max
- (undocumented)interval
- (undocumented)message
- (undocumented)void awaitAssert(scala.Function0<java.lang.Object> a, scala.concurrent.duration.Duration max, scala.concurrent.duration.Duration interval)
If no timeout is given, take it from the innermost enclosing within
block.
Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "akka.test.timefactor".
a
- (undocumented)max
- (undocumented)interval
- (undocumented)<T> T within(scala.concurrent.duration.FiniteDuration min, scala.concurrent.duration.FiniteDuration max, scala.Function0<T> f)
min
and
max
. 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 enclosing within
block.
Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "akka.test.timefactor", while the min Duration is not.
val ret = within(50 millis) { test ! "ping" expectMsgClass(classOf[String]) }
min
- (undocumented)max
- (undocumented)f
- (undocumented)
<T> T within(scala.concurrent.duration.FiniteDuration max, scala.Function0<T> f)
within(0 seconds, max)(f)
.
max
- (undocumented)f
- (undocumented)
<T> T expectMsg(T obj)
expectMsg(remaining, obj)
, but correctly treating the timeFactor.
obj
- (undocumented)
<T> T expectMsg(scala.concurrent.duration.FiniteDuration max, T obj)
max
- (undocumented)obj
- (undocumented)
<T> T expectMsg(scala.concurrent.duration.FiniteDuration max, java.lang.String hint, T obj)
max
- (undocumented)hint
- (undocumented)obj
- (undocumented)
<T> T expectMsg_internal(scala.concurrent.duration.Duration max, T obj, scala.Option<java.lang.String> hint)
<T> T expectMsgPF(scala.concurrent.duration.Duration max, java.lang.String hint, scala.PartialFunction<java.lang.Object,T> f)
Use this variant to implement more complicated or conditional processing.
max
- (undocumented)hint
- (undocumented)f
- (undocumented)
Terminated expectTerminated(ActorRef target, scala.concurrent.duration.Duration max)
target
- (undocumented)max
- (undocumented)
java.lang.Object fishForMessage(scala.concurrent.duration.Duration max, java.lang.String hint, scala.PartialFunction<java.lang.Object,java.lang.Object> f)
max
- (undocumented)hint
- (undocumented)f
- (undocumented)
<T> T expectMsgType(scala.reflect.ClassTag<T> t)
expectMsgType[T](remaining)
, but correctly treating the timeFactor.
t
- (undocumented)
<T> T expectMsgType(scala.concurrent.duration.FiniteDuration max, scala.reflect.ClassTag<T> t)
max
- (undocumented)t
- (undocumented)
<C> C expectMsgClass(java.lang.Class<C> c)
expectMsgClass(remaining, c)
, but correctly treating the timeFactor.
c
- (undocumented)
<C> C expectMsgClass(scala.concurrent.duration.FiniteDuration max, java.lang.Class<C> c)
max
- (undocumented)c
- (undocumented)
<C> C expectMsgClass_internal(scala.concurrent.duration.FiniteDuration max, java.lang.Class<C> c)
<T> T expectMsgAnyOf(scala.collection.Seq<T> obj)
expectMsgAnyOf(remaining, obj...)
, but correctly treating the timeFactor.
obj
- (undocumented)
<T> T expectMsgAnyOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<T> obj)
max
- (undocumented)obj
- (undocumented)
<T> T expectMsgAnyOf_internal(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<T> obj)
<C> C expectMsgAnyClassOf(scala.collection.Seq<java.lang.Class<? extends C>> obj)
expectMsgAnyClassOf(remaining, obj...)
, but correctly treating the timeFactor.
obj
- (undocumented)
<C> C expectMsgAnyClassOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<java.lang.Class<? extends C>> obj)
max
- (undocumented)obj
- (undocumented)
<C> C expectMsgAnyClassOf_internal(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<java.lang.Class<? extends C>> obj)
<T> scala.collection.immutable.Seq<T> expectMsgAllOf(scala.collection.Seq<T> obj)
expectMsgAllOf(remaining, obj...)
, but correctly treating the timeFactor.
obj
- (undocumented)
<T> scala.collection.immutable.Seq<T> expectMsgAllOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<T> obj)
dispatcher ! SomeWork1() dispatcher ! SomeWork2() expectMsgAllOf(1 second, Result1(), Result2())
max
- (undocumented)obj
- (undocumented)
void checkMissingAndUnexpected(scala.collection.Seq<java.lang.Object> missing, scala.collection.Seq<java.lang.Object> unexpected, java.lang.String missingMessage, java.lang.String unexpectedMessage)
<T> scala.collection.immutable.Seq<T> expectMsgAllOf_internal(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<T> obj)
<T> scala.collection.immutable.Seq<T> expectMsgAllClassOf(scala.collection.Seq<java.lang.Class<? extends T>> obj)
expectMsgAllClassOf(remaining, obj...)
, but correctly treating the timeFactor.
obj
- (undocumented)
<T> scala.collection.immutable.Seq<T> expectMsgAllClassOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<java.lang.Class<? extends T>> obj)
max
- (undocumented)obj
- (undocumented)
<T> scala.collection.immutable.Seq<T> internalExpectMsgAllClassOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<java.lang.Class<? extends T>> obj)
<T> scala.collection.immutable.Seq<T> expectMsgAllConformingOf(scala.collection.Seq<java.lang.Class<? extends T>> obj)
expectMsgAllConformingOf(remaining, obj...)
, but correctly treating the timeFactor.
obj
- (undocumented)
<T> scala.collection.immutable.Seq<T> expectMsgAllConformingOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<java.lang.Class<? extends T>> obj)
Beware that one object may satisfy all given class constraints, which may be counter-intuitive.
max
- (undocumented)obj
- (undocumented)
<T> scala.collection.immutable.Seq<T> internalExpectMsgAllConformingOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<java.lang.Class<? extends T>> obj)
void expectNoMsg()
expectNoMsg(remaining)
, but correctly treating the timeFactor.
void expectNoMsg(scala.concurrent.duration.FiniteDuration max)
max
- (undocumented)void expectNoMsg_internal(scala.concurrent.duration.FiniteDuration max)
<T> scala.collection.immutable.Seq<T> receiveWhile(scala.concurrent.duration.Duration max, scala.concurrent.duration.Duration idle, int messages, scala.PartialFunction<java.lang.Object,T> f)
Note that it is not an error to hit the max
duration in this case.
One possible use of this method is for testing whether messages of certain characteristics are generated at a certain rate:
test ! ScheduleTicks(100 millis) val series = receiveWhile(750 millis) { case Tick(count) => count } assert(series == (1 to 7).toList)
max
- (undocumented)idle
- (undocumented)messages
- (undocumented)f
- (undocumented)
scala.collection.immutable.Seq<java.lang.Object> receiveN(int n)
receiveN(n, remaining)
but correctly taking into account
Duration.timeFactor.
n
- (undocumented)
scala.collection.immutable.Seq<java.lang.Object> receiveN(int n, scala.concurrent.duration.FiniteDuration max)
n
- (undocumented)max
- (undocumented)
scala.collection.immutable.Seq<java.lang.Object> receiveN_internal(int n, scala.concurrent.duration.Duration max)
java.lang.Object receiveOne(scala.concurrent.duration.Duration max)
This method does NOT automatically scale its Duration parameter!
max
- (undocumented)
void shutdown(ActorSystem actorSystem, scala.concurrent.duration.Duration duration, boolean verifySystemShutdown)
If verifySystemShutdown is true, then an exception will be thrown on failure.
actorSystem
- (undocumented)duration
- (undocumented)verifySystemShutdown
- (undocumented)java.lang.String format(java.util.concurrent.TimeUnit u, scala.concurrent.duration.Duration d)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |