コード例 #1
0
        public void TestClose()
        {
            MessageDispatchChannel channel = new MessageDispatchChannel();

            channel.Start();
            Assert.IsTrue(channel.Running == true);
            Assert.IsTrue(channel.Closed == false);
            channel.Close();
            Assert.IsTrue(channel.Running == false);
            Assert.IsTrue(channel.Closed == true);
            channel.Start();
            Assert.IsTrue(channel.Running == false);
            Assert.IsTrue(channel.Closed == true);
        }
コード例 #2
0
        public void TestDequeue()
        {
            MessageDispatchChannel channel = new MessageDispatchChannel();

            MessageDispatch dispatch1 = new MessageDispatch();
            MessageDispatch dispatch2 = new MessageDispatch();
            MessageDispatch dispatch3 = new MessageDispatch();

            channel.Start();
            Assert.IsTrue(channel.Running == true);

            DateTime timeStarted = DateTime.Now;

            Assert.IsTrue(channel.Dequeue(TimeSpan.FromMilliseconds(1000)) == null);

            DateTime timeFinished = DateTime.Now;

            TimeSpan elapsed = timeFinished - timeStarted;

            Assert.IsTrue(elapsed.TotalMilliseconds >= 999);

            channel.Enqueue(dispatch1);
            channel.Enqueue(dispatch2);
            channel.Enqueue(dispatch3);
            Assert.IsTrue(channel.Empty == false);
            Assert.IsTrue(channel.Count == 3);
            Assert.IsTrue(channel.Dequeue(TimeSpan.FromMilliseconds(Timeout.Infinite)) == dispatch1);
            Assert.IsTrue(channel.Dequeue(TimeSpan.Zero) == dispatch2);
            Assert.IsTrue(channel.Dequeue(TimeSpan.FromMilliseconds(1000)) == dispatch3);

            Assert.IsTrue(channel.Count == 0);
            Assert.IsTrue(channel.Empty == true);
        }
コード例 #3
0
        public void TestDequeueNoWait()
        {
            MessageDispatchChannel channel = new MessageDispatchChannel();

            MessageDispatch dispatch1 = new MessageDispatch();
            MessageDispatch dispatch2 = new MessageDispatch();
            MessageDispatch dispatch3 = new MessageDispatch();

            Assert.IsTrue(channel.Running == false);
            Assert.IsTrue(channel.DequeueNoWait() == null);

            channel.Enqueue(dispatch1);
            channel.Enqueue(dispatch2);
            channel.Enqueue(dispatch3);

            Assert.IsTrue(channel.DequeueNoWait() == null);
            channel.Start();
            Assert.IsTrue(channel.Running == true);

            Assert.IsTrue(channel.Empty == false);
            Assert.IsTrue(channel.Count == 3);
            Assert.IsTrue(channel.DequeueNoWait() == dispatch1);
            Assert.IsTrue(channel.DequeueNoWait() == dispatch2);
            Assert.IsTrue(channel.DequeueNoWait() == dispatch3);

            Assert.IsTrue(channel.Count == 0);
            Assert.IsTrue(channel.Empty == true);
        }
コード例 #4
0
        public void TestPeek()
        {
            MessageDispatchChannel channel   = new MessageDispatchChannel();
            MessageDispatch        dispatch1 = new MessageDispatch();
            MessageDispatch        dispatch2 = new MessageDispatch();

            Assert.IsTrue(channel.Empty == true);
            Assert.IsTrue(channel.Count == 0);

            channel.EnqueueFirst(dispatch1);

            Assert.IsTrue(channel.Empty == false);
            Assert.IsTrue(channel.Count == 1);

            channel.EnqueueFirst(dispatch2);

            Assert.IsTrue(channel.Empty == false);
            Assert.IsTrue(channel.Count == 2);

            Assert.IsTrue(channel.Peek() == null);

            channel.Start();

            Assert.IsTrue(channel.Peek() == dispatch2);
            Assert.IsTrue(channel.DequeueNoWait() == dispatch2);
            Assert.IsTrue(channel.Peek() == dispatch1);
            Assert.IsTrue(channel.DequeueNoWait() == dispatch1);
        }
コード例 #5
0
        public void Start()
        {
            if (_unconsumedMessages.Stopped)
            {
                return;
            }

            _started.Value = true;
            _unconsumedMessages.Start();
            _session.Executor.Wakeup();
        }
コード例 #6
0
        public void Start()
        {
            if (!messageQueue.Running)
            {
                messageQueue.Start();

                if (HasUncomsumedMessages)
                {
                    this.Wakeup();
                }
            }
        }
コード例 #7
0
        public void Start()
        {
            if (_messageQueue.Started)
            {
                return;
            }
            _messageQueue.Start();

            if (HasUncomsumedMessages)
            {
                Wakeup();
            }
        }
コード例 #8
0
        public void TestRemoveAll()
        {
            MessageDispatchChannel channel = new MessageDispatchChannel();

            MessageDispatch dispatch1 = new MessageDispatch();
            MessageDispatch dispatch2 = new MessageDispatch();
            MessageDispatch dispatch3 = new MessageDispatch();

            channel.Enqueue(dispatch1);
            channel.Enqueue(dispatch2);
            channel.Enqueue(dispatch3);

            channel.Start();
            Assert.IsTrue(channel.Running == true);
            Assert.IsTrue(channel.Empty == false);
            Assert.IsTrue(channel.Count == 3);
            Assert.IsTrue(channel.RemoveAll().Length == 3);
            Assert.IsTrue(channel.Count == 0);
            Assert.IsTrue(channel.Empty == true);
        }