示例#1
0
        public void AddingEventAndSendingMessages()
        {
            var         dr           = new DefaultDependencyResolver();
            var         bus          = new MessageBus(dr);
            var         subscriber   = new Subscriber(new[] { "a" });
            int         max          = 100;
            var         cd           = new CountDownRange <int>(Enumerable.Range(0, max));
            int         prev         = -1;
            IDisposable subscription = null;

            try
            {
                subscription = bus.Subscribe(subscriber, null, result =>
                {
                    foreach (var m in EnumerateMessages(result))
                    {
                        int n = Int32.Parse(m.Value);
                        Assert.True(prev < n, "out of order");
                        prev = n;
                        Assert.True(cd.Mark(n));
                    }

                    return(TaskAsyncHelper.True);
                }, 10);

                for (int i = 0; i < max; i++)
                {
                    subscriber.AddEvent("b");
                    bus.Publish("test", "b", i.ToString()).Wait();
                }

                Assert.True(cd.Wait(TimeSpan.FromSeconds(10)));
            }
            finally
            {
                if (subscription != null)
                {
                    subscription.Dispose();
                }
            }
        }
示例#2
0
        public void AddingEventAndSendingMessages()
        {
            var dr = new DefaultDependencyResolver();
            var bus = new MessageBus(dr);
            var subscriber = new Subscriber(new[] { "a" });
            int max = 100;
            var cd = new CountDownRange<int>(Enumerable.Range(0, max));
            int prev = -1;
            IDisposable subscription = null;

            try
            {
                subscription = bus.Subscribe(subscriber, null, result =>
                {
                    foreach (var m in EnumerateMessages(result))
                    {
                        int n = Int32.Parse(m.Value);
                        Assert.True(prev < n, "out of order");
                        prev = n;
                        Assert.True(cd.Mark(n));
                    }

                    return TaskAsyncHelper.True;
                }, 10);

                for (int i = 0; i < max; i++)
                {
                    subscriber.AddEvent("b");
                    bus.Publish("test", "b", i.ToString()).Wait();
                }

                Assert.True(cd.Wait(TimeSpan.FromSeconds(10)));
            }
            finally
            {
                if (subscription != null)
                {
                    subscription.Dispose();
                }
            }
        }