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

Make SessionToken on QueryRequestOptions public #979

Merged
merged 11 commits into from
Nov 22, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public ConsistencyLevel? ConsistencyLevel
///
/// </para>
/// </remarks>
internal string SessionToken { get; set; }
public string SessionToken { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a note to the changelog

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've done this now, let me know if it's not correct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this is made public we need to wire it through the query stack right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding this is already done on the line 164:

RequestOptions.SetSessionToken(request, this.SessionToken);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I just want to make sure what the story will be. If a user does multiple point writes, then what session token will they send for the query?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point but also a different question.
SessionToken would be same as what is used for any ReadItemAsync.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything else I need to change, or are we all good now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope we are good to ship it. Thanks @dpgregory for your contributions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! No worries, it wasn't much!


internal CosmosSerializationFormatOptions CosmosSerializationFormatOptions { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3954,6 +3954,18 @@
"Attributes": [],
"MethodInfo": null
},
"System.String get_SessionToken()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "System.String get_SessionToken()"
},
"System.String SessionToken": {
"Type": "Property",
"Attributes": [],
"MethodInfo": null
},
"Void .ctor()": {
"Type": "Constructor",
"Attributes": [],
Expand Down Expand Up @@ -4012,6 +4024,13 @@
"CompilerGeneratedAttribute"
],
"MethodInfo": "Void set_ResponseContinuationTokenLimitInKb(System.Nullable`1[System.Int32])"
},
"Void set_SessionToken(System.String)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "Void set_SessionToken(System.String)"
}
},
"NestedTypes": {}
Expand Down Expand Up @@ -4648,6 +4667,18 @@
"Attributes": [],
"MethodInfo": null
},
"System.String get_SessionToken()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "System.String get_SessionToken()"
},
"System.String SessionToken": {
"Type": "Property",
"Attributes": [],
"MethodInfo": null
},
"Void .ctor()": {
"Type": "Constructor",
"Attributes": [],
Expand Down Expand Up @@ -4706,6 +4737,13 @@
"CompilerGeneratedAttribute"
],
"MethodInfo": "Void set_ResponseContinuationTokenLimitInKb(System.Nullable`1[System.Int32])"
},
"Void set_SessionToken(System.String)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "Void set_SessionToken(System.String)"
}
},
"NestedTypes": {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,34 @@ public async Task RequestOptionsConsistencyLevel()
await invoker.SendAsync(requestMessage, new CancellationToken());
}
}
}
}

[TestMethod]
public async Task QueryRequestOptionsSessionToken()
{
const string SessionToken = "SessionToken";
ItemRequestOptions options = new ItemRequestOptions
{
SessionToken = SessionToken
};

TestHandler testHandler = new TestHandler((request, cancellationToken) =>
{
Assert.AreEqual(SessionToken, request.Headers.GetValues(HttpConstants.HttpHeaders.SessionToken).First());
return TestHandler.ReturnSuccess();
});

CosmosClient client = MockCosmosUtil.CreateMockCosmosClient();

RequestInvokerHandler invoker = new RequestInvokerHandler(client);
invoker.InnerHandler = testHandler;
RequestMessage requestMessage = new RequestMessage(HttpMethod.Get, new System.Uri("https://dummy.documents.azure.com:443/dbs"));
requestMessage.Headers.Add(HttpConstants.HttpHeaders.PartitionKey, "[]");
requestMessage.ResourceType = ResourceType.Document;
requestMessage.OperationType = OperationType.Read;
requestMessage.RequestOptions = options;
await invoker.SendAsync(requestMessage, new CancellationToken());
}

[TestMethod]
public async Task ConsistencyLevelClient()
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [#979](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/979) Make SessionToken on QueryRequestOptions public.
- [#995](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/995) Included session token in diagnostics.
- [#1000](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/1000) Add PortReuseMode to CosmosClientOptions.
- [#1017](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/1017) Adding ClientSideRequestStatistics to gateway calls and making endtime nullable
Expand Down