diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/ItemRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/ItemRequestOptions.cs index 59b5b245f7..d807f42f57 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/ItemRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/ItemRequestOptions.cs @@ -151,6 +151,7 @@ internal override void PopulateRequestOptions(RequestMessage request) } DedicatedGatewayRequestOptions.PopulateMaxIntegratedCacheStalenessOption(this.DedicatedGatewayRequestOptions, request); + DedicatedGatewayRequestOptions.PopulateBypassIntegratedCacheOption(this.DedicatedGatewayRequestOptions, request); RequestOptions.SetSessionToken(request, this.SessionToken); base.PopulateRequestOptions(request); diff --git a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs index 8711836191..8ce4761c31 100644 --- a/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/RequestOptions/QueryRequestOptions.cs @@ -264,6 +264,7 @@ internal override void PopulateRequestOptions(RequestMessage request) } DedicatedGatewayRequestOptions.PopulateMaxIntegratedCacheStalenessOption(this.DedicatedGatewayRequestOptions, request); + DedicatedGatewayRequestOptions.PopulateBypassIntegratedCacheOption(this.DedicatedGatewayRequestOptions, request); request.Headers.Add(HttpConstants.HttpHeaders.PopulateQueryMetrics, bool.TrueString); diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/DedicatedGatewayRequestOptions.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/DedicatedGatewayRequestOptions.cs index e3b7dccf3f..9ca854388c 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Settings/DedicatedGatewayRequestOptions.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/DedicatedGatewayRequestOptions.cs @@ -23,6 +23,40 @@ public class DedicatedGatewayRequestOptions /// public TimeSpan? MaxIntegratedCacheStaleness { get; set; } + /// + /// Gets or sets if bypass the integrated cache or not associated with the request in the Azure CosmosDB service. + /// When set this value to true, the request will not be served from the integrated cache, and the response will not be cached either. + /// + /// Default value is false. + /// + /// + /// + /// + /// +#if PREVIEW + public +#else + internal +#endif + bool? BypassIntegratedCache { get; set; } + internal static void PopulateMaxIntegratedCacheStalenessOption(DedicatedGatewayRequestOptions dedicatedGatewayRequestOptions, RequestMessage request) { if (dedicatedGatewayRequestOptions?.MaxIntegratedCacheStaleness != null) @@ -37,5 +71,13 @@ internal static void PopulateMaxIntegratedCacheStalenessOption(DedicatedGatewayR request.Headers.Set(HttpConstants.HttpHeaders.DedicatedGatewayPerRequestCacheStaleness, cacheStalenessInMilliseconds.ToString(CultureInfo.InvariantCulture)); } } + + internal static void PopulateBypassIntegratedCacheOption(DedicatedGatewayRequestOptions dedicatedGatewayRequestOptions, RequestMessage request) + { + if (dedicatedGatewayRequestOptions != null && dedicatedGatewayRequestOptions.BypassIntegratedCache.HasValue && dedicatedGatewayRequestOptions.BypassIntegratedCache.Value) + { + request.Headers.Set(HttpConstants.HttpHeaders.DedicatedGatewayPerRequestBypassIntegratedCache, true.ToString(CultureInfo.InvariantCulture)); + } + } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetPreviewSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetPreviewSDKAPI.json index 08d0d65a7e..de49584da2 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetPreviewSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Contracts/DotNetPreviewSDKAPI.json @@ -377,6 +377,31 @@ }, "NestedTypes": {} }, + "Microsoft.Azure.Cosmos.DedicatedGatewayRequestOptions;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { + "Subclasses": {}, + "Members": { + "System.Nullable`1[System.Boolean] BypassIntegratedCache": { + "Type": "Property", + "Attributes": [], + "MethodInfo": "System.Nullable`1[System.Boolean] BypassIntegratedCache;CanRead:True;CanWrite:True;System.Nullable`1[System.Boolean] get_BypassIntegratedCache();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_BypassIntegratedCache(System.Nullable`1[System.Boolean]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "System.Nullable`1[System.Boolean] get_BypassIntegratedCache()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "System.Nullable`1[System.Boolean] get_BypassIntegratedCache();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + }, + "Void set_BypassIntegratedCache(System.Nullable`1[System.Boolean])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Void set_BypassIntegratedCache(System.Nullable`1[System.Boolean]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;" + } + }, + "NestedTypes": {} + }, "Microsoft.Azure.Cosmos.Fluent.ChangeFeedPolicyDefinition;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": { "Subclasses": {}, "Members": { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Resource/Settings/DedicatedGatewayRequestOptionsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Resource/Settings/DedicatedGatewayRequestOptionsTests.cs new file mode 100644 index 0000000000..b0f5cd2ea0 --- /dev/null +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Resource/Settings/DedicatedGatewayRequestOptionsTests.cs @@ -0,0 +1,94 @@ +namespace Microsoft.Azure.Cosmos.Tests.Resource.Settings +{ + using Microsoft.Azure.Documents; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class DedicatedGatewayRequestOptionsTests + { + [TestMethod] + public void BypassIntegratedCacheHeaderIsSetWhenTrue() + { + DedicatedGatewayRequestOptions dedicatedGatewayRequestOptions = new DedicatedGatewayRequestOptions + { + BypassIntegratedCache = true + }; + + ItemRequestOptions itemRequestOptions = new ItemRequestOptions + { + DedicatedGatewayRequestOptions = dedicatedGatewayRequestOptions + }; + + QueryRequestOptions queryRequestOptions = new QueryRequestOptions + { + DedicatedGatewayRequestOptions = dedicatedGatewayRequestOptions + }; + + RequestMessage itemRequestMessage = new RequestMessage(); + RequestMessage queryRequestMessage = new RequestMessage(); + + itemRequestOptions.PopulateRequestOptions(itemRequestMessage); + queryRequestOptions.PopulateRequestOptions(queryRequestMessage); + + + Assert.IsNotNull(itemRequestMessage.Headers[HttpConstants.HttpHeaders.DedicatedGatewayPerRequestBypassIntegratedCache]); + Assert.IsNotNull(queryRequestMessage.Headers[HttpConstants.HttpHeaders.DedicatedGatewayPerRequestBypassIntegratedCache]); + + Assert.AreEqual("True", itemRequestMessage.Headers[HttpConstants.HttpHeaders.DedicatedGatewayPerRequestBypassIntegratedCache]); + Assert.AreEqual("True", queryRequestMessage.Headers[HttpConstants.HttpHeaders.DedicatedGatewayPerRequestBypassIntegratedCache]); + } + + [TestMethod] + public void BypassIntegratedCacheHeaderIsNotSetWhenFalse() + { + DedicatedGatewayRequestOptions dedicatedGatewayRequestOptions = new DedicatedGatewayRequestOptions + { + BypassIntegratedCache = false + }; + + ItemRequestOptions itemRequestOptions = new ItemRequestOptions + { + DedicatedGatewayRequestOptions = dedicatedGatewayRequestOptions + }; + + QueryRequestOptions queryRequestOptions = new QueryRequestOptions + { + DedicatedGatewayRequestOptions = dedicatedGatewayRequestOptions + }; + + RequestMessage itemRequestMessage = new RequestMessage(); + RequestMessage queryRequestMessage = new RequestMessage(); + + itemRequestOptions.PopulateRequestOptions(itemRequestMessage); + queryRequestOptions.PopulateRequestOptions(queryRequestMessage); + + + Assert.IsNull(itemRequestMessage.Headers[HttpConstants.HttpHeaders.DedicatedGatewayPerRequestBypassIntegratedCache]); + Assert.IsNull(queryRequestMessage.Headers[HttpConstants.HttpHeaders.DedicatedGatewayPerRequestBypassIntegratedCache]); + } + + [TestMethod] + public void BypassIntegratedCacheHeaderIsNotSetWhenNotSet() + { + ItemRequestOptions itemRequestOptions = new ItemRequestOptions + { + DedicatedGatewayRequestOptions = new DedicatedGatewayRequestOptions() + }; + + QueryRequestOptions queryRequestOptions = new QueryRequestOptions + { + DedicatedGatewayRequestOptions = new DedicatedGatewayRequestOptions() + }; + + RequestMessage itemRequestMessage = new RequestMessage(); + RequestMessage queryRequestMessage = new RequestMessage(); + + itemRequestOptions.PopulateRequestOptions(itemRequestMessage); + queryRequestOptions.PopulateRequestOptions(queryRequestMessage); + + + Assert.IsNull(itemRequestMessage.Headers[HttpConstants.HttpHeaders.DedicatedGatewayPerRequestBypassIntegratedCache]); + Assert.IsNull(queryRequestMessage.Headers[HttpConstants.HttpHeaders.DedicatedGatewayPerRequestBypassIntegratedCache]); + } + } +}