Exemplo n.º 1
0
 @Test
 public void testLocalTopologyWithLinkedActorsAndExitTraps() throws Exception {
   ServerTopology topology = null;
   try {
     topology = new ServerTopology(HOST, PORT);
     CountDownLatch killLatch = new CountDownLatch(1);
     CountDownLatch trapLatch = new CountDownLatch(1);
     Address actorAddress1 =
         topology.spawnActor(ACTOR_ADDRESS_1, new TestKilledHandler(killLatch));
     assertNotNull(actorAddress1);
     Address actorAddress2 =
         topology.spawnActor(ACTOR_ADDRESS_2, new TestHandlerTrappingExit(trapLatch));
     assertNotNull(actorAddress2);
     Actor actor1 = topology.getActor(actorAddress1);
     Actor actor2 = topology.getActor(actorAddress2);
     actor1.link(actor2);
     actor1.send(EXPECTED_MESSAGE);
     boolean killed = killLatch.await(3, TimeUnit.SECONDS);
     assertTrue(killed);
     assertFalse(actor1.isActive());
     boolean trapped = trapLatch.await(3, TimeUnit.SECONDS);
     assertTrue(trapped);
     assertTrue(actor2.isActive());
   } finally {
     topology.shutdown();
   }
 }
Exemplo n.º 2
0
 @Test(expected = TopologyException.class)
 public void testSpawnActorAfterShutdownThrowsException() throws Exception {
   ServerTopology topology = null;
   try {
     topology = new ServerTopology(HOST, PORT);
   } finally {
     topology.shutdown();
   }
   topology.spawnActor(ACTOR_ADDRESS_1, new Object());
 }
Exemplo n.º 3
0
 @Test
 public void testSpawnAndGetActorAtOneTime() throws Exception {
   ServerTopology topology = null;
   try {
     topology = new ServerTopology(HOST, PORT);
     Actor actor = topology.spawnAndGetActor(ACTOR_ADDRESS_1, new Object());
     assertNotNull(actor);
   } finally {
     topology.shutdown();
   }
 }
Exemplo n.º 4
0
 @Test
 public void testSpawnActorAndSendMessageWithOSThreads() throws Exception {
   ServerTopology topology = null;
   try {
     topology = new ServerTopology(HOST, PORT, ThreadingPolicies.newOSThreadingPolicy(10));
     CountDownLatch messageReceiveLatch = new CountDownLatch(1);
     Address actorAddress =
         topology.spawnActor(ACTOR_ADDRESS_1, new TestHandler(messageReceiveLatch));
     assertNotNull(actorAddress);
     Actor actor = topology.getActor(actorAddress);
     actor.send(EXPECTED_MESSAGE);
     boolean success = messageReceiveLatch.await(3, TimeUnit.SECONDS);
     assertTrue(success);
   } finally {
     topology.shutdown();
   }
 }
Exemplo n.º 5
0
 @Test
 public void testLocalTopologyWithDefaultFailoverPolicyAKANoFailoverPolicy() throws Exception {
   ServerTopology topology = null;
   try {
     topology = new ServerTopology(HOST, PORT);
     CountDownLatch killLatch = new CountDownLatch(1);
     Address actorAddress = topology.spawnActor(ACTOR_ADDRESS_1, new TestKilledHandler(killLatch));
     assertNotNull(actorAddress);
     Actor actor = topology.getActor(actorAddress);
     actor.send(EXPECTED_MESSAGE);
     boolean killed = killLatch.await(3, TimeUnit.SECONDS);
     assertTrue(killed);
     Actor killedActor = topology.getActor(actorAddress);
     assertNull(killedActor);
   } finally {
     topology.shutdown();
   }
 }
Exemplo n.º 6
0
 @Test
 public void testSpawnActorAndSendMessageWithFutureAndResult() throws Exception {
   ServerTopology topology = null;
   try {
     topology = new ServerTopology(HOST, PORT);
     Address actorAddress =
         topology.spawnActor(ACTOR_ADDRESS_1, new TestHandlerWithFutureAndResult());
     assertNotNull(actorAddress);
     Actor actor = topology.getActor(actorAddress);
     FutureResult future = actor.send(EXPECTED_MESSAGE, 10, TimeUnit.SECONDS);
     future.await();
     assertTrue(future.isCompleted());
     assertFalse(future.isExpired());
     assertEquals(EXPECTED_MESSAGE, future.getResult());
     assertNull(future.getException());
   } finally {
     topology.shutdown();
   }
 }
Exemplo n.º 7
0
 @Test
 public void testLocalTopologyWithFailedActorAndAllForOneFailoverPolicy() throws Exception {
   ServerTopology topology = null;
   try {
     topology = new ServerTopology(HOST, PORT, FailoverPolicies.newAllForOnePolicy());
     CountDownLatch restartLatch1 = new CountDownLatch(1);
     CountDownLatch restartLatch2 = new CountDownLatch(1);
     Address actorAddress1 =
         topology.spawnActor(ACTOR_ADDRESS_1, new TestRestartedHandlerOnFail(restartLatch1));
     assertNotNull(actorAddress1);
     Address actorAddress2 =
         topology.spawnActor(ACTOR_ADDRESS_2, new TestRestartedHandler(restartLatch2));
     assertNotNull(actorAddress2);
     Actor actor1 = topology.getActor(actorAddress1);
     actor1.send(EXPECTED_MESSAGE);
     boolean restarted = restartLatch1.await(3, TimeUnit.SECONDS);
     assertTrue(restarted);
     Actor restartedActor = topology.getActor(actorAddress1);
     assertSame(actor1, restartedActor);
     restarted = restartLatch2.await(3, TimeUnit.SECONDS);
     assertTrue(restarted);
   } finally {
     topology.shutdown();
   }
 }
Exemplo n.º 8
0
 @Test
 public void testHotSwap() throws Exception {
   ServerTopology topology = null;
   try {
     topology = new ServerTopology(HOST, PORT);
     CountDownLatch firstLatch = new CountDownLatch(1);
     CountDownLatch swappedLatch = new CountDownLatch(1);
     Address actorAddress = topology.spawnActor(ACTOR_ADDRESS_1, new TestHandler(firstLatch));
     Actor actor = topology.getActor(actorAddress);
     actor.send(EXPECTED_MESSAGE);
     boolean received = firstLatch.await(3, TimeUnit.SECONDS);
     assertTrue(received);
     actor.swap(new TestSwappedHandler(swappedLatch));
     actor.send(EXPECTED_MESSAGE);
     received = swappedLatch.await(3, TimeUnit.SECONDS);
     assertFalse(received);
     actor.send(SWAPPED_MESSAGE);
     received = swappedLatch.await(3, TimeUnit.SECONDS);
     assertTrue(received);
   } finally {
     topology.shutdown();
   }
 }
Exemplo n.º 9
0
 @Test(expected = TopologyException.class)
 public void testGetActorAfterShutdownThrowsException() throws Exception {
   ServerTopology topology = new ServerTopology(HOST, PORT);
   topology.shutdown();
   topology.getActor(Address.newRemoteAddress(HOST, PORT, ACTOR_ADDRESS_1));
 }