コード例 #1
0
        public void HeterogeneityDispatchTest_有2個consumer_主動通知()
        {
            var queue = GetQueue();

            var dispatch = new HeterogeneityDispatch();

            dispatch.Binding(queue);

            var consumer1 = new IntConsumer();

            dispatch.Register(consumer1);
            var consumer2 = new StringConsumer();

            dispatch.Register(consumer2);

            Task.Factory.StartNew(() => dispatch.Notice());

            Thread.Sleep(200);

            (new[] { 24, 36 }).ToExpectedObject().ShouldEqual(consumer1.Queue.ToArray());

            (new[] { "Flora MQ", "Message Queue" }).ToExpectedObject().ShouldEqual(consumer2.Queue.ToArray());
        }
コード例 #2
0
        public void HeterogeneityDispatchTest_兩個consumer依順序取值()
        {
            var queue = GetQueue();

            var dispatch = new HeterogeneityDispatch();

            dispatch.Binding(queue);

            var consumer1 = new IntConsumer();

            dispatch.Register(consumer1);
            var consumer2 = new StringConsumer();

            dispatch.Register(consumer2);

            consumer1.DoWork();
            consumer2.DoWork();
            consumer1.DoWork();
            consumer2.DoWork();

            (new[] { 24, 36 }).ToExpectedObject().ShouldEqual(consumer1.Queue.ToArray());

            (new[] { "Flora MQ", "Message Queue" }).ToExpectedObject().ShouldEqual(consumer2.Queue.ToArray());
        }
コード例 #3
0
        public void HeterogeneityDispatchTest_當只有一個consume取值時()
        {
            var queue = GetQueue();

            var dispatch = new HeterogeneityDispatch();

            dispatch.Binding(queue);

            var consumer1 = new IntConsumer();

            dispatch.Register(consumer1);
            var consumer2 = new StringConsumer();

            dispatch.Register(consumer2);

            consumer1.DoWork();
            consumer1.DoWork();
            consumer1.DoWork();
            consumer1.DoWork();

            (new[] { 24 }).ToExpectedObject().ShouldEqual(consumer1.Queue.ToArray());

            (new string[] { }).ToExpectedObject().ShouldEqual(consumer2.Queue.ToArray());
        }