diff --git a/Microsoft.Azure.Cosmos/src/GatewayStoreClient.cs b/Microsoft.Azure.Cosmos/src/GatewayStoreClient.cs index c779dc7855..e151ffcd94 100644 --- a/Microsoft.Azure.Cosmos/src/GatewayStoreClient.cs +++ b/Microsoft.Azure.Cosmos/src/GatewayStoreClient.cs @@ -320,6 +320,14 @@ private async ValueTask PrepareRequestMessageAsync( } } + if (request.Properties != null) + { + foreach (KeyValuePair property in request.Properties) + { + requestMessage.Properties.Add(property); + } + } + // add activityId Guid activityId = System.Diagnostics.Trace.CorrelationManager.ActivityId; Debug.Assert(activityId != Guid.Empty); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayStoreModelTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayStoreModelTest.cs index 43078d1866..36b350a751 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayStoreModelTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayStoreModelTest.cs @@ -161,6 +161,67 @@ public async Task TestRetries() } + /// + /// Verifies that if the DCE has Properties set, the HttpRequestMessage has them too. Used on ThinClient. + /// + [TestMethod] + public async Task PassesPropertiesFromDocumentServiceRequest() + { + IDictionary properties = new Dictionary() + { + {"property1", Guid.NewGuid() }, + {"property2", Guid.NewGuid().ToString() } + }; + + Func> sendFunc = request => + { + Assert.AreEqual(properties.Count, request.Properties.Count); + foreach (KeyValuePair item in properties) + { + Assert.AreEqual(item.Value, request.Properties[item.Key]); + } + + return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) ); + }; + + Mock mockDocumentClient = new Mock(); + 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(); + foreach (KeyValuePair property in properties) + { + request.Properties.Add(property.Key, property.Value); + } + + await storeModel.ProcessMessageAsync(request); + } + } + } + [TestMethod] public async Task TestApplySessionForMasterOperation() {