Example #1
0
        internal static async Task WaitForReIndexingToFinish(
            int maxWaitDurationInSeconds,
            CosmosContainerSettings collection)
        {
            await Task.Delay(TimeSpan.FromSeconds(5));

            int currentWaitSeconds = 0;
            var lockedClients      = ReplicationTests.GetClientsLocked();

            for (int index = 0; index < lockedClients.Length; ++index)
            {
                Logger.LogLine("Client: " + index);

                while (true)
                {
                    long reindexerProgress = (await TestCommon.AsyncRetryRateLimiting(
                                                  () => lockedClients[index].ReadDocumentCollectionAsync(collection.SelfLink, new RequestOptions {
                        PopulateQuotaInfo = true
                    }))).IndexTransformationProgress;
                    Logger.LogLine("Progress: " + reindexerProgress);
                    if (reindexerProgress == -1)
                    {
                        throw new Exception("Failed to obtain the reindexer progress.");
                    }
                    else if (reindexerProgress == 100)
                    {
                        Logger.LogLine("ReIndexing finished after: " + currentWaitSeconds + " seconds");
                        break;
                    }
                    else
                    {
                        await Task.Delay(TimeSpan.FromSeconds(1));

                        currentWaitSeconds++;
                        Logger.LogLine("ReIndexing still running after: " + currentWaitSeconds + " seconds");
                        if (currentWaitSeconds > maxWaitDurationInSeconds)
                        {
                            throw new Exception("ReIndexing did not complete after: " + maxWaitDurationInSeconds + "  seconds");
                        }
                    }
                }
            }
        }
Example #2
0
        internal static async Task WaitForReIndexingToFinish(int maxWaitDurationInSeconds, CosmosContainerSettings collection, DocumentClient client)
        {
            await Task.Delay(TimeSpan.FromSeconds(5));

            int currentWaitSeconds = 0;

            while (true)
            {
                ResourceResponse <CosmosContainerSettings> documentCollectionResponse = await TestCommon.AsyncRetryRateLimiting(() => client.ReadDocumentCollectionAsync(collection.SelfLink));

                var header = documentCollectionResponse.ResponseHeaders[HttpConstants.HttpHeaders.CollectionIndexTransformationProgress];
                Logger.LogLine("Progress: " + header);
                int headerInt = int.Parse(header, CultureInfo.InvariantCulture);
                if (headerInt != 100)
                {
                    await Task.Delay(TimeSpan.FromSeconds(1));

                    currentWaitSeconds++;
                    Logger.LogLine("ReIndexing still running after: " + currentWaitSeconds + " seconds");
                    if (currentWaitSeconds > maxWaitDurationInSeconds)
                    {
                        throw new Exception("ReIndexing did not complete after: " + maxWaitDurationInSeconds + "  seconds");
                    }
                }
                else
                {
                    Logger.LogLine("ReIndexing Finished after: " + currentWaitSeconds + " seconds");
                    break;
                }
            }
        }