c

akka.testkit

JavaTestKit

class JavaTestKit extends AnyRef

Java API: Test kit for testing actors. Inheriting from this class enables reception of replies from actors, which are queued by an internal actor and can be examined using the expectMsg... methods. Assertions and bounds concerning timing are available in the form of Within blocks.

Beware of two points:

  • the ActorSystem passed into the constructor needs to be shutdown, otherwise thread pools and memory will be leaked - this trait is not thread-safe (only one actor with one queue, one stack of Within blocks); take care not to run tests within a single test class instance in parallel.
  • It should be noted that for CI servers and the like all maximum Durations are scaled using the dilated method, which uses the TestKitExtension.Settings.TestTimeFactor settable via akka.conf entry "akka.test.timefactor".
Deprecated

Use akka.testkit.javadsl.TestKit instead, since 2.5.0

Source
JavaTestKit.java
Linear Supertypes
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. JavaTestKit
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new JavaTestKit(system: ActorSystem)

    Deprecated

    Use akka.testkit.javadsl.TestKit instead, since 2.5.0

Type Members

  1. abstract class AwaitAssert extends AnyRef

    Await until the given assert does not throw an exception or the timeout expires, whichever comes first.

    Await until the given assert does not throw an exception or the timeout expires, whichever comes first. If the timeout expires the last exception is thrown.

    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".

  2. abstract class AwaitCond extends AnyRef

    Await until the given condition evaluates to true or the timeout expires, whichever comes first.

    Await until the given condition evaluates to 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".

  3. abstract class EventFilter[T] extends AnyRef

    Facilities for selectively filtering out expected events from logging so that you can keep your test run’s console output clean and do not miss real error messages.

    Facilities for selectively filtering out expected events from logging so that you can keep your test run’s console output clean and do not miss real error messages.

    If the occurrences is set to Integer.MAX_VALUE, no tracking is done.

  4. abstract class ExpectMsg[T] extends AnyRef

    Receive one message from the test actor and assert that the given matching function accepts it.

    Receive one message from the test actor and assert that the given matching function accepts it. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

    The received object as transformed by the matching function can be retrieved with the get method.

    Use this variant to implement more complicated or conditional processing.

    
    final String out = new ExpectMsg<String>("match hint") {
      protected String match(Object in) {
        if (in instanceof Integer)
          return "match";
        else
          throw noMatch();
      }
    }.get(); // this extracts the received message
    
    

  5. abstract class IgnoreMsg extends AnyRef

    Ignore all messages in the test actor for which the given function returns true.

  6. abstract class ReceiveWhile[T] extends AnyRef

    Receive a series of messages until one does not match the given match function or the idle timeout is met (disabled by default) or the overall maximum duration is elapsed.

    Receive a series of messages until one does not match the given match function or the idle timeout is met (disabled by default) or the overall maximum duration is elapsed. Returns the sequence of messages.

    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.

  7. abstract class Within extends AnyRef

    Execute code block while bounding its execution time between min and max.

    Execute code block while bounding its execution time between 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 dilated, which uses the configuration entry "akka.test.timefactor", while the min Duration is not.

    
    // the run() method needs to finish within 3 seconds
    new Within(duration("3 seconds")) {
      protected void run() {
        // ...
      }
    }
    
    

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from JavaTestKit to any2stringadd[JavaTestKit] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (JavaTestKit, B)
    Implicit
    This member is added by an implicit conversion from JavaTestKit to ArrowAssoc[JavaTestKit] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def childActorOf(props: Props): ActorRef

    Spawns an actor as a child of this test actor, and returns the child's ActorRef.

    Spawns an actor as a child of this test actor, and returns the child's ActorRef. The actor will have an auto-generated name and will be supervised using SupervisorStrategy.stoppingStrategy.

    props

    Props to create the child actor

  8. def childActorOf(props: Props, name: String): ActorRef

    Spawns an actor as a child of this test actor, and returns the child's ActorRef.

    Spawns an actor as a child of this test actor, and returns the child's ActorRef. The actor will be supervised using SupervisorStrategy.stoppingStrategy.

    props

    Props to create the child actor

    name

    Actor name for the child actor

  9. def childActorOf(props: Props, supervisorStrategy: SupervisorStrategy): ActorRef

    Spawns an actor as a child of this test actor, and returns the child's ActorRef.

    Spawns an actor as a child of this test actor, and returns the child's ActorRef. The actor will have an auto-generated name.

    props

    Props to create the child actor

    supervisorStrategy

    Strategy should decide what to do with failures in the actor.

  10. def childActorOf(props: Props, name: String, supervisorStrategy: SupervisorStrategy): ActorRef

    Spawns an actor as a child of this test actor, and returns the child's ActorRef.

    Spawns an actor as a child of this test actor, and returns the child's ActorRef.

    props

    Props to create the child actor

    name

    Actor name for the child actor

    supervisorStrategy

    Strategy should decide what to do with failures in the actor.

  11. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  12. def dilated(d: Duration): Duration
  13. def ensuring(cond: (JavaTestKit) ⇒ Boolean, msg: ⇒ Any): JavaTestKit
    Implicit
    This member is added by an implicit conversion from JavaTestKit to Ensuring[JavaTestKit] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. def ensuring(cond: (JavaTestKit) ⇒ Boolean): JavaTestKit
    Implicit
    This member is added by an implicit conversion from JavaTestKit to Ensuring[JavaTestKit] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  15. def ensuring(cond: Boolean, msg: ⇒ Any): JavaTestKit
    Implicit
    This member is added by an implicit conversion from JavaTestKit to Ensuring[JavaTestKit] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  16. def ensuring(cond: Boolean): JavaTestKit
    Implicit
    This member is added by an implicit conversion from JavaTestKit to Ensuring[JavaTestKit] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  17. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  18. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  19. def expectMsgAllOf(max: FiniteDuration, msgs: <repeated...>[AnyRef]): Array[AnyRef]

    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.

    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. This construct is useful when the order in which the objects are received is not fixed. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

  20. def expectMsgAllOf(msgs: <repeated...>[AnyRef]): Array[AnyRef]

    Same as expectMsgAllOf(remainingOrDefault(), obj...), but correctly treating the timeFactor.

  21. def expectMsgAnyClassOf(max: FiniteDuration, classes: <repeated...>[Class[_]]): AnyRef

    Receive one message from the test actor and assert that it conforms to one of the given classes.

    Receive one message from the test actor and assert that it conforms to one of the given classes. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

    returns

    the received object

  22. def expectMsgAnyClassOf[T](classes: <repeated...>[Class[_ <: T]]): T

    Same as expectMsgAnyClassOf(remainingOrDefault(), obj...), but correctly treating the timeFactor.

  23. def expectMsgAnyOf(max: FiniteDuration, msgs: <repeated...>[AnyRef]): AnyRef

    Receive one message from the test actor and assert that it equals one of the given objects.

    Receive one message from the test actor and assert that it equals one of the given objects. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

    returns

    the received object

  24. def expectMsgAnyOf(msgs: <repeated...>[AnyRef]): AnyRef

    Same as expectMsgAnyOf(remainingOrDefault(), obj...), but correctly treating the timeFactor.

  25. def expectMsgClass[T](max: FiniteDuration, clazz: Class[T]): T

    Receive one message from the test actor and assert that it conforms to the given class.

    Receive one message from the test actor and assert that it conforms to the given class. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

    returns

    the received object

  26. def expectMsgClass[T](clazz: Class[T]): T

    Same as expectMsgClass(remainingOrDefault(), clazz), but correctly treating the timeFactor.

  27. def expectMsgEquals[T](max: FiniteDuration, msg: T): T

    Receive one message from the test actor and assert that it equals the given object.

    Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

    returns

    the received object

  28. def expectMsgEquals[T](msg: T): T

    Same as expectMsgEquals(remainingOrDefault(), obj), but correctly treating the timeFactor.

  29. def expectNoMsg(max: FiniteDuration): Unit

    Assert that no message is received for the specified time.

  30. def expectNoMsg(): Unit

    Same as expectNoMsg(remainingOrDefault()), but correctly treating the timeFactor.

  31. def expectTerminated(target: ActorRef): Terminated

    Same as expectTerminated(remainingOrDefault(), target), but correctly treating the timeFactor.

    Same as expectTerminated(remainingOrDefault(), target), but correctly treating the timeFactor. Don't forget to 'watch' it first!

  32. def expectTerminated(max: Duration, target: ActorRef): Terminated

    Assert that the given ActorRef is Terminated within the specified time.

    Assert that the given ActorRef is Terminated within the specified time. Don't forget to 'watch' it first!

  33. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  34. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from JavaTestKit to StringFormat[JavaTestKit] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  35. def forward(actor: ActorRef): Unit
  36. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  37. def getLastSender(): ActorRef
  38. def getRef(): ActorRef

    Shorthand to get the testActor.

  39. def getRemainingTime(): FiniteDuration
  40. def getRemainingTimeOr(def: FiniteDuration): FiniteDuration
  41. def getSystem(): ActorSystem
  42. def getTestActor(): ActorRef

    ActorRef of the test actor.

    ActorRef of the test actor. Access is provided to enable e.g. registration as message target.

  43. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  44. def ignoreNoMsg(): Unit

    Stop ignoring messages in the test actor.

  45. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  46. def msgAvailable(): Boolean

    Query queue status.

  47. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  48. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  49. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  50. def receiveN(n: Int, max: FiniteDuration): Array[AnyRef]

    Receive N messages in a row before the given deadline.

  51. def receiveN(n: Int): Array[AnyRef]

    Same as receiveN(n, remaining()), but correctly treating the timeFactor.

  52. def receiveOne(max: Duration): AnyRef

    Receive one message from the internal queue of the TestActor.

    Receive one message from the internal queue of the TestActor. If the given duration is zero, the queue is polled (non-blocking).

    This method does NOT automatically scale its Duration parameter!

  53. def remaining(): FiniteDuration

    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").

  54. def remainingOr(duration: FiniteDuration): FiniteDuration

    Obtain time remaining for execution of the innermost enclosing Within block or missing that it returns the given duration.

  55. def remainingOrDefault(): FiniteDuration

    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").

  56. def reply(msg: Any): Unit
  57. def send(actor: ActorRef, msg: Any): Unit
  58. def setAutoPilot(pilot: AutoPilot): Unit

    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.

    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. Each invocation must return the AutoPilot for the next round.

  59. def shutdown(actorSystem: ActorSystem, verifySystemShutdown: Boolean): Unit
  60. def shutdown(actorSystem: ActorSystem, duration: Duration): Unit
  61. def shutdown(actorSystem: ActorSystem): Unit
  62. def shutdown(actorSystem: ActorSystem, duration: Duration, verifySystemShutdown: Boolean): Unit

    Shut down an actor system and wait for termination.

    Shut down an actor system and wait for termination. On failure debug output will be logged about the remaining actors in the system.

    If verifySystemShutdown is true, then an exception will be thrown on failure.

  63. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  64. def toString(): String
    Definition Classes
    AnyRef → Any
  65. def unwatch(ref: ActorRef): ActorRef

    Have the testActor stop watching someone (i.e.

    Have the testActor stop watching someone (i.e. getContext.unwatch(...)).

  66. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  67. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  68. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  69. def watch(ref: ActorRef): ActorRef

    Have the testActor watch someone (i.e.

    Have the testActor watch someone (i.e. getContext().getWatch(...) ).

  70. def [B](y: B): (JavaTestKit, B)
    Implicit
    This member is added by an implicit conversion from JavaTestKit to ArrowAssoc[JavaTestKit] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from JavaTestKit to any2stringadd[JavaTestKit]

Inherited by implicit conversion StringFormat from JavaTestKit to StringFormat[JavaTestKit]

Inherited by implicit conversion Ensuring from JavaTestKit to Ensuring[JavaTestKit]

Inherited by implicit conversion ArrowAssoc from JavaTestKit to ArrowAssoc[JavaTestKit]

Ungrouped