Search in sources :

Example 6 with ActorSystem

use of actor4j.core.ActorSystem in project actor4j-core by relvaner.

the class UnhandledFeature method before.

@Before
public void before() {
    system = new ActorSystem();
    system.setParallelismMin(1);
    system.setDebugUnhandled(true);
}
Also used : ActorSystem(actor4j.core.ActorSystem) Before(org.junit.Before)

Example 7 with ActorSystem

use of actor4j.core.ActorSystem in project actor4j-core by relvaner.

the class ActorFeature method test_preStart_addChild.

@Test(timeout = 2000)
public void test_preStart_addChild() {
    CountDownLatch testDone = new CountDownLatch(1);
    ActorSystem system = new ActorSystem();
    UUID parent = system.addActor(() -> new Actor("parent") {

        protected UUID child;

        @Override
        public void preStart() {
            child = addChild(() -> new Actor("child") {

                @Override
                public void receive(ActorMessage<?> message) {
                    testDone.countDown();
                }
            });
        }

        @Override
        public void receive(ActorMessage<?> message) {
            tell(null, 0, child);
        }
    });
    system.start();
    system.send(new ActorMessage<>(null, 0, system.SYSTEM_ID, parent));
    try {
        testDone.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    system.shutdownWithActors(true);
}
Also used : ActorSystem(actor4j.core.ActorSystem) Actor(actor4j.core.actors.Actor) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) Test(org.junit.Test)

Example 8 with ActorSystem

use of actor4j.core.ActorSystem in project actor4j-core by relvaner.

the class AwaitFeature method before.

@Before
public void before() {
    system = new ActorSystem();
    system.setParallelismMin(1);
}
Also used : ActorSystem(actor4j.core.ActorSystem) Before(org.junit.Before)

Example 9 with ActorSystem

use of actor4j.core.ActorSystem in project actor4j-core by relvaner.

the class EmbeddedActorFeature method test_become_unbecome.

@Test(timeout = 2000)
public void test_become_unbecome() {
    CountDownLatch testDone = new CountDownLatch(2);
    AtomicInteger counter = new AtomicInteger(0);
    ActorSystem system = new ActorSystem();
    UUID host = system.addActor(() -> new Actor("host") {

        protected EmbeddedActor client;

        @Override
        public void preStart() {
            client = new EmbeddedActor("host:client", this) {

                @Override
                public boolean receive(ActorMessage<?> message) {
                    boolean result = false;
                    if (message.tag == SWAP) {
                        become(msg -> {
                            logger().debug(String.format("Received String message: %s", msg.valueAsString()));
                            unbecome();
                            if (counter.incrementAndGet() == 1)
                                assertEquals("Hello World!", msg.valueAsString());
                            else
                                assertEquals("Hello World Again!", msg.valueAsString());
                            testDone.countDown();
                            return true;
                        }, false);
                        result = true;
                    }
                    return result;
                }
            };
        }

        @Override
        public void receive(ActorMessage<?> message) {
            if (!client.embedded(message))
                unhandled(message);
        }
    });
    system.send(new ActorMessage<Object>(null, SWAP, system.SYSTEM_ID, host));
    system.send(new ActorMessage<Object>("Hello World!", 0, system.SYSTEM_ID, host));
    system.send(new ActorMessage<Object>(null, SWAP, system.SYSTEM_ID, host));
    system.send(new ActorMessage<Object>("Hello World Again!", 0, system.SYSTEM_ID, host));
    system.start();
    try {
        testDone.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    system.shutdownWithActors(true);
}
Also used : ActorSystem(actor4j.core.ActorSystem) CountDownLatch(java.util.concurrent.CountDownLatch) EmbeddedActor(actor4j.core.actors.EmbeddedActor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmbeddedActor(actor4j.core.actors.EmbeddedActor) Actor(actor4j.core.actors.Actor) ActorMessage(actor4j.core.messages.ActorMessage) UUID(java.util.UUID) Test(org.junit.Test)

Example 10 with ActorSystem

use of actor4j.core.ActorSystem in project actor4j-core by relvaner.

the class SafetyFeature method before.

@Before
public void before() {
    system = new ActorSystem();
    system.setParallelismMin(1);
}
Also used : ActorSystem(actor4j.core.ActorSystem) Before(org.junit.Before)

Aggregations

ActorSystem (actor4j.core.ActorSystem)10 CountDownLatch (java.util.concurrent.CountDownLatch)6 Test (org.junit.Test)6 ActorMessage (actor4j.core.messages.ActorMessage)5 UUID (java.util.UUID)5 Actor (actor4j.core.actors.Actor)4 Before (org.junit.Before)4 Assert (org.junit.Assert)3 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ActorTimer (actor4j.core.ActorTimer)1 EmbeddedActor (actor4j.core.actors.EmbeddedActor)1 PersistentActor (actor4j.core.actors.PersistentActor)1 PrimaryActor (actor4j.core.actors.PrimaryActor)1 PseudoActor (actor4j.core.actors.PseudoActor)1 SecondaryActor (actor4j.core.actors.SecondaryActor)1 StatelessActor (actor4j.core.actors.StatelessActor)1 ActorPersistenceObject (actor4j.core.persistence.ActorPersistenceObject)1