public void ParallelEnqueueAndDequeueQueueBfs() { var scheduler = new QueueDistinctBfsScheduler(); var ownerId = Guid.NewGuid().ToString("N"); Parallel.For(0, 1000, new ParallelOptions { MaxDegreeOfParallelism = 20 }, i => { scheduler.Enqueue(new[] { new Request("http://www.a.com") { OwnerId = ownerId } }); scheduler.Enqueue(new[] { new Request("http://www.a.com") { OwnerId = ownerId } }); scheduler.Enqueue(new[] { new Request("http://www.a.com") { OwnerId = ownerId } }); scheduler.Enqueue(new[] { new Request("http://www.b.com") { OwnerId = ownerId } }); scheduler.Enqueue(new[] { new Request($"http://www.{i.ToString()}.com", null) { OwnerId = ownerId } }); }); Parallel.For(0, 1000, new ParallelOptions { MaxDegreeOfParallelism = 20 }, i => { scheduler.Dequeue(ownerId); }); Assert.Equal(2, scheduler.Requests[ownerId].Count); Assert.Equal(1002, scheduler.Total); }
public void EnqueueAndDequeueQueueBfs() { var ownerId = Guid.NewGuid().ToString("N"); var scheduler = new QueueDistinctBfsScheduler(); scheduler.Enqueue(new[] { new Request("http://www.a.com") { OwnerId = ownerId } }); scheduler.Enqueue(new[] { new Request("http://www.b.com") { OwnerId = ownerId } }); scheduler.Enqueue(new[] { new Request("http://www.a.com") { OwnerId = ownerId } }); scheduler.Enqueue(new[] { new Request("http://www.a.com") { OwnerId = ownerId } }); var request = scheduler.Dequeue(ownerId)[0]; Assert.Equal("http://www.a.com", request.Url); Assert.Single(scheduler.Requests[ownerId]); Assert.Equal(2, scheduler.Total); }