public void OrderedReading() { BoundedBlockingQueue <int> q = new BoundedBlockingQueue <int>(10); q.Send(1); q.Send(2); q.Send(3); int read = q.Receive(); Assert.AreEqual(1, read); read = q.Receive(); Assert.AreEqual(2, read); read = q.Receive(); Assert.AreEqual(3, read); }
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 } }
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 } }
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]); }
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]); }
public void OrderedReading() { BoundedBlockingQueue<int> q = new BoundedBlockingQueue<int>(10); q.Send(1); q.Send(2); q.Send(3); int read = q.Receive(); Assert.AreEqual(1, read); read = q.Receive(); Assert.AreEqual(2, read); read = q.Receive(); Assert.AreEqual(3, read); }