Exemple #1
0
        public void ActorHandlersMap_CanAddTwoActorsHandlingSameMessageTypeInDifferentPartitions()
        {
            var actorHandlersMap      = new ActorHandlerMap();
            var partition             = Guid.NewGuid().ToByteArray();
            var actorWithoutPartition = new ConfigurableActor(new[]
            {
                new MessageHandlerDefinition
                {
                    Handler = null,
                    Message = MessageDefinition.Create <SimpleMessage>()
                }
            });

            var actorWithPartition = new ConfigurableActor(new[]
            {
                new MessageHandlerDefinition
                {
                    Handler = null,
                    Message = MessageDefinition.Create <SimpleMessage>(partition)
                }
            });

            actorHandlersMap.Add(actorWithoutPartition);
            actorHandlersMap.Add(actorWithPartition);

            actorHandlersMap.Get(MessageIdentifier.Create(typeof(SimpleMessage), partition));
            actorHandlersMap.Get(MessageIdentifier.Create(typeof(SimpleMessage)));
        }
Exemple #2
0
        public void WhenDuplicatedKeyExceptionThrown_NonOfTheActorHandlersIsAdded()
        {
            var actorHandlersMap = new ActorHandlerMap();

            var simpleMessageActor = new ConfigurableActor(new[]
            {
                new MessageHandlerDefinition
                {
                    Handler = null,
                    Message = MessageDefinition.Create <SimpleMessage>()
                }
            });
            var exceptionMessageActor = new ConfigurableActor(new[]
            {
                new MessageHandlerDefinition
                {
                    Handler = null,
                    Message = MessageDefinition.Create <ExceptionMessage>()
                },
                new MessageHandlerDefinition
                {
                    Handler = null,
                    Message = MessageDefinition.Create <SimpleMessage>()
                }
            });

            actorHandlersMap.Add(simpleMessageActor);
            actorHandlersMap.Get(MessageIdentifier.Create <SimpleMessage>());

            Assert.Throws <DuplicatedKeyException>(() => { actorHandlersMap.Add(exceptionMessageActor); });

            actorHandlersMap.Get(MessageIdentifier.Create <SimpleMessage>());
            Assert.Throws <KeyNotFoundException>(() => actorHandlersMap.Get(MessageIdentifier.Create <ExceptionMessage>()));
        }
Exemple #3
0
        public void AddingActorsHandlingTheSameMessageTwice_ThowsDuplicatedKeyException()
        {
            var actorHandlersMap = new ActorHandlerMap();
            var actor            = new EchoActor();

            actorHandlersMap.Add(actor);
            Assert.Throws <DuplicatedKeyException>(() => { actorHandlersMap.Add(actor); });
        }
Exemple #4
0
        public void AddingActorWithoutRegisteredMessageHandlers_ThrowsNoException()
        {
            var actorHandlersMap = new ActorHandlerMap();
            var voidActor        = new ConfigurableActor(Enumerable.Empty <MessageHandlerDefinition>());

            actorHandlersMap.Add(voidActor);
        }
Exemple #5
0
        public void GettingHandlerForNonRegisteredMessageIdentifier_ThrowsKeyNotFoundException()
        {
            var actorHandlersMap = new ActorHandlerMap();
            var actor            = new EchoActor();

            actorHandlersMap.Add(actor);

            Assert.Throws <KeyNotFoundException>(() => actorHandlersMap.Get(new MessageIdentifier(KinoMessages.Exception)));
        }
Exemple #6
0
        public void CanAddReturnsFalse_IfActorAlreadyAdded()
        {
            var actorHandlersMap = new ActorHandlerMap();
            var actor            = new EchoActor();

            actorHandlersMap.Add(actor);

            Assert.False(actorHandlersMap.CanAdd(actor));
        }