private async Task <Container> RunWithErrorAsync( Container container, Action <TransactionalBatch> appendOperation, HttpStatusCode expectedFailedOperationStatusCode) { TestDoc testDocToCreate = BatchTestBase.PopulateTestDoc(this.PartitionKey1); TestDoc anotherTestDocToCreate = BatchTestBase.PopulateTestDoc(this.PartitionKey1); TransactionalBatch batch = new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1)) .CreateItem(testDocToCreate); appendOperation(batch); TransactionalBatchResponse batchResponse = await batch .CreateItem(anotherTestDocToCreate) .ExecuteAsync(); BatchSinglePartitionKeyTests.VerifyBatchProcessed( batchResponse, numberOfOperations: 3, expectedStatusCode: expectedFailedOperationStatusCode); Assert.AreEqual((HttpStatusCode)StatusCodes.FailedDependency, batchResponse[0].StatusCode); Assert.AreEqual(expectedFailedOperationStatusCode, batchResponse[1].StatusCode); Assert.AreEqual((HttpStatusCode)StatusCodes.FailedDependency, batchResponse[2].StatusCode); await BatchTestBase.VerifyNotFoundAsync(container, testDocToCreate); await BatchTestBase.VerifyNotFoundAsync(container, anotherTestDocToCreate); return(container); }
private async Task <TransactionalBatchResponse[]> RunTwoLargeBatchesAsync(Container container) { TransactionalBatch batch1 = new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1)); TransactionalBatch batch2 = new BatchCore((ContainerCore)container, BatchTestBase.GetPartitionKey(this.PartitionKey1)); for (int i = 0; i < Constants.MaxOperationsInDirectModeBatchRequest; i++) { batch1.CreateItem(BatchSinglePartitionKeyTests.PopulateTestDoc(this.PartitionKey1)); batch2.CreateItem(BatchSinglePartitionKeyTests.PopulateTestDoc(this.PartitionKey1)); } Task <TransactionalBatchResponse> batch1Task = batch1.ExecuteAsync(); await Task.Delay(50); Task <TransactionalBatchResponse> batch2Task = batch2.ExecuteAsync(); TransactionalBatchResponse[] batchResponses = await Task.WhenAll(batch1Task, batch2Task); return(batchResponses); }
public async Task BatchLargerThanServerRequestAsync() { Container container = BatchUnitTests.GetContainer(); const int operationCount = 20; int appxDocSize = Constants.MaxDirectModeBatchRequestBodySizeInBytes / operationCount; // Increase the doc size by a bit so all docs won't fit in one server request. appxDocSize = (int)(appxDocSize * 1.05); Batch batch = new BatchCore((ContainerCore)container, new Cosmos.PartitionKey(BatchUnitTests.PartitionKey1)); for (int i = 0; i < operationCount; i++) { TestItem testItem = new TestItem(new string('x', appxDocSize)); batch.CreateItem(testItem); } await BatchUnitTests.VerifyExceptionThrownOnExecuteAsync( batch, typeof(RequestEntityTooLargeException)); }
public async Task BatchLargerThanServerRequestAsync() { Container container = BatchTestBase.JsonContainer; const int operationCount = 20; int appxDocSize = Constants.MaxDirectModeBatchRequestBodySizeInBytes / operationCount; // Increase the doc size by a bit so all docs won't fit in one server request. appxDocSize = (int)(appxDocSize * 1.05); TransactionalBatch batch = new BatchCore((ContainerCore)container, new Cosmos.PartitionKey(this.PartitionKey1)); for (int i = 0; i < operationCount; i++) { TestDoc doc = BatchTestBase.PopulateTestDoc(this.PartitionKey1, minDesiredSize: appxDocSize); batch.CreateItem(doc); } TransactionalBatchResponse batchResponse = await batch.ExecuteAsync(); Assert.AreEqual(HttpStatusCode.RequestEntityTooLarge, batchResponse.StatusCode); }