public void DrainToWithWritersTest() { var queue = new CostBoundedConcurrentQueue <string>(10000, new StringLengthCostAssigner()); for (int i = 0; i < 5000; i++) { queue.Enqueue(BuildStringOfSize(2)); } Assert.Equal(10000, queue.Cost); // start background writer that will attempt to enqueue // new messages while we drain var writerThread = StartBackgroundWriter(queue, 1, 7000); Thread.Sleep(100); var drainCollection = new List <string>(); queue.DrainTo(drainCollection); // only the original 5000 messages should be drained, none // of the newly-written messages Assert.Equal(5000, drainCollection.Count); // background writer should finish writing Thread.Sleep(1000); drainCollection.Clear(); queue.DrainTo(drainCollection); Assert.Equal(7000, drainCollection.Count); if (writerThread.IsAlive) { writerThread.Abort(); } }
public void DrainToWithWritersTest() { var queue = new CostBoundedConcurrentQueue<string>(10000, new StringLengthCostAssigner()); for (int i = 0; i < 5000; i++) { queue.Enqueue(BuildStringOfSize(2)); } Assert.Equal(10000, queue.Cost); // start background writer that will attempt to enqueue // new messages while we drain var writerThread = StartBackgroundWriter(queue, 1, 7000); Thread.Sleep(100); var drainCollection = new List<string>(); queue.DrainTo(drainCollection); // only the original 5000 messages should be drained, none // of the newly-written messages Assert.Equal(5000, drainCollection.Count); // background writer should finish writing Thread.Sleep(1000); drainCollection.Clear(); queue.DrainTo(drainCollection); Assert.Equal(7000, drainCollection.Count); if (writerThread.IsAlive) { writerThread.Abort(); } }
public void DrainToTest() { var queue = new CostBoundedConcurrentQueue<string>(1000, new StringLengthCostAssigner()); queue.Enqueue(BuildStringOfSize(600)); queue.Enqueue(BuildStringOfSize(200)); Assert.Equal(800, queue.Cost); queue.DrainTo(new List<string>()); Assert.Equal(0, queue.Cost); Assert.Equal(0, queue.Count); }
public void DrainToTest() { var queue = new CostBoundedConcurrentQueue <string>(1000, new StringLengthCostAssigner()); queue.Enqueue(BuildStringOfSize(600)); queue.Enqueue(BuildStringOfSize(200)); Assert.Equal(800, queue.Cost); queue.DrainTo(new List <string>()); Assert.Equal(0, queue.Cost); Assert.Equal(0, queue.Count); }