Exemplo n.º 1
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());
        }
Exemplo n.º 2
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());
        }
Exemplo n.º 3
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());
        }