private static void ValidateCounts(IDocumentStore store, DataGenerator generator) { using (var session = store.OpenSession()) { var statistics = store.DatabaseCommands.GetStatistics(); //Console.WriteLine(RavenJObject.FromObject(statistics).ToString(Formatting.Indented)); Assert.Equal(0, statistics.Errors.Length); Assert.Equal(0, statistics.StaleIndexes.Length); Assert.Equal(generator.ExpectedNumberOfIndexes, statistics.Indexes.Length); Assert.Equal(0, statistics.CountOfAttachments); Assert.Equal(generator.ExpectedNumberOfOrders, session.Query<Order>().Count()); Assert.Equal(generator.ExpectedNumberOfCompanies, session.Query<Company>().Count()); Assert.Equal(generator.ExpectedNumberOfProducts, session.Query<Product>().Count()); Assert.Equal(generator.ExpectedNumberOfEmployees, session.Query<Employee>().Count()); var total = generator.ExpectedNumberOfCompanies + generator.ExpectedNumberOfEmployees + generator.ExpectedNumberOfOrders + generator.ExpectedNumberOfProducts; Assert.Equal(total, session.Query<dynamic, RavenDocumentsByEntityName>().Count()); Assert.Equal(total, statistics.CountOfDocuments); } }
public void LargeMigrationSelf(int numberOfIterations, string requestedStorage) { var backupLocation = NewDataPath("Self-Backup", forceCreateDir: true); DataGenerator generator; using (var store = NewRemoteDocumentStore(runInMemory: false, requestedStorage: requestedStorage)) { using (var client = new ThinClient(store.Url, DatabaseName)) { generator = new DataGenerator(client, numberOfIterations); client.PutDatabase(DatabaseName); generator.Generate(); client.StartBackup(DatabaseName, backupLocation, waitForBackupToComplete: true); } } using (var store = NewRemoteDocumentStore(runInMemory: false)) { store.DefaultDatabase = "Northwind"; var operation = store .DatabaseCommands .GlobalAdmin .StartRestore(new DatabaseRestoreRequest { BackupLocation = backupLocation, DatabaseName = "Northwind" }); operation.WaitForCompletion(); ValidateBackup(store, generator); } }
private static void ValidateOrdersTotals(IDocumentStore store, DataGenerator generator) { using (var session = store.OpenSession()) { var count = session .Query<OrdersTotals.Result, OrdersTotals>() .Count(); Assert.Equal(generator.ExpectedNumberOfOrders, count); } }
private static void ValidateOrdersByEmployeeAndCompanyReduce(IDocumentStore store, DataGenerator generator) { using (var session = store.OpenSession()) { var count = session .Query<OrdersByEmployeeAndCompanyReduce.Result, OrdersByEmployeeAndCompanyReduce>() .Count(); Assert.Equal(generator.ExpectedNumberOfOrders, count); } }
private static void ValidateIndexes(IDocumentStore store, DataGenerator generator) { ValidateOrdersByCompany(store); ValidateProductSales(store); ValidateOrdersTotals(store, generator); ValidateOrdersByEmployeeAndCompany(store, generator); ValidateOrdersByEmployeeAndCompanyReduce(store, generator); }
private static void ValidateBackup(IDocumentStore store, DataGenerator generator) { WaitForIndexingOfLargeDatabase(store, timeout: TimeSpan.FromMinutes(60)); ValidateCounts(store, generator); ValidateIndexes(store, generator); }
public void LargeMigration(int numberOfIterations) { var exceptions = new List<Exception>(); foreach (var configuration in serversToTest) foreach (var storageType in configuration.StorageTypes) { KillPreviousServers(); Console.WriteLine("|> Processing: {0}. Storage: {1}.", configuration.Name, storageType); var backupLocation = NewDataPath(configuration.Name + "-Backup", forceCreateDir: true); using (var client = new ThinClient(string.Format("http://localhost:{0}", Port), DatabaseName)) { var generator = new DataGenerator(client, numberOfIterations); using (var server = DeployServer(configuration.Name, storageType)) { File.AppendAllLines(ServersFileName, new[] { server.ProcessId.ToString(CultureInfo.InvariantCulture) }); client.PutDatabase(DatabaseName); generator.Generate(); if (configuration.WaitForIndexingBeforeBackup) client.WaitForIndexing(); client.StartBackup(DatabaseName, backupLocation, waitForBackupToComplete: true); } using (var store = NewRemoteDocumentStore(runInMemory: false)) { store.DefaultDatabase = "Northwind"; var operation = store .DatabaseCommands .GlobalAdmin .StartRestore(new DatabaseRestoreRequest { BackupLocation = backupLocation, DatabaseName = "Northwind" }); operation.WaitForCompletion(); try { ValidateBackup(store, generator); } catch (Exception e) { Console.WriteLine(e); exceptions.Add(new InvalidOperationException("Migration failed: " + configuration.Name + ". Storage: " + storageType + ". Message: " + e.Message, e)); } } } } if (exceptions.Count > 0) throw new AggregateException(exceptions); }