diff --git a/Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs b/Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs index 122f2ad660..b5c1ea917c 100644 --- a/Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs +++ b/Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs @@ -95,6 +95,14 @@ public virtual Stream Content /// public virtual Headers Headers { get; } + /// + /// Gets the Continuation Token in the current . + /// + /// + /// This is only used in feed operations like query and change feed + /// + public virtual string ContinuationToken => this.Headers?.ContinuationToken; + /// /// Gets the original request message /// diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosBasicQueryTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosBasicQueryTests.cs index 9f2cae0d20..ce74d4be45 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosBasicQueryTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosBasicQueryTests.cs @@ -374,6 +374,7 @@ private async Task> ToListAsync(QueryStream createStreamQuery, Query< pagedStreamResults.AddRange(responseResults); continuationToken = response.Headers.ContinuationToken; + Assert.AreEqual(response.ContinuationToken, response.Headers.ContinuationToken); } while (continuationToken != null); Assert.AreEqual(pagedStreamResults.Count, streamResults.Count); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemChangeFeedTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemChangeFeedTests.cs index 8be5404fdf..e7e30258b8 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemChangeFeedTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemChangeFeedTests.cs @@ -66,6 +66,7 @@ public async Task StandByFeedIterator() await feedIterator.ReadNextAsync(this.cancellationToken)) { lastcontinuation = responseMessage.Headers.ContinuationToken; + Assert.AreEqual(responseMessage.ContinuationToken, responseMessage.Headers.ContinuationToken); List deserializedToken = JsonConvert.DeserializeObject>(lastcontinuation); currentRange = deserializedToken[0].Range; Assert.AreEqual(pkRangesCount, deserializedToken.Count); @@ -107,6 +108,7 @@ await feedIterator.ReadNextAsync(this.cancellationToken)) await setIteratorNew.ReadNextAsync(this.cancellationToken)) { lastcontinuation = responseMessage.Headers.ContinuationToken; + Assert.AreEqual(responseMessage.ContinuationToken, responseMessage.Headers.ContinuationToken); currentRange = JsonConvert.DeserializeObject>(lastcontinuation)[0].Range; if (responseMessage.IsSuccessStatusCode) @@ -158,6 +160,7 @@ public async Task StandByFeedIterator_EmptyBeginning() await feedIterator.ReadNextAsync(this.cancellationToken)) { lastcontinuation = responseMessage.Headers.ContinuationToken; + Assert.AreEqual(responseMessage.ContinuationToken, responseMessage.Headers.ContinuationToken); List deserializedToken = JsonConvert.DeserializeObject>(lastcontinuation); currentRange = deserializedToken[0].Range; if (responseMessage.IsSuccessStatusCode) @@ -274,6 +277,7 @@ public async Task StandByFeedIterator_NoFetchNext() await feedIterator.ReadNextAsync(this.cancellationToken)) { continuationToken = responseMessage.Headers.ContinuationToken; + Assert.AreEqual(responseMessage.ContinuationToken, responseMessage.Headers.ContinuationToken); if (responseMessage.IsSuccessStatusCode) { Collection response = TestCommon.Serializer.FromStream>(responseMessage.Content).Data; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index e659289481..bba79ee283 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -452,7 +452,7 @@ public async Task ItemStreamIterator(bool useStatelessIterator) await feedIterator.ReadNextAsync(this.cancellationToken)) { lastContinuationToken = responseMessage.Headers.ContinuationToken; - + Assert.AreEqual(responseMessage.ContinuationToken, responseMessage.Headers.ContinuationToken); Collection response = TestCommon.Serializer.FromStream>(responseMessage.Content).Data; foreach (ToDoActivity toDoActivity in response) { @@ -806,6 +806,8 @@ public async Task QuerySinglePartitionItemStreamTest(int perPKItemCount, int max ResponseMessage response = await feedIterator.ReadNextAsync(); lastContinuationToken = response.Headers.ContinuationToken; + Assert.AreEqual(response.ContinuationToken, response.Headers.ContinuationToken); + Trace.TraceInformation($"ContinuationToken: {lastContinuationToken}"); JsonSerializer serializer = new JsonSerializer(); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosReadFeedTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosReadFeedTests.cs index 03bd65aa22..90686cf12e 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosReadFeedTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosReadFeedTests.cs @@ -91,9 +91,11 @@ public async Task CrossPartitionBiDirectionalItemReadFeedTest(bool useStatelessI using (ResponseMessage response = await iter.ReadNextAsync()) { - lastKnownContinuationToken = response.Headers.ContinuationToken; - Assert.IsNotNull(response); + + lastKnownContinuationToken = response.Headers.ContinuationToken; + Assert.AreEqual(response.ContinuationToken, response.Headers.ContinuationToken); + using (StreamReader reader = new StreamReader(response.Content)) { string json = await reader.ReadToEndAsync(); @@ -131,6 +133,7 @@ public async Task CrossPartitionBiDirectionalItemReadFeedTest(bool useStatelessI using (ResponseMessage response = await iter.ReadNextAsync()) { lastKnownContinuationToken = response.Headers.ContinuationToken; + Assert.AreEqual(response.ContinuationToken, response.Headers.ContinuationToken); Assert.IsNotNull(response); using (StreamReader reader = new StreamReader(response.Content)) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/DotNetSDKAPI.json index d68c31d780..c560e599fc 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/DotNetSDKAPI.json @@ -4153,11 +4153,21 @@ "Attributes": [], "MethodInfo": null }, + "System.String ContinuationToken": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, "System.String ErrorMessage": { "Type": "Property", "Attributes": [], "MethodInfo": null }, + "System.String get_ContinuationToken()": { + "Type": "Method", + "Attributes": [], + "MethodInfo": "System.String get_ContinuationToken()" + }, "System.String get_ErrorMessage()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ diff --git a/changelog.md b/changelog.md index be1be53ef6..9e11beeb78 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#571](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/571) Added a default JSON.net serializer with optional settings - [#572](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/572) Added partition key validation on CreateContainerIfNotExistsAsync - [#592](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/592) Added CreateIfNotExistsAsync to container builder +- [#597](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/597) Added continuation token property to ResponseMessage ### Fixed