@Test public void testingWithoutParent() { TestProbe probe = new TestProbe(system); ActorRef child = system.actorOf(Props.create(DependentChild.class, probe.ref())); probe.send(child, "ping"); probe.expectMsg("pong"); }
@Test public void fabricatedParentTestsItsChildResponses() throws Exception { // didn't put final on these in order to make the parent fit in one line in the html docs // #test-fabricated-parent TestProbe proxy = new TestProbe(system); ActorRef parent = system.actorOf(Props.create(new FabricatedParentCreator(proxy))); proxy.send(parent, "ping"); proxy.expectMsg("pong"); // #test-fabricated-parent }
public void exampleProdActorFactoryFunction() throws Exception { // #child-maker-prod Function<ActorRefFactory, ActorRef> maker = new Function<ActorRefFactory, ActorRef>() { @Override public ActorRef apply(ActorRefFactory f) throws Exception { return f.actorOf(Props.create(Child.class)); } }; ActorRef parent = system.actorOf(Props.create(GenericDependentParent.class, maker)); // #child-maker-prod }
@Test public void testingWithChildProbe() throws Exception { final TestProbe probe = new TestProbe(system); // #child-maker-test Function<ActorRefFactory, ActorRef> maker = new Function<ActorRefFactory, ActorRef>() { @Override public ActorRef apply(ActorRefFactory param) throws Exception { return probe.ref(); } }; ActorRef parent = system.actorOf(Props.create(GenericDependentParent.class, maker)); // #child-maker-test probe.send(parent, "pingit"); probe.expectMsg("ping"); }