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 WaitForLazyIndexingToCompleteAsync(CosmosContainerSettings collection)
        {
            TimeSpan maxWaitTime           = TimeSpan.FromMinutes(10);
            TimeSpan sleepTimeBetweenReads = TimeSpan.FromSeconds(1);

            // First wait for replication to complete
            TestCommon.WaitForServerReplication();

            var lockedClients = ReplicationTests.GetClientsLocked();

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

                while (true)
                {
                    long lazyIndexingProgress = (await lockedClients[index].ReadDocumentCollectionAsync(collection, new RequestOptions {
                        PopulateQuotaInfo = true
                    })).LazyIndexingProgress;
                    if (lazyIndexingProgress == -1)
                    {
                        throw new Exception("Failed to obtain the lazy indexing progress.");
                    }
                    else if (lazyIndexingProgress == 100)
                    {
                        Logger.LogLine("Indexing completed at {0}", DateTime.Now.ToString("HH:mm:ss.f", CultureInfo.InvariantCulture));
                        break;
                    }
                    else
                    {
                        Logger.LogLine("Obtained the lazy indexing progress: {0}. Sleep for {1} seconds", lazyIndexingProgress, sleepTimeBetweenReads.TotalSeconds);
                        await Task.Delay(sleepTimeBetweenReads);

                        maxWaitTime -= sleepTimeBetweenReads;
                        if (maxWaitTime.TotalMilliseconds <= 0)
                        {
                            throw new Exception("Indexing didn't complete within the allocated time");
                        }
                    }
                }
            }
        }