示例#1
0
        public virtual void TestClear()
        {
            SinkQueue <int> q = new SinkQueue <int>(128);

            for (int i = 0; i < q.Capacity() + 97; ++i)
            {
                q.Enqueue(i);
            }
            Assert.Equal("queue size", q.Capacity(), q.Size());
            q.Clear();
            Assert.Equal("queue size", 0, q.Size());
        }
示例#2
0
        public virtual void TestHangingConsumer()
        {
            SinkQueue <int> q = NewSleepingConsumerQueue(2, 1, 2);

            Assert.Equal("queue back", 2, (int)q.Back());
            Assert.True("should drop", !q.Enqueue(3));
            // should not block
            Assert.Equal("queue size", 2, q.Size());
            Assert.Equal("queue head", 1, (int)q.Front());
            Assert.Equal("queue back", 2, (int)q.Back());
        }
示例#3
0
        public virtual void TestFull()
        {
            SinkQueue <int> q = new SinkQueue <int>(1);

            q.Enqueue(1);
            Assert.True("should drop", !q.Enqueue(2));
            Assert.Equal("element", 1, (int)q.Dequeue());
            q.Enqueue(3);
            q.Consume(new _Consumer_114());
            Assert.Equal("queue size", 0, q.Size());
        }
示例#4
0
        public virtual void TestCommon()
        {
            SinkQueue <int> q = new SinkQueue <int>(2);

            q.Enqueue(1);
            Assert.Equal("queue front", 1, (int)q.Front());
            Assert.Equal("queue back", 1, (int)q.Back());
            Assert.Equal("element", 1, (int)q.Dequeue());
            Assert.True("should enqueue", q.Enqueue(2));
            q.Consume(new _Consumer_50());
            Assert.True("should enqueue", q.Enqueue(3));
            Assert.Equal("element", 3, (int)q.Dequeue());
            Assert.Equal("queue size", 0, q.Size());
            Assert.Equal("queue front", null, q.Front());
            Assert.Equal("queue back", null, q.Back());
        }
示例#5
0
        public virtual void TestConcurrentConsumers()
        {
            SinkQueue <int> q = NewSleepingConsumerQueue(2, 1);

            Assert.True("should enqueue", q.Enqueue(2));
            Assert.Equal("queue back", 2, (int)q.Back());
            Assert.True("should drop", !q.Enqueue(3));
            // should not block
            ShouldThrowCME(new _Fun_206(q));
            ShouldThrowCME(new _Fun_211(q));
            ShouldThrowCME(new _Fun_216(q));
            ShouldThrowCME(new _Fun_221(q));
            // The queue should still be in consistent state after all the exceptions
            Assert.Equal("queue size", 2, q.Size());
            Assert.Equal("queue front", 1, (int)q.Front());
            Assert.Equal("queue back", 2, (int)q.Back());
        }
示例#6
0
        public virtual void TestConsumerException()
        {
            SinkQueue <int>  q  = new SinkQueue <int>(1);
            RuntimeException ex = new RuntimeException("expected");

            q.Enqueue(1);
            try
            {
                q.Consume(new _Consumer_157(ex));
            }
            catch (Exception expected)
            {
                NUnit.Framework.Assert.AreSame("consumer exception", ex, expected);
            }
            // The queue should be in consistent state after exception
            Assert.Equal("queue size", 1, q.Size());
            Assert.Equal("element", 1, (int)q.Dequeue());
        }