예제 #1
0
        public void CreateActorRefUsingActorAndSendThreeMessages()
        {
            int             total = 0;
            EventWaitHandle wait  = new AutoResetEvent(false);

            Actor actor = new LambdaActor(c => { total += (int)c; if (total >= 6)
                                                 {
                                                     wait.Set();
                                                 }
                                          });

            ActorSystem system = new ActorSystem();

            var result = system.ActorOf(actor);

            Assert.IsNotNull(result);
            Assert.AreSame(result, actor.Self);

            result.Tell(1);
            result.Tell(2);
            result.Tell(3);

            wait.WaitOne();

            Assert.AreEqual(6, total);
            system.Stop(result);

            // TODO better time management
            Thread.Sleep(1000);

            Assert.AreEqual(ActorState.Stopped, actor.State);
        }
예제 #2
0
        public void SendOneMessage()
        {
            int total = 0;

            Actor actor = new LambdaActor(c => { total += (int)c; });

            actor.Receive(1);

            Assert.AreEqual(1, total);
        }
예제 #3
0
        public void SendThreeMessages()
        {
            int total = 0;

            Actor actor = new LambdaActor(c => { total += (int)c; });

            actor.Receive(1);
            actor.Receive(2);
            actor.Receive(3);

            Assert.AreEqual(6, total);
        }
예제 #4
0
        public void CreateAndUseForwardActor()
        {
            int             total = 0;
            EventWaitHandle wait  = new AutoResetEvent(false);

            Actor actor = new LambdaActor(c => { total += (int)c; wait.Set(); });

            ActorSystem system = new ActorSystem();

            var   actorref  = system.ActorOf(actor);
            Actor forwarder = new ForwardActor(actorref);

            forwarder.Receive(1);

            wait.WaitOne();

            Assert.AreEqual(1, total);
        }