Beispiel #1
0
        public void TestDeferred()
        {
            Publicator p1 = new Publicator();

            Subscriber1 sub = new Subscriber1();

            sub.EventReceived += sub_EventReceived;
            sub.EventHandled  += sub_EventHandled;
            sub.Subscribe();

            ThreadPool.QueueUserWorkItem(state =>
            {
                Thread.Sleep(TimeSpan.FromSeconds(1));
                (state as IPublisher <DefferMessage2>).Publish(new DefferMessage2()
                {
                    Content = "Hello world"
                });
            }, p1);

            if (!countEvent.Wait(TimeSpan.FromMinutes(1)))
            {
                Assert.Fail();
            }

            sub.Dispose();
        }
Beispiel #2
0
        public void TestDeferred2()
        {
            countEvent.Reset(2);

            Publicator  p1 = new Publicator();
            Publicator2 p2 = new Publicator2();

            p1.Publish(new DefferMessage2()
            {
                Content = "Hello world"
            });
            p2.Publish(new DefferMessage1()
            {
                Data = "Hello world .........1221."
            });

            Subscriber1 sub = new Subscriber1();

            sub.EventReceived += sub_EventReceived;
            sub.EventHandled  += sub_EventHandled;

            Subscriber2 sub2 = new Subscriber2();

            sub2.EventReceived += sub_EventReceived2;
            sub2.EventHandled  += sub_EventHandled2;

            ThreadPool.QueueUserWorkItem(state =>
            {
                Thread.Sleep(TimeSpan.FromSeconds(5));
                sub.Subscribe();
            }, null);

            ThreadPool.QueueUserWorkItem(state =>
            {
                Thread.Sleep(TimeSpan.FromSeconds(3));
                sub2.Subscribe();
            }, null);

            if (!countEvent.Wait(TimeSpan.FromMinutes(2)))
            {
                Assert.Fail();
            }
            else
            {
                countEvent.Reset(18);
            }

            p1.Publish(new DefferMessage2()
            {
                Content = "Hello world"
            });
            p2.Publish(new DefferMessage1()
            {
                Data = "Hello world .........1221."
            });

            p1.Publish(new DefferMessage2()
            {
                Content = "Hello world"
            });
            p2.Publish(new DefferMessage1()
            {
                Data = "Hello world .........1221."
            });

            p1.Publish(new DefferMessage2()
            {
                Content = "Hello world"
            });
            p2.Publish(new DefferMessage1()
            {
                Data = "Hello world .........1221."
            });

            p1.Publish(new DefferMessage2()
            {
                Content = "Hello world"
            });
            p2.Publish(new DefferMessage1()
            {
                Data = "Hello world .........1221."
            });

            sub.Dispose();
            sub2.Dispose();
        }