From 9d7fad1c8e408cbca954361c3ac8f6545531c4f4 Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Wed, 21 Apr 2021 10:54:24 -0700 Subject: [PATCH] ChangeFeedProcessor now does not force refresh cache. PartitionKeyRange validation is opt-in instead of default on. --- .../Bootstrapping/PartitionSynchronizerCore.cs | 2 +- .../Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs | 2 +- .../Utils/BaseCosmosClientHelper.cs | 4 ++-- .../Utils/HttpHandlerMetaDataValidator.cs | 4 +--- .../Utils/TestCommon.cs | 6 +++--- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/Bootstrapping/PartitionSynchronizerCore.cs b/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/Bootstrapping/PartitionSynchronizerCore.cs index d89d58868f..764c319fd6 100644 --- a/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/Bootstrapping/PartitionSynchronizerCore.cs +++ b/Microsoft.Azure.Cosmos/src/ChangeFeedProcessor/Bootstrapping/PartitionSynchronizerCore.cs @@ -52,7 +52,7 @@ public override async Task CreateMissingLeasesAsync() this.containerRid, FeedRangeEpk.FullRange.Range, NoOpTrace.Singleton, - forceRefresh: true); + forceRefresh: false); DefaultTrace.TraceInformation("Source collection: '{0}', {1} partition(s)", this.container.LinkUri, ranges.Count); await this.CreateLeasesAsync(ranges).ConfigureAwait(false); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs index 5df7fac8e5..1a7cbf248c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosItemTests.cs @@ -45,7 +45,7 @@ public class CosmosItemTests : BaseCosmosClientHelper [TestInitialize] public async Task TestInitialize() { - await base.TestInit(); + await base.TestInit(validateSinglePartitionKeyRangeCacheCall: true); string PartitionKey = "/pk"; this.containerSettings = new ContainerProperties(id: Guid.NewGuid().ToString(), partitionKeyPath: PartitionKey); ContainerResponse response = await this.database.CreateContainerAsync( diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/BaseCosmosClientHelper.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/BaseCosmosClientHelper.cs index 2b6fcb6d25..2ae461e193 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/BaseCosmosClientHelper.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/BaseCosmosClientHelper.cs @@ -15,12 +15,12 @@ public abstract class BaseCosmosClientHelper protected CancellationTokenSource cancellationTokenSource = null; protected CancellationToken cancellationToken; - public async Task TestInit() + public async Task TestInit(bool validateSinglePartitionKeyRangeCacheCall = false) { this.cancellationTokenSource = new CancellationTokenSource(); this.cancellationToken = this.cancellationTokenSource.Token; - this.cosmosClient = TestCommon.CreateCosmosClient(); + this.cosmosClient = TestCommon.CreateCosmosClient(validatePartitionKeyRangeCalls: validateSinglePartitionKeyRangeCacheCall); this.database = await this.cosmosClient.CreateDatabaseAsync(Guid.NewGuid().ToString(), cancellationToken: this.cancellationToken); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/HttpHandlerMetaDataValidator.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/HttpHandlerMetaDataValidator.cs index 453a77d7dd..6a059fc9a1 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/HttpHandlerMetaDataValidator.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/HttpHandlerMetaDataValidator.cs @@ -9,12 +9,10 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests using System.Net.Http; using System.Threading; using System.Threading.Tasks; - using Microsoft.VisualStudio.TestTools.UnitTesting; public class HttpHandlerMetaDataValidator : DelegatingHandler { private readonly ConcurrentDictionary numOfPkRangeCachePerCollection = new ConcurrentDictionary(); - public HttpHandlerMetaDataValidator() : base(new HttpClientHandler()) { } @@ -23,7 +21,7 @@ public HttpHandlerMetaDataValidator() : base(new HttpClientHandler()) protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { - HttpResponseMessage httpResponseMessage = await base.SendAsync(request, cancellationToken);; + HttpResponseMessage httpResponseMessage = await base.SendAsync(request, cancellationToken); ; if (request.Method == HttpMethod.Get) { if (httpResponseMessage.StatusCode == System.Net.HttpStatusCode.NotModified diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TestCommon.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TestCommon.cs index 92fab47d4a..0e61918d45 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TestCommon.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/TestCommon.cs @@ -74,7 +74,7 @@ internal static (string endpoint, string authKey) GetAccountInfo() internal static CosmosClientBuilder GetDefaultConfiguration( bool useCustomSeralizer = true, - bool validatePartitionKeyRangeCalls = true) + bool validatePartitionKeyRangeCalls = false) { (string endpoint, string authKey) = TestCommon.GetAccountInfo(); CosmosClientBuilder clientBuilder = new CosmosClientBuilder(accountEndpoint: endpoint, authKeyOrResourceToken: authKey); @@ -94,7 +94,7 @@ internal static CosmosClientBuilder GetDefaultConfiguration( internal static CosmosClient CreateCosmosClient( Action customizeClientBuilder = null, bool useCustomSeralizer = true, - bool validatePartitionKeyRangeCalls = true) + bool validatePartitionKeyRangeCalls = false) { CosmosClientBuilder cosmosClientBuilder = GetDefaultConfiguration(useCustomSeralizer, validatePartitionKeyRangeCalls); customizeClientBuilder?.Invoke(cosmosClientBuilder); @@ -107,7 +107,7 @@ internal static CosmosClient CreateCosmosClient( internal static CosmosClient CreateCosmosClient( CosmosClientOptions clientOptions, string resourceToken = null, - bool validatePartitionKeyRangeCalls = true) + bool validatePartitionKeyRangeCalls = false) { string authKey = resourceToken ?? ConfigurationManager.AppSettings["MasterKey"]; string endpoint = ConfigurationManager.AppSettings["GatewayEndpoint"];