Пример #1
0
 @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");
 }
Пример #2
0
  @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
  }
Пример #3
0
  @Test
  public void testingWithCustomProps() {
    TestProbe probe = new TestProbe(system);
    Props childProps = Props.create(MockedChild.class);
    TestActorRef<DependentParent> parent =
        TestActorRef.create(system, Props.create(DependentParent.class, childProps));

    probe.send(parent, "pingit");

    // test some parent state change
    assertTrue(parent.underlyingActor().ponged == true || parent.underlyingActor().ponged == false);
  }
Пример #4
0
 @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");
 }