Ejemplo n.º 1
0
        public void should_handle_messages_of_different_types()
        {
            var testActor = new MyTestActor(ActorId.GenerateNew());

            testActor.Handle(new MyTestMessage1());
            testActor.Handle(new MyTestMessage2());

            Check.That(testActor.HandledMessagesTypes)
            .ContainsExactly(typeof(MyTestMessage1), typeof(MyTestMessage2));
        }
Ejemplo n.º 2
0
        public void should_send_message_to_the_actor_via_system_in_memory()
        {
            var testActorId = ActorId.GenerateNew();
            var testActor   = new MyTestActor(testActorId);

            using (var system = ActorsSystem.WithoutQueues(null, testActor))
            {
                var messageToSend = new MyTestMessage1(destinationId: testActorId);
                system.Send(messageToSend);

                Check.That(testActor.HandledMessages).Contains(messageToSend);
            }
        }
Ejemplo n.º 3
0
        public void should_send_message_to_the_actor_via_system_with_queues()
        {
            var testActorId = ActorId.GenerateNew();
            var testActor   = new MyTestActor(testActorId);

            using (var system = ActorsSystem.WithQueues(null, testActor))
            {
                var messageToSend = new MyTestMessage1(destinationId: testActorId);
                system.Send(messageToSend);

                Thread.Sleep(500); //that's because of queues usage. use in memory system to avoid dependency from time
                Check.That(testActor.HandledMessages).Contains(messageToSend);
            }
        }
Ejemplo n.º 4
0
        public void should_distribute_messages_in_a_round_robin_fashion()
        {
            //arrange
            var actor1 = new MyTestActor(ActorId.GenerateNew());
            var actor2 = new MyTestActor(ActorId.GenerateNew());

            var factory         = From(actor1, actor2);
            var roundRobinActor = new RoundRobinActor(ActorId.GenerateNew(), factory, 2, null, new DummyMailBox());

            //act
            roundRobinActor.Handle(new MyTestMessage1());
            roundRobinActor.Handle(new MyTestMessage1());
            roundRobinActor.Handle(new MyTestMessage1());

            //assert
            Check.That(actor1.HandledMessages).HasSize(2);
            Check.That(actor2.HandledMessages).HasSize(1);
        }
Ejemplo n.º 5
0
        public void should_distribute_messages_in_a_round_robin_fashion_with_queues()
        {
            //arrange
            var actor1 = new MyTestActor(ActorId.GenerateNew());
            var actor2 = new MyTestActor(ActorId.GenerateNew());

            var factory         = From(QueuedActor.Of(actor1), QueuedActor.Of(actor2));
            var roundRobinActor = QueuedActor.Of(new RoundRobinActor(ActorId.GenerateNew(), factory, 2, null, new DummyMailBox()));

            //act
            roundRobinActor.Handle(new MyTestMessage1());
            roundRobinActor.Handle(new MyTestMessage1());
            roundRobinActor.Handle(new MyTestMessage1());

            //assert
            Thread.Sleep(500);
            Check.That(actor1.HandledMessages).HasSize(2);
            Check.That(actor2.HandledMessages).HasSize(1);
        }