Example #1
0
 @Test
 public void demonstrateTestActorRef() {
   final Props props = Props.create(MyActor.class);
   final TestActorRef<MyActor> ref = TestActorRef.create(system, props, "testA");
   final MyActor actor = ref.underlyingActor();
   assertTrue(actor.testMe());
 }
Example #2
0
 @Test
 public void demonstrateExceptions() {
   // #test-expecting-exceptions
   final Props props = Props.create(MyActor.class);
   final TestActorRef<MyActor> ref = TestActorRef.create(system, props, "myActor");
   try {
     ref.receive(new Exception("expected"));
     fail("expected an exception to be thrown");
   } catch (Exception e) {
     assertEquals("expected", e.getMessage());
   }
   // #test-expecting-exceptions
 }
Example #3
0
 @Test
 public void demonstrateAsk() throws Exception {
   // #test-behavior
   final Props props = Props.create(MyActor.class);
   final TestActorRef<MyActor> ref = TestActorRef.create(system, props, "testB");
   final Future<Object> future = akka.pattern.Patterns.ask(ref, "say42", 3000);
   assertTrue(future.isCompleted());
   assertEquals(42, Await.result(future, Duration.Zero()));
   // #test-behavior
 }