Exemplo n.º 1
0
        public void LockFreeQueuePeek()
        {
            var   queue = new LockFreeQueue <int>();
            Int32 t     = 0;

            //We enqueue some items to test
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);
            //We check that after a peeking we have the correct value but the item
            //is not deleted
            Assert.IsTrue(queue.Peek(ref t));
            Assert.AreEqual(t, 1);
            Assert.AreEqual(queue.Count, 5);
            queue.DequeueSingle();
            Assert.IsTrue(queue.Peek(ref t));
            Assert.AreEqual(t, 2);
            Assert.AreEqual(queue.Count, 4);
            queue.DequeueSingle();
            Assert.IsTrue(queue.Peek(ref t));
            Assert.AreEqual(t, 3);
            Assert.AreEqual(queue.Count, 3);
            queue.DequeueSingle();
            Assert.IsTrue(queue.Peek(ref t));
            Assert.AreEqual(t, 4);
            Assert.AreEqual(queue.Count, 2);
            queue.DequeueSingle();
            Assert.IsTrue(queue.Peek(ref t));
            Assert.AreEqual(t, 5);
            Assert.AreEqual(queue.Count, 1);
            queue.DequeueSingle();
            Assert.IsFalse(queue.Peek(ref t));
        }
 public void ItShouldBePossibleToClearAQueueAndDequeueASingleItem()
 {
     var lfq = new LockFreeQueue<string>();
     var lele = new List<string>();
     for (int i = 0; i < ENQUEUED_DATA; i++)
     {
         lele.Add("TEST_" + i);
     }
     lfq.Enqueue(lele);
     Assert.AreEqual("TEST_0", lfq.DequeueSingle());
     lfq.Clear();
     Assert.IsNull(lfq.DequeueSingle());
 }
 public void ItShouldBePossibleToEnqueuAndDequeuNonNullableElements()
 {
     var lfq = new LockFreeQueue<int>();
     var lele = new List<int>();
     for (int i = 0; i < ENQUEUED_DATA; i++)
     {
         lele.Add(i);
     }
     lfq.Enqueue(lele);
     Assert.AreEqual(0, lfq.DequeueSingle());
     lfq.Clear();
     Assert.AreEqual(0,lfq.Count);
     Assert.AreEqual(0,lfq.DequeueSingle());
 }
        public void LockFreeQueueIntItShouldBePossibleToClearAQueueAndDequeueASingleItem()
        {
            var lfq  = new LockFreeQueue <string>();
            var lele = new List <string>();

            for (int i = 0; i < ENQUEUED_DATA; i++)
            {
                lele.Add("TEST_" + i);
            }
            lfq.Enqueue(lele);
            Assert.AreEqual("TEST_0", lfq.DequeueSingle());
            lfq.Clear();
            Assert.IsNull(lfq.DequeueSingle());
        }
        public void LockFreeQueueIntItShouldBePossibleToEnqueuAndDequeuNonNullableElements()
        {
            var lfq  = new LockFreeQueue <int>();
            var lele = new List <int>();

            for (int i = 0; i < ENQUEUED_DATA; i++)
            {
                lele.Add(i);
            }
            lfq.Enqueue(lele);
            Assert.AreEqual(0, lfq.DequeueSingle());
            lfq.Clear();
            Assert.AreEqual(0, lfq.Count);
            Assert.AreEqual(0, lfq.DequeueSingle());
        }
Exemplo n.º 6
0
        public void LockFreeQueueDequeue()
        {
            var queue = new LockFreeQueue <int>();

            //We enqueue some items to test
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);
            //For each number enqueued we check that is removed properly and in the
            //queue order (FIFO)
            Assert.AreEqual(queue.DequeueSingle(), 1);
            Assert.AreEqual(queue.Count, 4);
            Assert.AreEqual(queue.DequeueSingle(), 2);
            Assert.AreEqual(queue.Count, 3);
            Assert.AreEqual(queue.DequeueSingle(), 3);
            Assert.AreEqual(queue.Count, 2);
            Assert.AreEqual(queue.DequeueSingle(), 4);
            Assert.AreEqual(queue.Count, 1);
            Assert.AreEqual(queue.DequeueSingle(), 5);
            Assert.AreEqual(queue.Count, 0);
            Assert.AreEqual(default(int), queue.DequeueSingle());
        }