Example #1
0
        public void ClosedQueueWithBlockedReader()
        {
            bool test = false;
            BoundedBlockingQueue <int> q = new BoundedBlockingQueue <int>(10);
            Thread t = new Thread(new ParameterizedThreadStart((object o) =>
            {
                try
                {
                    ((BoundedBlockingQueue)o).ReceiveInner();
                    test = false;
                }
                catch (BoundedBlockingQueue.ClosedQueueException)
                {
                    test = true;
                }
            }
                                                               ));

            t.Start(q);
            Thread.Sleep(100);

            q.CloseEntrance();
            t.Join();
            Assert.IsTrue(test);
        }
Example #2
0
 public void ClosedQueue()
 {
     BoundedBlockingQueue<int> q = new BoundedBlockingQueue<int>(10);
     q.Send(1);
     q.CloseEntrance();
     q.Receive();
     try
     {
         q.Receive();
         Assert.Fail("Expected exception");
     }
     catch (BoundedBlockingQueue.ClosedQueueException)
     {
         // noop
     }
 }
Example #3
0
        public void ClosedQueue()
        {
            BoundedBlockingQueue <int> q = new BoundedBlockingQueue <int>(10);

            q.Send(1);
            q.CloseEntrance();
            q.Receive();
            try
            {
                q.Receive();
                Assert.Fail("Expected exception");
            }
            catch (BoundedBlockingQueue.ClosedQueueException)
            {
                // noop
            }
        }
Example #4
0
        public void Blocking()
        {
            List <int> result            = new List <int>();
            BoundedBlockingQueue <int> q = new BoundedBlockingQueue <int>(10);
            Thread t = new Thread(new ThreadStart(() =>
            {
                for (int i = 0; i < 10000; i++)
                {
                    q.Send(i);
                }
            }
                                                  ));
            Thread t2 = new Thread(new ThreadStart(() =>
            {
                while (true)
                {
                    try
                    {
                        result.Add(q.Receive());
                    }
                    catch (BoundedBlockingQueue.ClosedQueueException)
                    {
                        return;
                    }
                }
            }
                                                   ));

            t.Start();
            t2.Start();

            t.Join();
            q.CloseEntrance();

            t2.Join();
            Assert.AreEqual(10000, result.Count);
            Assert.AreEqual(9999, result[9999]);
        }
Example #5
0
        public void Blocking()
        {
            List<int> result = new List<int>();
            BoundedBlockingQueue<int> q = new BoundedBlockingQueue<int>(10);
            Thread t = new Thread(new ThreadStart(() =>
            {
                for (int i = 0; i < 10000; i++)
                {
                    q.Send(i);
                }
            }
            ));
            Thread t2 = new Thread(new ThreadStart(() =>
            {
                while (true)
                {
                    try
                    {
                        result.Add(q.Receive());
                    }
                    catch (BoundedBlockingQueue.ClosedQueueException)
                    {
                        return;
                    }
                }
            }
            ));
            t.Start();
            t2.Start();

            t.Join();
            q.CloseEntrance();

            t2.Join();
            Assert.AreEqual(10000, result.Count);
            Assert.AreEqual(9999, result[9999]);
        }
Example #6
0
        public void ClosedQueueWithBlockedReader()
        {
            bool test = false;
            BoundedBlockingQueue<int> q = new BoundedBlockingQueue<int>(10);
            Thread t = new Thread(new ParameterizedThreadStart( (object o) =>
            {
                try
                {
                    ((BoundedBlockingQueue)o).ReceiveInner();
                    test = false;
                }
                catch (BoundedBlockingQueue.ClosedQueueException)
                {
                    test = true;
                }
            }
            ));
            t.Start(q);
            Thread.Sleep(100);

            q.CloseEntrance();
            t.Join();
            Assert.IsTrue(test);
        }