示例#1
0
        private static async Task <Tuple <PartitionKeyRangeServerBatchRequest, ArraySegment <ItemBatchOperation> > > GetBatchWithCreateOperationsAsync(
            int operationCount,
            int maxServerRequestBodyLength,
            int maxServerRequestOperationCount,
            int docSizeInBytes = 20)
        {
            List <ItemBatchOperation> operations = new List <ItemBatchOperation>();

            byte[] body   = new byte[docSizeInBytes];
            Random random = new Random();

            random.NextBytes(body);
            for (int i = 0; i < operationCount; i++)
            {
                operations.Add(new ItemBatchOperation(OperationType.Create, 0, Cosmos.PartitionKey.Null, string.Empty, new MemoryStream(body)));
            }

            return(await PartitionKeyRangeServerBatchRequest.CreateAsync("0",
                                                                         new ArraySegment <ItemBatchOperation>(operations.ToArray()),
                                                                         maxServerRequestBodyLength,
                                                                         maxServerRequestOperationCount,
                                                                         false,
                                                                         MockCosmosUtil.Serializer,
                                                                         default(CancellationToken)));
        }
示例#2
0
        public async Task OverflowsBasedOnCount_WithOffset()
        {
            List <ItemBatchOperation> operations = new List <ItemBatchOperation>()
            {
                CreateItemBatchOperation("1"),
                CreateItemBatchOperation("2"),
                CreateItemBatchOperation("3")
            };

            // Setting max count to 1
            (PartitionKeyRangeServerBatchRequest request, ArraySegment <ItemBatchOperation> pendingOperations) = await PartitionKeyRangeServerBatchRequest.CreateAsync(
                "0",
                new ArraySegment <ItemBatchOperation>(operations.ToArray(), 1, 2),
                200000,
                1,
                false,
                MockCosmosUtil.Serializer,
                default(CancellationToken));

            Assert.AreEqual(1, request.Operations.Count);
            // The first element is not taken into account due to an Offset of 1
            Assert.AreEqual(operations[1].Id, request.Operations[0].Id);
            Assert.AreEqual(1, pendingOperations.Count);
            Assert.AreEqual(operations[2].Id, pendingOperations[0].Id);
        }
示例#3
0
        public async Task FitsAllOperations()
        {
            List <ItemBatchOperation> operations = new List <ItemBatchOperation>()
            {
                CreateItemBatchOperation(),
                CreateItemBatchOperation()
            };

            (PartitionKeyRangeServerBatchRequest request, ArraySegment <ItemBatchOperation> pendingOperations) = await PartitionKeyRangeServerBatchRequest.CreateAsync(
                "0",
                new ArraySegment <ItemBatchOperation>(operations.ToArray()),
                200000,
                2,
                false,
                MockCosmosUtil.Serializer,
                default(CancellationToken));

            Assert.AreEqual(operations.Count, request.Operations.Count);
            CollectionAssert.AreEqual(operations, request.Operations.ToArray());
            Assert.AreEqual(0, pendingOperations.Count);
        }
示例#4
0
        public async Task OverflowsBasedOnCount()
        {
            List <ItemBatchOperation> operations = new List <ItemBatchOperation>()
            {
                CreateItemBatchOperation("1"),
                CreateItemBatchOperation("2"),
                CreateItemBatchOperation("3")
            };

            // Setting max count to 1
            (PartitionKeyRangeServerBatchRequest request, ArraySegment <ItemBatchOperation> pendingOperations) = await PartitionKeyRangeServerBatchRequest.CreateAsync(
                "0",
                new ArraySegment <ItemBatchOperation>(operations.ToArray()),
                200000,
                1,
                false,
                MockCosmosUtil.Serializer,
                isClientEncrypted : false,
                intendedCollectionRidValue : null,
                default(CancellationToken));

            Assert.AreEqual(1, request.Operations.Count);
            Assert.AreEqual(operations[0].Id, request.Operations[0].Id);
            Assert.AreEqual(2, pendingOperations.Count);
            Assert.AreEqual(operations[1].Id, pendingOperations[0].Id);
            Assert.AreEqual(operations[2].Id, pendingOperations[1].Id);
        }
        public async Task OverflowsBasedOnCount()
        {
            List <ItemBatchOperation> operations = new List <ItemBatchOperation>()
            {
                CreateItemBatchOperation("1"),
                CreateItemBatchOperation("2"),
                CreateItemBatchOperation("3")
            };

            // Setting max count to 1
            (PartitionKeyRangeServerBatchRequest request, ArraySegment <ItemBatchOperation> pendingOperations) = await PartitionKeyRangeServerBatchRequest.CreateAsync("0", new ArraySegment <ItemBatchOperation>(operations.ToArray()), 200000, 1, false, new CosmosJsonDotNetSerializer(), default(CancellationToken));

            Assert.AreEqual(1, request.Operations.Count);
            Assert.AreEqual(operations[0].Id, request.Operations[0].Id);
            Assert.AreEqual(2, pendingOperations.Count);
            Assert.AreEqual(operations[1].Id, pendingOperations[0].Id);
            Assert.AreEqual(operations[2].Id, pendingOperations[1].Id);
        }