Пример #1
0
        public async Task TestMessageQueue()
        {
            var logger = new MockLogger();

            var container = new Container(configuration => configuration.AddRegistry <BusRegistry>());

            var messages = Enumerable.Range(0, 50)
                           .Select(_ => new TestMessage())
                           .Select(msg => new MessageDispatch(msg));

            var queue = new DispatchQueue(logger, 10, "TestQueue");
            var cache = container.GetInstance <IMessageHandlerInvokerCache>();

            Assert.AreEqual(0, TestsMessageDispatchingContext.Get());

            queue.Start();

            foreach (var dispatch in messages)
            {
                var type    = typeof(IMessageHandler <>).MakeGenericType(dispatch.Message.GetType());
                var invoker = new MessageHandlerInvoker(cache, MessageHandlerInvokerMode.Synchronous, type);
                queue.RunOrEnqueue(dispatch, invoker);
            }

            await Task.Delay(1000);

            Assert.AreEqual(100, TestsMessageDispatchingContext.Get());
        }
Пример #2
0
        public async Task TestMessageDispatcher()
        {
            var logger = new MockLogger();

            var container = new Container(configuration => configuration.AddRegistry <BusRegistry>());

            var messages1 = Enumerable.Range(0, 50)
                            .Select(_ => new TestMessage())
                            .Select(msg => new MessageDispatch(msg))
                            .ToList();

            var messages2 = Enumerable.Range(0, 100)
                            .Select(_ => new TestMessage2())
                            .Select(msg => new MessageDispatch(msg))
                            .ToList();


            Assert.AreEqual(0, TestsMessageDispatchingContext.Get());
            Assert.AreEqual(0, TestsMessageDispatchingContext2.Get());

            var messageDispatcher = new MessageDispatcher(logger, container);

            messageDispatcher.Dispatch(messages1.Concat(messages2).ToList());

            await Task.Delay(1000);

            Assert.AreEqual(100, TestsMessageDispatchingContext.Get());

            Assert.AreEqual(100, TestsMessageDispatchingContext2.Get());
        }
Пример #3
0
 public void Handle(TestMessage message)
 {
     TestsMessageDispatchingContext.Increment();
 }
Пример #4
0
 public void SetUp()
 {
     TestsMessageDispatchingContext.Reset();
     TestsMessageDispatchingContext2.Reset();
 }