Пример #1
0
        public async Task EnqueueAndDequeueQueueDfs()
        {
            var ownerId   = Guid.NewGuid().ToString("N");
            var scheduler = new MySqlQueueDfsScheduler(_hashAlgorithm, new Opt());
            await scheduler.InitializeAsync(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.a.com")
                                                 {
                                                     Owner = ownerId
                                                 } });

            await scheduler.EnqueueAsync(new[] { new Request("http://www.b.com")
                                                 {
                                                     Owner = ownerId
                                                 } });

            var request = (await scheduler.DequeueAsync()).First();

            Assert.Equal("http://www.b.com/", request.RequestUri.ToString());
            Assert.Equal(2, await scheduler.GetTotalAsync());
        }
Пример #2
0
        public async Task ParallelEnqueueAndDequeueQueueDfs()
        {
            var ownerId   = Guid.NewGuid().ToString("N");
            var scheduler = new MySqlQueueDfsScheduler(_hashAlgorithm, new Opt());
            await scheduler.InitializeAsync(ownerId);

            ParallelUtilities.For(0, 1000, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 10
            }, 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")
                                                     {
                                                         Owner = ownerId
                                                     } });
            });
            ParallelUtilities.For(0, 1000, new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = 20
            },
                                  async _ => { await scheduler.DequeueAsync(); });

            Assert.Equal(1002, await scheduler.GetTotalAsync());
        }