public async Task EnqueueAndDequeueQueueBfs() { var ownerId = Guid.NewGuid().ToString("N"); var scheduler = new QueueDistinctBfsScheduler(new HashSetDuplicateRemover(), _hashAlgorithm); await scheduler.EnqueueAsync(new[] { new Request("http://www.a.com") { Owner = ownerId } }); await scheduler.EnqueueAsync(new[] { new Request("http://www.b.com") { Owner = ownerId } }); await scheduler.EnqueueAsync(new[] { new Request("http://www.a.com") { Owner = ownerId } }); await scheduler.EnqueueAsync(new[] { new Request("http://www.a.com") { Owner = ownerId } }); var request = (await scheduler.DequeueAsync()).First(); Assert.Equal("http://www.a.com/", request.RequestUri.ToString()); Assert.Equal(2, scheduler.Total); }
public void ParallelEnqueueAndDequeueQueueBfs() { var scheduler = new QueueDistinctBfsScheduler(new HashSetDuplicateRemover()); var ownerId = Guid.NewGuid().ToString("N"); Parallel.For(0, 1000, new ParallelOptions { MaxDegreeOfParallelism = 20 }, async i => { await scheduler.EnqueueAsync(new[] { new Request("http://www.a.com") { Owner = ownerId } }); await scheduler.EnqueueAsync(new[] { new Request("http://www.a.com") { Owner = ownerId } }); await scheduler.EnqueueAsync(new[] { new Request("http://www.a.com") { Owner = ownerId } }); await scheduler.EnqueueAsync(new[] { new Request("http://www.b.com") { Owner = ownerId } }); await scheduler.EnqueueAsync(new[] { new Request($"http://www.{i.ToString()}.com", null) { Owner = ownerId } }); }); Parallel.For(0, 1000, new ParallelOptions { MaxDegreeOfParallelism = 20 }, async i => { await scheduler.DequeueAsync(); }); Assert.Equal(1002, scheduler.Total); }