Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding continuation token property to response message #597

Merged
merged 4 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public virtual Stream Content
/// </summary>
public virtual Headers Headers { get; }

/// <summary>
/// Gets the Continuation Token in the current <see cref="ResponseMessage"/>.
/// </summary>
/// <remarks>
/// This is only used in feed operations like query and change feed
/// </remarks>
public virtual string ContinuationToken => this.Headers?.ContinuationToken;

/// <summary>
/// Gets the original request message
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ private async Task<List<T>> ToListAsync<T>(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompositeContinuationToken> deserializedToken = JsonConvert.DeserializeObject<List<CompositeContinuationToken>>(lastcontinuation);
currentRange = deserializedToken[0].Range;
Assert.AreEqual(pkRangesCount, deserializedToken.Count);
Expand Down Expand Up @@ -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<List<CompositeContinuationToken>>(lastcontinuation)[0].Range;

if (responseMessage.IsSuccessStatusCode)
Expand Down Expand Up @@ -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<CompositeContinuationToken> deserializedToken = JsonConvert.DeserializeObject<List<CompositeContinuationToken>>(lastcontinuation);
currentRange = deserializedToken[0].Range;
if (responseMessage.IsSuccessStatusCode)
Expand Down Expand Up @@ -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<ToDoActivity> response = TestCommon.Serializer.FromStream<CosmosFeedResponseUtil<ToDoActivity>>(responseMessage.Content).Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ToDoActivity> response = TestCommon.Serializer.FromStream<CosmosFeedResponseUtil<ToDoActivity>>(responseMessage.Content).Data;
foreach (ToDoActivity toDoActivity in response)
{
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#557](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/557) Added trigger options to item request options
- [#571](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/571) Added a default JSON.net serializer with optional settings
- [#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

Expand Down