From f63814cd3c44bc14838b1619b32de7d39cdcb7d8 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Fri, 5 Jan 2024 17:21:36 -0800 Subject: [PATCH 1/2] Code changes to add partition key range id header to bulk and transactional responses. --- .../src/Batch/TransactionalBatchOperationResult.cs | 6 ++++++ .../src/Batch/TransactionalBatchResponse.cs | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Microsoft.Azure.Cosmos/src/Batch/TransactionalBatchOperationResult.cs b/Microsoft.Azure.Cosmos/src/Batch/TransactionalBatchOperationResult.cs index fc3d888ac5..0aa6d9bbf7 100644 --- a/Microsoft.Azure.Cosmos/src/Batch/TransactionalBatchOperationResult.cs +++ b/Microsoft.Azure.Cosmos/src/Batch/TransactionalBatchOperationResult.cs @@ -98,6 +98,11 @@ public virtual bool IsSuccessStatusCode /// internal virtual string SessionToken { get; set; } + /// + /// A string containing the partition key range id assigned to this result. + /// + internal virtual string PartitionKeyRangeId { get; set; } + /// /// ActivityId related to the operation /// @@ -218,6 +223,7 @@ internal ResponseMessage ToResponseMessage(ContainerInternal cosmosContainerCore RetryAfter = this.RetryAfter, RequestCharge = this.RequestCharge, Session = this.SessionToken, + PartitionKeyRangeId = this.PartitionKeyRangeId, ActivityId = this.ActivityId, }; diff --git a/Microsoft.Azure.Cosmos/src/Batch/TransactionalBatchResponse.cs b/Microsoft.Azure.Cosmos/src/Batch/TransactionalBatchResponse.cs index 86564dadee..e594644731 100644 --- a/Microsoft.Azure.Cosmos/src/Batch/TransactionalBatchResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Batch/TransactionalBatchResponse.cs @@ -312,6 +312,7 @@ private void CreateAndPopulateResults(IReadOnlyList operatio SubStatusCode = this.SubStatusCode, RetryAfter = TimeSpan.FromMilliseconds(retryAfterMilliseconds), SessionToken = this.Headers.Session, + PartitionKeyRangeId = this.Headers.PartitionKeyRangeId, ActivityId = this.ActivityId, }; @@ -345,6 +346,7 @@ private static async Task PopulateFromContentAsync( operationResult.Trace = trace; operationResult.SessionToken = responseMessage.Headers.Session; + operationResult.PartitionKeyRangeId = responseMessage.Headers.PartitionKeyRangeId; operationResult.ActivityId = responseMessage.Headers.ActivityId; results.Add(operationResult); From c171b51c39672136450e4bb2fd178d8c1fa26b20 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Sat, 6 Jan 2024 14:13:41 -0800 Subject: [PATCH 2/2] Code changes to add pk range id check in emulator tests. --- .../Batch/BatchAsyncContainerExecutorTests.cs | 1 + .../Batch/CosmosItemBulkTests.cs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Batch/BatchAsyncContainerExecutorTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Batch/BatchAsyncContainerExecutorTests.cs index 1c2998b7f9..86ea3cab79 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Batch/BatchAsyncContainerExecutorTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Batch/BatchAsyncContainerExecutorTests.cs @@ -61,6 +61,7 @@ public async Task DoOperationsAsync() MyDocument document = cosmosDefaultJsonSerializer.FromStream(result.ResourceStream); Assert.AreEqual(i.ToString(), document.id); + Assert.IsNotNull(result.PartitionKeyRangeId); ItemResponse storedDoc = await this.cosmosContainer.ReadItemAsync(i.ToString(), new Cosmos.PartitionKey(i.ToString())); Assert.IsNotNull(storedDoc.Resource); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Batch/CosmosItemBulkTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Batch/CosmosItemBulkTests.cs index 2658b00dfc..00c59d085c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Batch/CosmosItemBulkTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Batch/CosmosItemBulkTests.cs @@ -96,6 +96,7 @@ public async Task CreateItemStream_WithBulk() Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); ToDoActivity document = TestCommon.SerializerCore.FromStream(result.Content); Assert.AreEqual(i.ToString(), document.id); @@ -120,6 +121,7 @@ public async Task CreateItemAsync_WithBulk() Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.Created, result.StatusCode); } @@ -197,6 +199,7 @@ public async Task CreateItemAsyncValidateIntendedCollRid_WithBulk() Task> task = tasks[i]; ItemResponse result = await task; Assert.IsTrue(result.Headers.RequestCharge > 0); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.Created, result.StatusCode); } @@ -228,6 +231,7 @@ public async Task CreateItemAsyncValidateIntendedCollRid_WithBulk() Task> task = tasks[i]; ItemResponse result = await task; Assert.IsTrue(result.Headers.RequestCharge > 0); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.Created, result.StatusCode); } @@ -251,6 +255,7 @@ public async Task CreateItemJObjectWithoutPK_WithBulk() Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.Created, result.StatusCode); } @@ -275,6 +280,7 @@ public async Task UpsertItemStream_WithBulk() Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); ToDoActivity document = TestCommon.SerializerCore.FromStream(result.Content); Assert.AreEqual(i.ToString(), document.id); @@ -299,6 +305,7 @@ public async Task UpsertItem_WithBulk() Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.Created, result.StatusCode); } @@ -334,6 +341,7 @@ public async Task DeleteItemStream_WithBulk() Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode); } @@ -369,6 +377,7 @@ public async Task DeleteItem_WithBulk() Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode); } @@ -404,6 +413,7 @@ public async Task ReadItemStream_WithBulk() Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); } @@ -439,6 +449,7 @@ public async Task ReadItem_WithBulk() Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); } @@ -474,6 +485,7 @@ public async Task ReplaceItemStream_WithBulk() Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); } @@ -509,6 +521,7 @@ public async Task ReplaceItem_WithBulk() Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); } @@ -548,6 +561,7 @@ public async Task PatchItemStream_WithBulk() Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); } @@ -587,6 +601,7 @@ public async Task PatchItem_WithBulk() Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); Assert.AreEqual("patched", result.Resource.description); @@ -630,6 +645,7 @@ private async Task CreateLargeItemStreamWithBulk(int appxItemSize) Assert.IsTrue(result.Headers.RequestCharge > 0); Assert.IsNotNull(result.Headers.Session); Assert.IsNotNull(result.Headers.ActivityId); + Assert.IsNotNull(result.Headers.PartitionKeyRangeId); Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString())); Assert.AreEqual(HttpStatusCode.Created, result.StatusCode); }