Search in sources :

Example 6 with ChildSpec

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);
}
Also used : ShutdownMessage(co.paralleluniverse.actors.ShutdownMessage) ChildSpec(co.paralleluniverse.actors.behaviors.Supervisor.ChildSpec) Test(org.junit.Test)

Example 7 with ChildSpec

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));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ChildSpec(co.paralleluniverse.actors.behaviors.Supervisor.ChildSpec) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 8 with ChildSpec

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);
}
Also used : ShutdownMessage(co.paralleluniverse.actors.ShutdownMessage) ChildSpec(co.paralleluniverse.actors.behaviors.Supervisor.ChildSpec) Test(org.junit.Test)

Aggregations

ChildSpec (co.paralleluniverse.actors.behaviors.Supervisor.ChildSpec)8 Test (org.junit.Test)8 ShutdownMessage (co.paralleluniverse.actors.ShutdownMessage)7 ExecutionException (java.util.concurrent.ExecutionException)3 ActorRef (co.paralleluniverse.actors.ActorRef)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1