Exemplo n.º 1
0
 public void TestStop()
 {
     using ComparableTaskScheduler scheduler = new ComparableTaskScheduler();
     Assert.AreEqual(true, scheduler.TryQueueTask(new TestComparableTask(0, Task.FromResult(false))));
     scheduler.Stop();
     Assert.AreEqual(false, scheduler.TryQueueTask(new TestComparableTask(0, Task.FromResult(false))));
 }
        public async Task TestOperationCanceledExceptionAsync()
        {
            int    seed = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
            Random rand = new Random(seed);
            IDocumentClientRetryPolicy retryPolicy = new MockRetryPolicy(rand);
            ComparableTaskScheduler    scheduler   = new ComparableTaskScheduler(1);

            DocumentProducer <int> producer = new DocumentProducer <int>(
                scheduler,
                (continuation, pageSize) => null,
                new PartitionKeyRange {
                Id = "test", MinInclusive = "", MaxExclusive = "ff"
            },
                p => 0,
                (request, token) =>
            {
                scheduler.Stop();
                throw new Exception();
            },
                () => retryPolicy,
                (produer, size, ru, queryMetrics, token, length) => { },
                Guid.NewGuid()
                )
            {
                PageSize = 1000
            };

            await producer.MoveNextAsync(new CancellationTokenSource().Token);
        }