コード例 #1
0
        public async Task DispatchesAsync()
        {
            // Expect all operations to complete as their batches get dispached
            BatchAsyncStreamer batchAsyncStreamer = new BatchAsyncStreamer(
                2,
                MaxBatchByteSize,
                this.TimerWheel,
                this.limiter,
                1,
                MockCosmosUtil.Serializer,
                this.Executor,
                this.Retrier,
                this.GetMockClientContext());
            List <Task <TransactionalBatchOperationResult> > contexts = new List <Task <TransactionalBatchOperationResult> >(10);

            for (int i = 0; i < 10; i++)
            {
                ItemBatchOperation        operation = new ItemBatchOperation(OperationType.Create, i, Cosmos.PartitionKey.Null, i.ToString());
                ItemBatchOperationContext context   = AttachContext(operation);
                batchAsyncStreamer.Add(operation);
                contexts.Add(context.OperationTask);
            }

            await Task.WhenAll(contexts);

            for (int i = 0; i < 10; i++)
            {
                Task <TransactionalBatchOperationResult> context = contexts[i];
                Assert.AreEqual(TaskStatus.RanToCompletion, context.Status);
                TransactionalBatchOperationResult result = await context;
                Assert.AreEqual(i.ToString(), result.ETag);
            }
        }
コード例 #2
0
        public async Task ExceptionsOnBatchBubbleUpAsync()
        {
            BatchAsyncStreamer        batchAsyncStreamer = new BatchAsyncStreamer(2, MaxBatchByteSize, DispatchTimerInSeconds, this.TimerPool, new CosmosJsonDotNetSerializer(), this.ExecutorWithFailure, this.Retrier);
            ItemBatchOperationContext context            = AttachContext(this.ItemBatchOperation);

            batchAsyncStreamer.Add(this.ItemBatchOperation);
            Exception capturedException = await Assert.ThrowsExceptionAsync <Exception>(() => context.OperationTask);

            Assert.AreEqual(expectedException, capturedException);
        }
コード例 #3
0
        public async Task ExceptionsOnBatchBubbleUpAsync()
        {
            BatchAsyncStreamer        batchAsyncStreamer = new BatchAsyncStreamer(2, MaxBatchByteSize, this.TimerWheel, this.limiter, 1, MockCosmosUtil.Serializer, this.ExecutorWithFailure, this.Retrier, this.GetMockClientContext());
            ItemBatchOperationContext context            = AttachContext(this.ItemBatchOperation);

            batchAsyncStreamer.Add(this.ItemBatchOperation);
            Exception capturedException = await Assert.ThrowsExceptionAsync <Exception>(() => context.OperationTask);

            Assert.AreEqual(expectedException, capturedException);
        }
コード例 #4
0
        public async Task TimerDispatchesAsync()
        {
            // Bigger batch size than the amount of operations, timer should dispatch
            BatchAsyncStreamer        batchAsyncStreamer = new BatchAsyncStreamer(2, MaxBatchByteSize, this.TimerWheel, this.limiter, 1, MockCosmosUtil.Serializer, this.Executor, this.Retrier, this.GetMockClientContext());
            ItemBatchOperationContext context            = AttachContext(this.ItemBatchOperation);

            batchAsyncStreamer.Add(this.ItemBatchOperation);
            TransactionalBatchOperationResult result = await context.OperationTask;

            Assert.AreEqual(this.ItemBatchOperation.Id, result.ETag);
        }
コード例 #5
0
        public async Task TimerDispatchesAsync()
        {
            // Bigger batch size than the amount of operations, timer should dispatch
            BatchAsyncStreamer        batchAsyncStreamer = new BatchAsyncStreamer(2, MaxBatchByteSize, DispatchTimerInSeconds, this.TimerPool, new CosmosJsonDotNetSerializer(), this.Executor, this.Retrier);
            ItemBatchOperationContext context            = AttachContext(this.ItemBatchOperation);

            batchAsyncStreamer.Add(this.ItemBatchOperation);
            BatchOperationResult result = await context.OperationTask;

            Assert.AreEqual(this.ItemBatchOperation.Id, result.ETag);
        }
コード例 #6
0
        public async Task ValidatesCongestionControlAsync()
        {
            SemaphoreSlim      newLimiter         = new SemaphoreSlim(1, defaultMaxDegreeOfConcurrency);
            BatchAsyncStreamer batchAsyncStreamer = new BatchAsyncStreamer(2, MaxBatchByteSize, this.TimerWheel, newLimiter, defaultMaxDegreeOfConcurrency, MockCosmosUtil.Serializer, this.Executor, this.Retrier, this.GetMockClientContext());

            Assert.AreEqual(newLimiter.CurrentCount, 1);

            List <Task <TransactionalBatchOperationResult> > contexts = new List <Task <TransactionalBatchOperationResult> >(100);

            for (int i = 0; i < 600; i++)
            {
                ItemBatchOperation        operation = new ItemBatchOperation(OperationType.Create, i, Cosmos.PartitionKey.Null, i.ToString());
                ItemBatchOperationContext context   = AttachContext(operation);
                batchAsyncStreamer.Add(operation);
                contexts.Add(context.OperationTask);
            }

            // 300 batch request should atleast sum up to 1000 ms barrier with wait time of 20ms in executor
            await Task.WhenAll(contexts);

            await Task.Delay(2000);

            Assert.IsTrue(newLimiter.CurrentCount >= 2, "Count of threads that can enter into semaphore should increase atleast by 1");
        }
コード例 #7
0
        public async Task DispatchesAsync()
        {
            // Expect all operations to complete as their batches get dispached
            BatchAsyncStreamer batchAsyncStreamer        = new BatchAsyncStreamer(2, MaxBatchByteSize, DispatchTimerInSeconds, this.TimerPool, new CosmosJsonDotNetSerializer(), this.Executor, this.Retrier);
            List <Task <BatchOperationResult> > contexts = new List <Task <BatchOperationResult> >(10);

            for (int i = 0; i < 10; i++)
            {
                ItemBatchOperation        operation = new ItemBatchOperation(OperationType.Create, i, i.ToString());
                ItemBatchOperationContext context   = AttachContext(operation);
                batchAsyncStreamer.Add(operation);
                contexts.Add(context.OperationTask);
            }

            await Task.WhenAll(contexts);

            for (int i = 0; i < 10; i++)
            {
                Task <BatchOperationResult> context = contexts[i];
                Assert.AreEqual(TaskStatus.RanToCompletion, context.Status);
                BatchOperationResult result = await context;
                Assert.AreEqual(i.ToString(), result.ETag);
            }
        }
コード例 #8
0
 public void ValidatesSerializer()
 {
     _ = new BatchAsyncStreamer(1, MaxBatchByteSize, this.TimerWheel, this.limiter, 1, null, this.Executor, this.Retrier, this.GetMockClientContext());
 }
コード例 #9
0
 public void ValidatesSize(int size)
 {
     _ = new BatchAsyncStreamer(size, MaxBatchByteSize, this.TimerWheel, this.limiter, 1, MockCosmosUtil.Serializer, this.Executor, this.Retrier, this.GetMockClientContext());
 }
コード例 #10
0
 public void ValidatesRetrier()
 {
     _ = new BatchAsyncStreamer(1, MaxBatchByteSize, this.TimerWheel, this.limiter, 1, MockCosmosUtil.Serializer, this.Executor, null);
 }
コード例 #11
0
 public void ValidatesLimiter()
 {
     _ = new BatchAsyncStreamer(1, MaxBatchByteSize, this.TimerWheel, null, 1, null, this.Executor, this.Retrier);
 }
コード例 #12
0
 public void ValidatesRetrier()
 {
     BatchAsyncStreamer batchAsyncStreamer = new BatchAsyncStreamer(1, MaxBatchByteSize, DispatchTimerInSeconds, this.TimerPool, new CosmosJsonDotNetSerializer(), this.Executor, null);
 }
コード例 #13
0
 public void ValidatesSerializer()
 {
     BatchAsyncStreamer batchAsyncStreamer = new BatchAsyncStreamer(1, MaxBatchByteSize, DispatchTimerInSeconds, this.TimerPool, null, this.Executor, this.Retrier);
 }
コード例 #14
0
 public void ValidatesRetrier()
 {
     BatchAsyncStreamer batchAsyncStreamer = new BatchAsyncStreamer(1, MaxBatchByteSize, DispatchTimerInSeconds, this.TimerPool, MockCosmosUtil.Serializer, this.Executor, null);
 }
コード例 #15
0
 public void ValidatesDispatchTimer(int dispatchTimerInSeconds)
 {
     BatchAsyncStreamer batchAsyncStreamer = new BatchAsyncStreamer(1, MaxBatchByteSize, dispatchTimerInSeconds, this.TimerPool, this.limiter, 1, MockCosmosUtil.Serializer, this.Executor, this.Retrier);
 }
コード例 #16
0
 public void ValidatesSerializer()
 {
     BatchAsyncStreamer batchAsyncStreamer = new BatchAsyncStreamer(1, MaxBatchByteSize, this.TimerWheel, this.limiter, 1, null, this.Executor, this.Retrier);
 }