use of co.paralleluniverse.actors.ShutdownMessage in project quasar by puniverse.
the class SupervisorTest method whenChildDiesThenRestart.
@Test
public void whenChildDiesThenRestart() throws Exception {
final Supervisor sup = new SupervisorActor(RestartStrategy.ONE_FOR_ONE, new ChildSpec("actor1", ChildMode.PERMANENT, 5, 1, TimeUnit.SECONDS, 3, ActorSpec.of(Actor1.class, "actor1"))).spawn(factory);
ActorRef<Object> a;
a = getChild(sup, "actor1", 1000);
for (int i = 0; i < 3; i++) a.send(1);
a.send(new ShutdownMessage(null));
assertThat(LocalActor.<Integer>get(a), is(3));
a = getChild(sup, "actor1", 1000);
for (int i = 0; i < 5; i++) a.send(1);
a.send(new ShutdownMessage(null));
assertThat(LocalActor.<Integer>get(a), is(5));
sup.shutdown();
LocalActor.join(sup);
}
use of co.paralleluniverse.actors.ShutdownMessage in project quasar by puniverse.
the class SupervisorTest method restartTransientChildDeadOfUnnaturalCause.
@Test
public void restartTransientChildDeadOfUnnaturalCause() throws Exception {
final Supervisor sup = new SupervisorActor(RestartStrategy.ONE_FOR_ONE, new ChildSpec("actor1", ChildMode.TRANSIENT, 5, 1, TimeUnit.SECONDS, 3, ActorSpec.of(BadActor1.class, "actor1"))).spawn();
ActorRef<Object> a;
a = getChild(sup, "actor1", 1000);
for (int i = 0; i < 3; i++) a.send(1);
a.send(new ShutdownMessage(null));
try {
LocalActor.join(a);
fail();
} catch (ExecutionException e) {
}
ActorRef<Object> b = getChild(sup, "actor1", 200);
assertThat(b, not(nullValue()));
assertThat(b, not(equalTo(a)));
List<ActorRef<Object>> bcs = getChildren(sup);
assertThat(bcs.get(0), not(nullValue()));
assertThat(bcs.get(0), not(equalTo(a)));
assertEquals(bcs.size(), 1);
sup.shutdown();
LocalActor.join(sup);
}
use of co.paralleluniverse.actors.ShutdownMessage in project quasar by puniverse.
the class SupervisorTest method dontRestartTemporaryChildDeadOfUnnaturalCause.
@Test
public void dontRestartTemporaryChildDeadOfUnnaturalCause() throws Exception {
final Supervisor sup = new SupervisorActor(RestartStrategy.ONE_FOR_ONE, new ChildSpec("actor1", ChildMode.TEMPORARY, 5, 1, TimeUnit.SECONDS, 3, ActorSpec.of(BadActor1.class, "actor1"))).spawn(factory);
ActorRef<Object> a;
a = getChild(sup, "actor1", 1000);
for (int i = 0; i < 3; i++) a.send(1);
a.send(new ShutdownMessage(null));
try {
LocalActor.join(a);
fail();
} catch (ExecutionException e) {
}
a = getChild(sup, "actor1", 200);
assertThat(a, nullValue());
sup.shutdown();
LocalActor.join(sup);
}
use of co.paralleluniverse.actors.ShutdownMessage in project quasar by puniverse.
the class SupervisorTest method dontRestartTemporaryChildDeadOfNaturalCause.
@Test
public void dontRestartTemporaryChildDeadOfNaturalCause() throws Exception {
final Supervisor sup = new SupervisorActor(RestartStrategy.ONE_FOR_ONE, new ChildSpec("actor1", ChildMode.TEMPORARY, 5, 1, TimeUnit.SECONDS, 3, ActorSpec.of(Actor1.class, "actor1"))).spawn();
ActorRef<Object> a;
a = getChild(sup, "actor1", 1000);
for (int i = 0; i < 3; i++) a.send(1);
a.send(new ShutdownMessage(null));
assertThat(LocalActor.<Integer>get(a), is(3));
a = getChild(sup, "actor1", 200);
assertThat(a, nullValue());
List<ActorRef<Object>> cs = getChildren(sup);
assertEquals(cs.size(), 0);
sup.shutdown();
LocalActor.join(sup);
}
use of co.paralleluniverse.actors.ShutdownMessage in project quasar by puniverse.
the class SupervisorTest method restartPreInstantiatedChild.
@Test
public void restartPreInstantiatedChild() throws Exception {
final Supervisor sup = new SupervisorActor(RestartStrategy.ONE_FOR_ONE).spawn();
final ActorRef<Object> a1 = new Actor2("actor1").spawn();
sup.addChild(new ChildSpec("actor1", ChildMode.PERMANENT, 5, 1, TimeUnit.SECONDS, 3, a1));
ActorRef<Object> a;
a = getChild(sup, "actor1", 1);
assertThat(a, equalTo(a1));
for (int i = 0; i < 3; i++) a.send(1);
a.send(new ShutdownMessage(null));
assertThat(LocalActor.<Integer>get(a), is(3));
a = getChild(sup, "actor1", 1000);
assertThat(a, is(not(equalTo(a1))));
for (int i = 0; i < 5; i++) a.send(1);
a.send(new ShutdownMessage(null));
assertThat(LocalActor.<Integer>get(a), is(5));
sup.shutdown();
LocalActor.join(sup);
}
Aggregations