use of co.paralleluniverse.actors.behaviors.Supervisor.ChildSpec in project quasar by puniverse.
the class SupervisorTest method dontRestartTransientChildDeadOfNaturalCause.
@Test
public void dontRestartTransientChildDeadOfNaturalCause() throws Exception {
final Supervisor sup = new SupervisorActor(RestartStrategy.ONE_FOR_ONE, new ChildSpec("actor1", ChildMode.TRANSIENT, 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());
sup.shutdown();
LocalActor.join(sup);
}
use of co.paralleluniverse.actors.behaviors.Supervisor.ChildSpec in project quasar by puniverse.
the class SupervisorTest method testComplex1.
@Test
public void testComplex1() throws Exception {
AtomicInteger started = new AtomicInteger();
AtomicInteger terminated = new AtomicInteger();
final Supervisor sup = new SupervisorActor(RestartStrategy.ALL_FOR_ONE, new ChildSpec("actor1", ChildMode.PERMANENT, 5, 1, TimeUnit.SECONDS, 3, ActorSpec.of(Actor3.class, "actor1", started, terminated))).spawn();
ActorRef<Integer> a;
a = getChild(sup, "actor1", 1000);
a.send(3);
a.send(4);
assertThat(LocalActor.<Integer>get(a), is(7));
a = getChild(sup, "actor1", 1000);
a.send(70);
a.send(80);
try {
LocalActor.<Integer>get(a);
fail();
} catch (ExecutionException e) {
}
a = getChild(sup, "actor1", 1000);
a.send(7);
a.send(8);
assertThat(LocalActor.<Integer>get(a), is(15));
// give the actor time to start the GenServer
Thread.sleep(100);
sup.shutdown();
LocalActor.join(sup);
assertThat(started.get(), is(4));
assertThat(terminated.get(), is(4));
}
use of co.paralleluniverse.actors.behaviors.Supervisor.ChildSpec in project quasar by puniverse.
the class SupervisorTest method startChild.
@Test
public void startChild() 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));
sup.shutdown();
LocalActor.join(sup);
}
Aggregations