예제 #1
0
        public void Establish()
        {
            _commandProcessor = new SpyRequeueCommandProcessor();
            _channel          = new FakeChannel();
            var mapper = new MyEventMessageMapper();

            _messagePump = new MessagePump <MyEvent>(_commandProcessor, mapper)
            {
                Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = 3
            };

            _event = new MyEvent();

            var message1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(_event)));
            var message2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(_event)));

            _channel.Add(message1);
            _channel.Add(message2);
        }
        public void Establish()
        {
            _commandProcessor = new SpyCommandProcessor();
            _channel          = new FakeChannel();
            var mapper      = new MyEventMessageMapper();
            var messagePump = new MessagePump <MyEvent>(_commandProcessor, mapper);

            messagePump.Channel = _channel;
            messagePump.TimeoutInMilliseconds = 5000;

            var @event  = new MyEvent();
            var message = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(@event)));

            _channel.Add(message);

            _performer     = new Performer(_channel, messagePump);
            _performerTask = _performer.Run();
            _performer.Stop();
        }
예제 #3
0
        public void When_A_Message_Dispatcher_Restarts_A_Connection_After_All_Connections_Have_Stopped()
        {
            _dispatcher.Open("newTest");
            var @event  = new MyEvent();
            var message = new MyEventMessageMapper().MapToMessage(@event);

            _channel.Enqueue(message);
            Task.Delay(1000).Wait();


            //_should_have_consumed_the_messages_in_the_event_channel
            _channel.Length.Should().Be(0);
            //_should_have_a_running_state
            _dispatcher.State.Should().Be(DispatcherState.DS_RUNNING);
            //_should_have_only_one_consumer
            _dispatcher.Consumers.Should().HaveCount(1);
            //_should_have_two_connections
            _dispatcher.Connections.Should().HaveCount(2);
        }
        public MessagePumpEventRequeueCountThresholdTests()
        {
            _commandProcessor = new SpyRequeueCommandProcessor();
            _channel          = new FakeChannel();
            var mapper = new MyEventMessageMapper();

            _messagePump = new MessagePumpBlocking <MyEvent>(_commandProcessor, mapper)
            {
                Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = 3
            };

            _event = new MyEvent();

            var message1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonSerializer.Serialize(_event, JsonSerialisationOptions.Options)));
            var message2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonSerializer.Serialize(_event, JsonSerialisationOptions.Options)));

            _channel.Enqueue(message1);
            _channel.Enqueue(message2);
        }
예제 #5
0
        public void When_A_Message_Dispatcher_Restarts_A_Connection_After_All_Connections_Have_Stopped()
        {
            _dispatcher.Open("newTest");
            var @event  = new MyEvent();
            var message = new MyEventMessageMapper().MapToMessage(@event);

            _channel.Add(message);
            Task.Delay(1000).Wait();


            //_should_have_consumed_the_messages_in_the_event_channel
            Assert.AreEqual(0, _channel.Length);
            //_should_have_a_running_state
            Assert.AreEqual(DispatcherState.DS_RUNNING, _dispatcher.State);
            //_should_have_only_one_consumer
            Assert.AreEqual(1, _dispatcher.Consumers.Count());
            //_should_have_two_connections
            Assert.AreEqual(2, _dispatcher.Connections.Count());
        }
예제 #6
0
        public void When_A_Message_Dispatcher_Has_A_New_Connection_Added_While_Running()
        {
            _dispatcher.Open(_newSubscription);

            var @event  = new MyEvent();
            var message = new MyEventMessageMapper().MapToMessage(@event);

            _channel.Enqueue(message);

            Task.Delay(1000).Wait();

            //_should_have_consumed_the_messages_in_the_event_channel
            _channel.Length.Should().Be(0);
            //_should_have_a_running_state
            _dispatcher.State.Should().Be(DispatcherState.DS_RUNNING);
            //_should_have_only_one_consumer
            _dispatcher.Consumers.Should().HaveCount(2);
            //_should_have_two_connections
            _dispatcher.Connections.Should().HaveCount(2);
        }
        public MessagePumpToCommandProcessorTests()
        {
            _commandProcessor = new SpyCommandProcessor();
            _channel          = new FakeChannel();
            var mapper = new MyEventMessageMapper();

            _messagePump = new MessagePump <MyEvent>(_commandProcessor, mapper)
            {
                Channel = _channel, TimeoutInMilliseconds = 5000
            };

            _event = new MyEvent();

            var message = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonSerializer.Serialize(_event, JsonSerialisationOptions.Options)));

            _channel.Enqueue(message);
            var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody(""));

            _channel.Enqueue(quitMessage);
        }
        public MessagePumpUnacceptableMessageLimitBreachedTests()
        {
            _commandProcessor = new SpyRequeueCommandProcessor();
            _channel          = new FakeChannel();
            var mapper = new MyEventMessageMapper();

            _messagePump = new MessagePump <MyEvent>(_commandProcessor, mapper)
            {
                Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = 3, UnacceptableMessageLimit = 3
            };

            var unacceptableMessage1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_UNACCEPTABLE), new MessageBody(""));
            var unacceptableMessage2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_UNACCEPTABLE), new MessageBody(""));
            var unacceptableMessage3 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_UNACCEPTABLE), new MessageBody(""));
            var unacceptableMessage4 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_UNACCEPTABLE), new MessageBody(""));

            _channel.Enqueue(unacceptableMessage1);
            _channel.Enqueue(unacceptableMessage2);
            _channel.Enqueue(unacceptableMessage3);
            _channel.Enqueue(unacceptableMessage4);
        }
        public MessagePumpEventRequeueTests()
        {
            _commandProcessor = new SpyRequeueCommandProcessor();
            _channel          = new FakeChannel();
            var mapper = new MyEventMessageMapper();

            _messagePump = new MessagePump <MyEvent>(_commandProcessor, mapper)
            {
                Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = -1
            };

            _event = new MyEvent();

            var message1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(_event)));
            var message2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(_event)));

            _channel.Enqueue(message1);
            _channel.Enqueue(message2);
            var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody(""));

            _channel.Enqueue(quitMessage);
        }
예제 #10
0
        public MessageDispatcherResetConnection()
        {
            _channel          = new FakeChannel();
            _commandProcessor = new SpyCommandProcessor();

            var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory((_) => new MyEventMessageMapper()));

            messageMapperRegistry.Register <MyEvent, MyEventMessageMapper>();

            _subscription = new Subscription <MyEvent>(new SubscriptionName("test"), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: new RoutingKey("fakekey"));
            _dispatcher   = new Dispatcher(_commandProcessor, messageMapperRegistry, new List <Subscription> {
                _subscription
            });

            var @event  = new MyEvent();
            var message = new MyEventMessageMapper().MapToMessage(@event);

            _channel.Enqueue(message);

            _dispatcher.State.Should().Be(DispatcherState.DS_AWAITING);
            _dispatcher.Receive();
        }
        public void Establish()
        {
            _channel          = new FakeChannel();
            _commandProcessor = new SpyCommandProcessor();

            var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory(() => new MyEventMessageMapper()));

            messageMapperRegistry.Register <MyEvent, MyEventMessageMapper>();

            _connection    = new Connection(name: new ConnectionName("test"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: "fakekey");
            _newConnection = new Connection(name: new ConnectionName("newTest"), dataType: typeof(MyEvent), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_channel), channelName: new ChannelName("fakeChannel"), routingKey: "fakekey");
            _dispatcher    = new Dispatcher(_commandProcessor, messageMapperRegistry, new List <Connection> {
                _connection
            });

            var @event  = new MyEvent();
            var message = new MyEventMessageMapper().MapToMessage(@event);

            _channel.Add(message);

            Assert.AreEqual(DispatcherState.DS_AWAITING, _dispatcher.State);
            _dispatcher.Receive();
        }
예제 #12
0
        public MessageDispatcherMultipleConnectionTests()
        {
            _eventChannel   = new FakeChannel();
            _commandChannel = new FakeChannel();
            var commandProcessor = new SpyCommandProcessor();

            var container = new ServiceCollection();

            container.AddTransient <MyEventMessageMapper>();
            container.AddTransient <MyCommandMessageMapper>();

            var messageMapperRegistry = new MessageMapperRegistry(new ServiceProviderMapperFactory(container.BuildServiceProvider()));

            messageMapperRegistry.Register <MyEvent, MyEventMessageMapper>();
            messageMapperRegistry.Register <MyCommand, MyCommandMessageMapper>();


            var myEventConnection   = new Subscription <MyEvent>(new SubscriptionName("test"), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_eventChannel), channelName: new ChannelName("fakeChannel"), routingKey: new RoutingKey("fakekey"));
            var myCommandConnection = new Subscription <MyCommand>(new SubscriptionName("anothertest"), noOfPerformers: 1, timeoutInMilliseconds: 1000, channelFactory: new InMemoryChannelFactory(_commandChannel), channelName: new ChannelName("fakeChannel"), routingKey: new RoutingKey("fakekey"));

            _dispatcher = new Dispatcher(commandProcessor, messageMapperRegistry, new List <Subscription> {
                myEventConnection, myCommandConnection
            });

            var @event       = new MyEvent();
            var eventMessage = new MyEventMessageMapper().MapToMessage(@event);

            _eventChannel.Enqueue(eventMessage);

            var command        = new MyCommand();
            var commandMessage = new MyCommandMessageMapper().MapToMessage(command);

            _commandChannel.Enqueue(commandMessage);

            _dispatcher.State.Should().Be(DispatcherState.DS_AWAITING);
            _dispatcher.Receive();
        }
예제 #13
0
        public MessagePumpRetryEventConnectionFailureTests()
        {
            _commandProcessor = new SpyCommandProcessor();
            _channel          = new FailingChannel {
                NumberOfRetries = 4
            };
            var mapper = new MyEventMessageMapper();

            _messagePump = new MessagePump <MyEvent>(_commandProcessor, mapper)
            {
                Channel = _channel, TimeoutInMilliseconds = 5000, RequeueCount = -1
            };

            _event = new MyEvent();

            var message1 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(_event)));
            var message2 = new Message(new MessageHeader(Guid.NewGuid(), "MyTopic", MessageType.MT_EVENT), new MessageBody(JsonConvert.SerializeObject(_event)));

            _channel.Add(message1);
            _channel.Add(message2);
            var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody(""));

            _channel.Add(quitMessage);
        }