Exemplo n.º 1
0
        public void TestBackupsToBlobStorageAccount()
        {
            string hostName = string.Concat("Host-", Guid.NewGuid().ToString());

            var tasks = new List <Task>();

            // 1. Trigger the data generator to insert sample documents into the test collection
            IDataGenerator dataGenerator = new EmployeeSampleDataGenerator(this.client);

            tasks.Add(Task.Factory.StartNew(() =>
            {
                dataGenerator.GenerateSampleData().Wait();
            }));

            // 2. Trigger the backup executor to fetch all changes to the source collection and backup the changes to the specified Blob Storage Account
            BackupExecutor backupExecutor = new BackupExecutor(client, hostName);

            backupExecutor.ExecuteBackup().Wait();

            // 3. Wait for both (1) DataGenerator and (2) BackupExecutor to finish execution
            Task.WaitAll(tasks.ToArray());
            Thread.Sleep(60 * 2 * 1000);

            //// 4. Validate the number of documents backed up to Blob Storage
            int numberOfSampleDocumentsGenerated = int.Parse(ConfigurationManager.AppSettings["NumDocumentsToGenerate"]);

            Console.WriteLine("Count retrieved = {0}", BlobStorageHelper.GetListOfDocumentsBackedUpInContainer(this.CloudBlobClient));
            Assert.AreEqual(BlobStorageHelper.GetListOfDocumentsBackedUpInContainer(this.CloudBlobClient), numberOfSampleDocumentsGenerated);
        }
Exemplo n.º 2
0
        public void TestRestoreToBlobStorageAccount()
        {
            string hostName = string.Concat("Host-", Guid.NewGuid().ToString());

            string         restoreAccountName       = ConfigurationManager.AppSettings["RestoreAccountUri"];
            string         restoreAccountKey        = ConfigurationManager.AppSettings["RestoreAccountSecretKey"];
            DocumentClient documentClientForRestore = Utilities.CreateDocumentClient(restoreAccountName, restoreAccountKey);

            var tasks = new List <Task>();

            // 1. Trigger the data generator to insert sample documents into the test collection
            IDataGenerator dataGenerator = new EmployeeSampleDataGenerator(documentClientForRestore);

            tasks.Add(Task.Factory.StartNew(() =>
            {
                dataGenerator.GenerateSampleData().Wait();
            }));

            // 2. Trigger the backup executor to fetch all changes to the source collection and backup the changes to the specified Blob Storage Account
            BackupExecutor backupExecutor = new BackupExecutor(client, hostName);

            backupExecutor.ExecuteBackup().Wait();

            // 3. Wait for both (1) DataGenerator and (2) BackupExecutor to finish execution
            Task.WaitAll(tasks.ToArray());
            Thread.Sleep(60 * 2 * 1000);

            // 4. Validate the number of documents backed up to Blob Storage
            int numberOfSampleDocumentsGenerated = int.Parse(ConfigurationManager.AppSettings["NumDocumentsToGenerate"]);

            Assert.AreEqual(BlobStorageHelper.GetListOfDocumentsBackedUpInContainer(this.CloudBlobClient), numberOfSampleDocumentsGenerated);

            tasks = new List <Task>();

            RestoreExecutor restoreExecutor = new RestoreExecutor(client, hostName);

            tasks.Add(Task.Factory.StartNew(() =>
            {
                restoreExecutor.ExecuteRestore().Wait();
            }));

            Task.WaitAll(tasks.ToArray());

            string monitoredDatabaseName   = ConfigurationManager.AppSettings["DatabaseName"];
            string monitoredCollectionName = ConfigurationManager.AppSettings["CollectionName"];

            string restoreDatabaseName   = ConfigurationManager.AppSettings["RestoreDatabaseName"];
            string restoreCollectionName = ConfigurationManager.AppSettings["RestoreCollectionName"];

            long documentCountInSourceCollection   = CosmosDBHelper.FetchDocumentCountInCollection(this.client, monitoredDatabaseName, monitoredCollectionName).Result;
            long documentCountInRestoredCollection = CosmosDBHelper.FetchDocumentCountInCollection(documentClientForRestore, restoreDatabaseName, restoreCollectionName).Result;

            Assert.AreEqual(documentCountInSourceCollection, documentCountInRestoredCollection);
        }