Exemple #1
0
        public void CloseBehviour()
        {
            var queue = new SharedQueue();

            queue.Enqueue("Hello World");
            //queue.Close();

            var item = queue.Dequeue().ToString();
            Console.Out.WriteLine("item = {0}", item);

            ThreadPool.QueueUserWorkItem(state =>
            {
                // expect the queue to block here
                Console.WriteLine("Dequeue in thread");
                try
                {
                    var item2 = queue.Dequeue().ToString();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception in thread\n{0}", e.ToString());
                }
            });

            Thread.Sleep(100);
            Console.WriteLine("Closing queue");
            queue.Close();

            Console.WriteLine("Done");
        }
Exemple #2
0
 bool IEnumerator.MoveNext()
 {
     try {
         m_current = m_queue.Dequeue();
         return(true);
     } catch (EndOfStreamException) {
         m_current = null;
         return(false);
     }
 }
 bool IEnumerator.MoveNext()
 {
     try
     {
         _current = _queue.Dequeue();
         return(true);
     }
     catch (EndOfStreamException)
     {
         _current = default;
         return(false);
     }
 }
        public void TestBgLong()
        {
            SharedQueue q = new SharedQueue();
            EnqueueAfter(TimingInterval * 2, q, 123);

            ResetTimer();
            object v;
            bool r = q.Dequeue(TimingInterval, out v);
            Assert.Greater(TimingInterval + SafetyMargin, ElapsedMs());
            Assert.IsTrue(!r);
            Assert.AreEqual(null, v);
        }
        public void TestTimeoutShort()
        {
            SharedQueue q = new SharedQueue();
            q.Enqueue(123);

            ResetTimer();
            object v;
            bool r = q.Dequeue(TimingInterval, out v);
            Assert.Greater(SafetyMargin, ElapsedMs());
            Assert.IsTrue(r);
            Assert.AreEqual(123, v);
        }
        public void TestTimeoutNegative()
        {
            SharedQueue q = new SharedQueue();

            ResetTimer();
            object v;
            bool r = q.Dequeue(-10000, out v);
            Assert.Greater(SafetyMargin, ElapsedMs());
            Assert.IsTrue(!r);
            Assert.AreEqual(null, v);
        }
        public void TestTimeoutLong()
        {
            SharedQueue q = new SharedQueue();

            ResetTimer();
            object v;
            bool r = q.Dequeue(TimingInterval, out v);
            Assert.Less(TimingInterval - SafetyMargin, ElapsedMs());
            Assert.IsTrue(!r);
            Assert.AreEqual(null, v);
        }
        public void TestTimeoutInfinite()
        {
            SharedQueue q = new SharedQueue();
            EnqueueAfter(TimingInterval, q, 123);

            ResetTimer();
            object v;
            bool r = q.Dequeue(Timeout.Infinite, out v);
            Assert.Less(TimingInterval - SafetyMargin, ElapsedMs());
            Assert.IsTrue(r);
            Assert.AreEqual(123, v);
        }
        public void TestDoublePoll()
        {
            SharedQueue q = new SharedQueue();
            EnqueueAfter(TimingInterval * 2, q, 123);

            ResetTimer();
            object v;
            bool r;

            r = q.Dequeue(TimingInterval, out v);
            Assert.Less(TimingInterval - SafetyMargin, ElapsedMs());
            Assert.Greater(TimingInterval + SafetyMargin, ElapsedMs());
            Assert.IsTrue(!r);
            Assert.AreEqual(null, v);

            r = q.Dequeue(TimingInterval * 2, out v);
            Assert.Less(TimingInterval * 2 - SafetyMargin, ElapsedMs());
            Assert.Greater(TimingInterval * 2 + SafetyMargin, ElapsedMs());
            Assert.IsTrue(r);
            Assert.AreEqual(123, v);
        }
 public void TestDequeueNoWait2()
 {
     SharedQueue q = new SharedQueue();
     q.Enqueue(1);
     Assert.AreEqual(1, q.Dequeue());
     Assert.AreEqual(0, q.DequeueNoWait(0));
 }
 public void TestDelayedEnqueue()
 {
     SharedQueue q = new SharedQueue();
     ResetTimer();
     EnqueueAfter(TimingInterval, q, 1);
     Assert.AreEqual(0, q.DequeueNoWait(0));
     Assert.Greater(TimingInterval - SafetyMargin, ElapsedMs());
     Assert.AreEqual(1, q.Dequeue());
     Assert.Less(TimingInterval - SafetyMargin, ElapsedMs());
 }
 public void TestCloseWhenFull()
 {
     SharedQueue q = new SharedQueue();
     object v;
     q.Enqueue(1);
     q.Enqueue(2);
     q.Enqueue(3);
     q.Close();
     DelayedEnqueuer de = new DelayedEnqueuer(q, 0, 4);
     ExpectEof(new Thunk(de.EnqueueValue));
     Assert.AreEqual(1, q.Dequeue());
     Assert.AreEqual(2, q.DequeueNoWait(0));
     bool r = q.Dequeue(1, out v);
     Assert.IsTrue(r);
     Assert.AreEqual(3, v);
     ExpectEof(new Thunk(de.Dequeue));
 }