Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/GatewayStoreClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,14 @@ private async ValueTask<HttpRequestMessage> PrepareRequestMessageAsync(
}
}

if (request.Properties != null)
{
foreach (KeyValuePair<string, object> property in request.Properties)
{
requestMessage.Properties.Add(property);
}
}

// add activityId
Guid activityId = System.Diagnostics.Trace.CorrelationManager.ActivityId;
Debug.Assert(activityId != Guid.Empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,67 @@ public async Task TestRetries()

}

/// <summary>
/// Verifies that if the DCE has Properties set, the HttpRequestMessage has them too. Used on ThinClient.
/// </summary>
[TestMethod]
public async Task PassesPropertiesFromDocumentServiceRequest()
{
IDictionary<string, object> properties = new Dictionary<string, object>()
{
{"property1", Guid.NewGuid() },
{"property2", Guid.NewGuid().ToString() }
};

Func<HttpRequestMessage, Task<HttpResponseMessage>> sendFunc = request =>
{
Assert.AreEqual(properties.Count, request.Properties.Count);
foreach (KeyValuePair<string, object> item in properties)
{
Assert.AreEqual(item.Value, request.Properties[item.Key]);
}

return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) );
};

Mock<IDocumentClientInternal> mockDocumentClient = new Mock<IDocumentClientInternal>();
mockDocumentClient.Setup(client => client.ServiceEndpoint).Returns(new Uri("https://foo"));

using GlobalEndpointManager endpointManager = new GlobalEndpointManager(mockDocumentClient.Object, new ConnectionPolicy());
ISessionContainer sessionContainer = new SessionContainer(string.Empty);
DocumentClientEventSource eventSource = DocumentClientEventSource.Instance;
HttpMessageHandler messageHandler = new MockMessageHandler(sendFunc);
using GatewayStoreModel storeModel = new GatewayStoreModel(
endpointManager,
sessionContainer,
ConsistencyLevel.Eventual,
eventSource,
null,
MockCosmosUtil.CreateCosmosHttpClient(() => new HttpClient(messageHandler)));

using (new ActivityScope(Guid.NewGuid()))
{
using (DocumentServiceRequest request =
DocumentServiceRequest.Create(
Documents.OperationType.Query,
Documents.ResourceType.Document,
new Uri("https://foo.com/dbs/db1/colls/coll1", UriKind.Absolute),
new MemoryStream(Encoding.UTF8.GetBytes("content1")),
AuthorizationTokenType.PrimaryMasterKey,
null))
{
// Add properties to the DCE
request.Properties = new Dictionary<string, object>();
foreach (KeyValuePair<string, object> property in properties)
{
request.Properties.Add(property.Key, property.Value);
}

await storeModel.ProcessMessageAsync(request);
}
}
}

[TestMethod]
public async Task TestApplySessionForMasterOperation()
{
Expand Down