public void DenyWhileChangingOfRunningMessageConsumer()
		{
			IMessageSource<TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate);
			var factory = new TestRouterFactory(new Waiter(waitablesCount: 1), messages => messages.CheckOrder(TestRouterHelper.Sequence(0, TestRouterHelper.MessagesCountToGenerate)));
			using (IMessageConsumer<TestMessage> consumer = factory.CreateConsumer(source))
			{
				consumer.Consume(TestRouterHelper.HandleMessage);
				consumer.While = null;
			}
		}
		public void CheckOrderTest()
		{
			IMessageSource<TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate);
			var waiter = new Waiter(waitablesCount:1);
			var factory = new TestRouterFactory(waiter, messages => messages.CheckOrder(TestRouterHelper.Sequence(0, TestRouterHelper.MessagesCountToGenerate)));
			using(IMessageConsumer<TestMessage> consumer = factory.CreateConsumer(source))
			{
				consumer.Consume(TestRouterHelper.HandleMessage);
				waiter.Wait(true);
			}
		}
Esempio n. 3
0
        public void DenyWhileChangingOfRunningMessageConsumer()
        {
            IMessageSource <TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate);
            var factory = new TestRouterFactory(new Waiter(waitablesCount: 1), messages => messages.CheckOrder(TestRouterHelper.Sequence(0, TestRouterHelper.MessagesCountToGenerate)));

            using (IMessageConsumer <TestMessage> consumer = factory.CreateConsumer(source))
            {
                consumer.Consume(TestRouterHelper.HandleMessage);
                consumer.While = null;
            }
        }
		public void SwallowExceptionTest()
		{
			const int errorMessageIndex = 5;
			var waiter = new Waiter(waitablesCount:1);
			IMessageSource<TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate, errorMessageIndex, swallowException:true);
			var factory = new TestRouterFactory(waiter, messages => messages.CheckOrder(TestRouterHelper.SequenceExcluding(0, TestRouterHelper.MessagesCountToGenerate, errorMessageIndex)));
			using (IMessageConsumer<TestMessage> consumer = factory.CreateConsumer(source))
			{
				consumer.Consume(TestRouterHelper.HandleMessage);
				waiter.Wait(true);
			}
		}
Esempio n. 5
0
        public void CheckOrderTest()
        {
            IMessageSource <TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate);
            var waiter  = new Waiter(waitablesCount: 1);
            var factory = new TestRouterFactory(waiter, messages => messages.CheckOrder(TestRouterHelper.Sequence(0, TestRouterHelper.MessagesCountToGenerate)));

            using (IMessageConsumer <TestMessage> consumer = factory.CreateConsumer(source))
            {
                consumer.Consume(TestRouterHelper.HandleMessage);
                waiter.Wait(true);
            }
        }
Esempio n. 6
0
        public void SwallowExceptionTest()
        {
            const int errorMessageIndex         = 5;
            var       waiter                    = new Waiter(waitablesCount: 1);
            IMessageSource <TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate, errorMessageIndex, swallowException: true);
            var factory = new TestRouterFactory(waiter, messages => messages.CheckOrder(TestRouterHelper.SequenceExcluding(0, TestRouterHelper.MessagesCountToGenerate, errorMessageIndex)));

            using (IMessageConsumer <TestMessage> consumer = factory.CreateConsumer(source))
            {
                consumer.Consume(TestRouterHelper.HandleMessage);
                waiter.Wait(true);
            }
        }
		public void ChildrenOrderTest()
		{
			const int sourcesCount = 5;
			IMessageSource<TestMessage> source = MessageGenerator.CreateCompositeSource(TestRouterHelper.SourceName, sourcesCount, TestRouterHelper.MessagesCountToGenerate);
			var waiter = new Waiter(sourcesCount);
			var factory = new TestRouterFactory(waiter, messages => messages.CheckOrder(TestRouterHelper.Sequence(0, TestRouterHelper.MessagesCountToGenerate)));
			using (IMessageConsumer<TestMessage> router = factory.CreateRouter(source, factory, m => m.Tag))
			{
				router.Consume(TestRouterHelper.HandleMessage);
				waiter.Wait(true);
				// we compare to 55, not 50, because each source has stop message at the end.
				((TestMessageRouter) router).ReceiveCallCount.Should(Be.EqualTo(55)); 
			}
		}
		public void CheckIsRunningTest()
		{
			IMessageSource<TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate);
			var waiter = new Waiter(waitablesCount:1);
			var factory = new TestRouterFactory(waiter, messages =>{});
			using (IMessageConsumer<TestMessage> consumer = factory.CreateConsumer(source))
			{
				consumer.IsRunning.Should(Be.False, "consumer.IsRunning.Should(Be.False)");
				consumer.Consume(TestRouterHelper.HandleMessage);
				consumer.IsRunning.Should(Be.True, "consumer.IsRunning.Should(Be.True)");
				waiter.Wait();
				consumer.IsRunning.Should(Be.True, "consumer.IsRunning.Should(Be.True)");
			}
		}
Esempio n. 9
0
        public void CheckIsRunningTest()
        {
            IMessageSource <TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate);
            var waiter  = new Waiter(waitablesCount: 1);
            var factory = new TestRouterFactory(waiter, messages => {});

            using (IMessageConsumer <TestMessage> consumer = factory.CreateConsumer(source))
            {
                consumer.IsRunning.Should(Be.False);
                consumer.Consume(TestRouterHelper.HandleMessage);
                consumer.IsRunning.Should(Be.True);
                waiter.Wait();
                consumer.IsRunning.Should(Be.True);
            }
        }
Esempio n. 10
0
        public void ChildrenOrderTest()
        {
            const int sourcesCount = 5;
            IMessageSource <TestMessage> source = MessageGenerator.CreateCompositeSource(TestRouterHelper.SourceName, sourcesCount, TestRouterHelper.MessagesCountToGenerate);
            var waiter  = new Waiter(sourcesCount);
            var factory = new TestRouterFactory(waiter, messages => messages.CheckOrder(TestRouterHelper.Sequence(0, TestRouterHelper.MessagesCountToGenerate)));

            using (IMessageConsumer <TestMessage> router = factory.CreateRouter(source, factory, m => m.Tag))
            {
                router.Consume(TestRouterHelper.HandleMessage);
                waiter.Wait(true);
                // we compare to 55, not 50, because each source has stop message at the end.
                ((TestMessageRouter)router).ReceiveCallCount.Should(Be.EqualTo(55));
            }
        }
		public void RouterShouldHandleMessagesIfTagIsNotProvided()
		{
			IMessageSource<TestMessage> source = MessageGenerator.CreateSource(string.Empty, 5);
			var waiter = new Waiter(1);
			var factory = new TestRouterFactory(waiter, messages => { });
			using (IMessageConsumer<TestMessage> router = factory.CreateRouter(source, factory, m => m.Tag))
			{
				var messagesHandled = 0;
				waiter.Register(router);
				router.While = m => TestMessage.IsNotStopMessage(string.Empty, m);
				router.Consume(message => messagesHandled++);
				waiter.Wait(true);

				messagesHandled.Should(Be.EqualTo(6));
				//Do not receive message from queue, if router handles message by itself. Let the handle logic do this.
				((TestMessageRouter)router).ReceiveCallCount.Should(Be.EqualTo(0));
			}
		}
Esempio n. 12
0
        public void RouterShouldHandleMessagesIfTagIsNotProvided()
        {
            IMessageSource <TestMessage> source = MessageGenerator.CreateSource(string.Empty, 5);
            var waiter  = new Waiter(1);
            var factory = new TestRouterFactory(waiter, messages => { });

            using (IMessageConsumer <TestMessage> router = factory.CreateRouter(source, factory, m => m.Tag))
            {
                var messagesHandled = 0;
                waiter.Register(router);
                router.While = m => TestMessage.IsNotStopMessage(string.Empty, m);
                router.Consume(message => messagesHandled++);
                waiter.Wait(true);

                messagesHandled.Should(Be.EqualTo(6));
                //Do not receive message from queue, if router handles message by itself. Let the handle logic do this.
                ((TestMessageRouter)router).ReceiveCallCount.Should(Be.EqualTo(0));
            }
        }