Example #1
0
        public async Task TestKeyRangeCacheRefresh()
        {
            bool   validate     = false;
            bool   pass         = false;
            string expectedPath = null;
            HttpClientHandlerHelper httpClientHandler = new HttpClientHandlerHelper
            {
                RequestCallBack = (HttpRequestMessage request, CancellationToken cancellationToken) =>
                {
                    if (validate)
                    {
                        pass = request.RequestUri.LocalPath == expectedPath;
                    }

                    return(null);
                }
            };

            using (CosmosClient client = TestCommon.CreateCosmosClient(builder => builder
                                                                       .WithConnectionModeGateway()
                                                                       .WithHttpClientFactory(() => new HttpClient(httpClientHandler))))
            {
                ContainerInternal                containerInternal = client.GetContainer(this.database.Id, this.Container.Id) as ContainerInternal;
                CosmosQueryClientCore            queryClient       = new CosmosQueryClientCore(client.ClientContext, containerInternal);
                NetworkAttachedDocumentContainer networkAttachedDocumentContainer = new NetworkAttachedDocumentContainer(
                    containerInternal,
                    queryClient,
                    Guid.NewGuid());

                // warm up the caches
                _ = await containerInternal.ReadItemStreamAsync("doesnotexist", PartitionKey.Null);

                ContainerProperties containerProperties = await containerInternal.GetCachedContainerPropertiesAsync(false, NoOpTrace.Singleton, default);

                expectedPath = "/" + containerProperties.SelfLink + "pkranges";
                validate     = true;

                TryCatch result = await networkAttachedDocumentContainer.MonadicRefreshProviderAsync(
                    trace : NoOpTrace.Singleton,
                    cancellationToken : default);