Exemplo n.º 1
0
        public void RedisTest()
        {
            SubscriberRedis <TestEvent> subs = new SubscriberRedis <TestEvent>();

            subs.RedisSubscriptionSuccess += subs_RedisSubscriptionSuccess;
            subs.EventReceived            += subs_EventReceived;
            subs.EventHandled             += subs_EventHandled;

            subs.Subscribe();

            PublisherRedis <TestEvent> pub = new PublisherRedis <TestEvent>();

            pub.Publish(new TestEvent());

            if (!mre.WaitOne(TimeSpan.FromSeconds(10)))
            {
                Assert.Fail();
            }
            else
            {
                Assert.IsTrue(RedisSubscribed);
            }

            mre.Reset();

            if (!mre.WaitOne(TimeSpan.FromSeconds(10)))
            {
                Assert.Fail();
            }

            mre.Reset();

            (subs as IUnsubscribe).Unsubscribe();
        }
Exemplo n.º 2
0
        public void RedisCountMsgsTest()
        {
            SubscriberRedis<TestEvent> subs = new SubscriberRedis<TestEvent>();
            subs.RedisSubscriptionSuccess += subs_RedisSubscriptionSuccess2;
            subs.EventReceived += subs_EventReceived2;
            subs.EventHandled += subs_EventHandled2;

            subs.Subscribe();

            if (!mre.WaitOne(TimeSpan.FromSeconds(3)))
                Assert.Fail();

            new Thread(new ThreadStart(() =>
            {
                for (int i = 0; i < 10; i++)
                {
                    ThreadPool.QueueUserWorkItem((state) =>
                    {
                        PublisherRedis<TestEvent> pub = new PublisherRedis<TestEvent>();
                        pub.Publish(new TestEvent() { Data = DateTime.Now.ToString("hh:mm:ss") });
                        Thread.Sleep(950);
                    });
                }
            })).Start();

            if (!countEvent.Wait(TimeSpan.FromSeconds(15)))
            {
                Assert.Fail();
            }
            else
            {
                if (subs.GetTotalReceivedMsgs == 10)
                    (subs as IUnsubscribe).Unsubscribe();
            }
        }
Exemplo n.º 3
0
        public void RedisCountMsgsTest()
        {
            SubscriberRedis <TestEvent> subs = new SubscriberRedis <TestEvent>();

            subs.RedisSubscriptionSuccess += subs_RedisSubscriptionSuccess2;
            subs.EventReceived            += subs_EventReceived2;
            subs.EventHandled             += subs_EventHandled2;

            subs.Subscribe();

            if (!mre.WaitOne(TimeSpan.FromSeconds(3)))
            {
                Assert.Fail();
            }

            new Thread(new ThreadStart(() =>
            {
                for (int i = 0; i < 10; i++)
                {
                    ThreadPool.QueueUserWorkItem((state) =>
                    {
                        PublisherRedis <TestEvent> pub = new PublisherRedis <TestEvent>();
                        pub.Publish(new TestEvent()
                        {
                            Data = DateTime.Now.ToString("hh:mm:ss")
                        });
                        Thread.Sleep(950);
                    });
                }
            })).Start();

            if (!countEvent.Wait(TimeSpan.FromSeconds(15)))
            {
                Assert.Fail();
            }
            else
            {
                if (subs.GetTotalReceivedMsgs == 10)
                {
                    (subs as IUnsubscribe).Unsubscribe();
                }
            }
        }
Exemplo n.º 4
0
        public void RedisTest()
        {
            SubscriberRedis<TestEvent> subs = new SubscriberRedis<TestEvent>();
            subs.RedisSubscriptionSuccess += subs_RedisSubscriptionSuccess;
            subs.EventReceived += subs_EventReceived;
            subs.EventHandled += subs_EventHandled;

            subs.Subscribe();

            PublisherRedis<TestEvent> pub = new PublisherRedis<TestEvent>();
            pub.Publish(new TestEvent());

            if (!mre.WaitOne(TimeSpan.FromSeconds(10)))
                Assert.Fail();
            else
                Assert.IsTrue(RedisSubscribed);

            mre.Reset();

            if (!mre.WaitOne(TimeSpan.FromSeconds(10)))
                Assert.Fail();

            mre.Reset();

            (subs as IUnsubscribe).Unsubscribe();
        }