예제 #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)));
        }
예제 #2
0
        public void Provider_should_return_all_matching_sla_definitions_for_given_response()
        {
            var provider = new SlaProvider();

            var def1 = new SlaDefinition(
                MessageDefinition.Create <IRequestOne>(r => r.OneId),
                MessageDefinition.Create <IResponseOne>(r => r.Id),
                TimeSpan.FromSeconds(1));

            var def2 = new SlaDefinition(
                MessageDefinition.Create <IRequestTwo>(r => r.TwoId),
                MessageDefinition.Create <IResponseTwo>(r => r.Id),
                TimeSpan.FromSeconds(2));

            var def3 = new SlaDefinition(
                MessageDefinition.Create <IExtendedRequestOne>(r => r.OneId),
                MessageDefinition.Create <IResponseOne>(r => r.Id),
                TimeSpan.FromSeconds(3));

            var def4 = new SlaDefinition(
                MessageDefinition.Create <IRequestOne>(r => r.OneId),
                MessageDefinition.Create <IExtendedResponseOne>(r => r.Id),
                TimeSpan.FromSeconds(3));

            provider.Add(def1);
            provider.Add(def2);
            provider.Add(def3);
            provider.Add(def4);

            var definitions = provider.GetSlaDefinitionsFor(new Mock <IExtendedResponseOne>().Object);

            Assert.That(definitions.ToArray(), Is.EquivalentTo(new[] { def1, def3, def4 }));
        }
예제 #3
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>()));
        }
 public override IEnumerable <MessageHandlerDefinition> GetInterfaceDefinition()
 => new[]
 {
     new MessageHandlerDefinition
     {
         Message = MessageDefinition.Create <LeaseRequestMessage>(clusterName),
         Handler = GetLease
     }
 };
예제 #5
0
        public void Definition_should_allow_to_retrieve_proper_correlation_id()
        {
            var message = new TestMessage {
                FirstId = Guid.NewGuid(), SecondId = Guid.NewGuid()
            };
            var def1 = MessageDefinition.Create <TestMessage>(m => m.FirstId);
            var def2 = MessageDefinition.Create <TestMessage>(m => m.SecondId);

            Assert.That(def1.GetCorrelationId(message), Is.EqualTo(message.FirstId), "It should use FirstId");
            Assert.That(def2.GetCorrelationId(message), Is.EqualTo(message.SecondId), "It should use SecondId");
        }
예제 #6
0
 public override IEnumerable <MessageHandlerDefinition> GetInterfaceDefinition()
 => new[]
 {
     new MessageHandlerDefinition
     {
         Message = MessageDefinition.Create <InternalDiscoverLeaseProviderInstancesRequestMessage>(clusterName),
         Handler = InternalDiscoverLeaseProviderInstancesRequest
     },
     new MessageHandlerDefinition
     {
         Message = MessageDefinition.Create <InternalDiscoverLeaseProviderInstancesResponseMessage>(clusterName),
         Handler = InternalDiscoverLeaseProviderInstancesResponse
     }
 };
예제 #7
0
 public override IEnumerable <MessageHandlerDefinition> GetInterfaceDefinition()
 {
     return(new[]
     {
         new MessageHandlerDefinition
         {
             Message = MessageDefinition.Create <CreateLeaseProviderInstanceRequestMessage>(clusterName),
             Handler = CreateLeaseProviderInstance
         },
         new MessageHandlerDefinition
         {
             Message = MessageDefinition.Create <InternalCreateLeaseProviderInstanceRequestMessage>(clusterName),
             Handler = InternalCreateLeaseProviderInstance
         }
     });
 }
예제 #8
0
        public void Provider_should_return_one_request_definition_if_multiple_slas_are_referring_to_the_same_request()
        {
            var provider = new SlaProvider();

            var requestDefinition = MessageDefinition.Create <IRequestOne>(r => r.OneId);

            var def1 = new SlaDefinition(
                requestDefinition,
                MessageDefinition.Create <IResponseOne>(r => r.Id),
                TimeSpan.FromSeconds(1));

            var def2 = new SlaDefinition(
                requestDefinition,
                MessageDefinition.Create <IResponseTwo>(r => r.Id),
                TimeSpan.FromSeconds(2));

            provider.Add(def1);
            provider.Add(def2);

            Assert.That(provider.GetRequestDefinitions(new Mock <IRequestOne>().Object).ToArray(), Is.EqualTo(new[] { requestDefinition }));
        }
예제 #9
0
 public void Definition_should_not_allow_to_use_null_to_retrieve_correlation_id()
 {
     Assert.Throws <ArgumentNullException>(() => MessageDefinition.Create <TestMessage>(x => x.FirstId).GetCorrelationId(null));
 }
예제 #10
0
        public void Definition_should_not_allow_to_use_wrong_message_type_to_retrieve_correlation_id()
        {
            var exception = Assert.Throws <InvalidOperationException>(() => MessageDefinition.Create <TestMessage>(x => x.FirstId).GetCorrelationId(""));

            Assert.That(exception.Message, Is.EqualTo(string.Format("The specified message is not of {0} type: {1}", typeof(TestMessage), typeof(string))));
        }
예제 #11
0
        public void Definition_should_contain_a_proper_message_type()
        {
            var definition = MessageDefinition.Create <TestMessage>(m => m.FirstId);

            Assert.That(definition.Type, Is.EqualTo(typeof(TestMessage)));
        }