true
If no timeout is given, take it from the innermost enclosing Within block.
Within
Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "akka.test.timefactor".
141142143144145146147148149150151
} } @Test public void contextActorOf() { new JavaTestKit(system) { { //#context-actorOf class A extends UntypedActor { final ActorRef child = getContext().actorOf(Props.create(MyUntypedActor.class), "myChild");
325326327328329330331332333334335
// ActorSystem is a heavy object: create only one per application final ActorSystem system = ActorSystem.create("MySystem", config); final ActorRef myActor = system.actorOf(Props.create(MyActor.class), "myactor"); //#system-actorOf try { new JavaTestKit(system) { { myActor.tell("hello", getRef()); expectMsgEquals("hello"); } };
205206207208209210211212213214215
final ActorRef myActor = getContext().actorOf( Props.create(DependencyInjector.class, applicationContext, "MyActor"), "myactor3"); //#creating-indirectly new JavaTestKit(system) { { myActor.tell("hello", getRef()); expectMsgEquals("..."); } };
397398399400401402403404405406407
//#receive-timeout @Test public void using_receiveTimeout() { final ActorRef myActor = system.actorOf(Props.create(ReceiveTimeoutActor.class)); new JavaTestKit(system) { { myActor.tell("Hello", getRef()); expectMsgEquals("Hello world"); expectMsgEquals("timeout"); }
227228229230231232233234235236237
} @Test public void receiveTimeout() { final ActorRef myActor = system.actorOf(Props.create(MyReceiveTimeoutUntypedActor.class)); new JavaTestKit(system) { { new Within(Duration.create(1, TimeUnit.SECONDS), Duration.create(1500, TimeUnit.MILLISECONDS)) { @Override protected void run() {
245246247248249250251252253254255
} @Test public void usePoisonPill() { final ActorRef myActor = system.actorOf(Props.create(MyUntypedActor.class)); new JavaTestKit(system) { { final ActorRef sender = getRef(); //#poison-pill myActor.tell(akka.actor.PoisonPill.getInstance(), sender); //#poison-pill
445446447448449450451452453454455
//#hot-swap-actor @Test public void using_hot_swap() { final ActorRef actor = system.actorOf(Props.create(HotSwapActor.class), "hot"); new JavaTestKit(system) { { actor.tell("foo", getRef()); actor.tell("foo", getRef()); expectMsgEquals("I am already angry?"); actor.tell("bar", getRef());
513514515516517518519520521522523
@Test public void using_watch() { ActorRef actor = system.actorOf(Props.create(WatchActor.class)); new JavaTestKit(system) { { actor.tell("kill", getRef()); expectMsgEquals("finished"); } };
259260261262263264265266267268269
}; } @Test public void useKill() { new JavaTestKit(system) { { class Master extends UntypedActor { private SupervisorStrategy strategy = new OneForOneStrategy(-1, Duration.Undefined(), new Function<Throwable, Directive>() { @Override
556557558559560561562563564565566
@Test public void using_Identify() { ActorRef a = system.actorOf(Props.empty()); ActorRef b = system.actorOf(Props.create(Follower.class)); new JavaTestKit(system) { { watch(b); system.stop(a); assertEquals(expectMsgClass(Duration.create(2, TimeUnit.SECONDS), Terminated.class).actor(), b); }