public void SmugglerBetweenOperationShouldNotCreateDatabases() { using (var store = NewRemoteDocumentStore()) { var smugglerApi = new SmugglerDatabaseApi(); var options = new SmugglerBetweenOptions <RavenConnectionStringOptions> { From = new RavenConnectionStringOptions { Url = store.Url, DefaultDatabase = "DB1" }, To = new RavenConnectionStringOptions { Url = store.Url, DefaultDatabase = "DB2" } }; var aggregateException = Assert.Throws <AggregateException>(() => smugglerApi.Between(options).Wait()); var exception = aggregateException.ExtractSingleInnerException(); Assert.True(exception.Message.StartsWith("Smuggler does not support database creation (database 'DB1' on server")); store.DatabaseCommands.GlobalAdmin.EnsureDatabaseExists("DB1"); aggregateException = Assert.Throws <AggregateException>(() => smugglerApi.Between(options).Wait()); exception = aggregateException.ExtractSingleInnerException(); Assert.True(exception.Message.StartsWith("Smuggler does not support database creation (database 'DB2' on server")); } }
public async void Sample2() { #region smuggler_api_3 // export Documents and Indexes // from Northwind database // found on http://localhost:8080 // and import them to NewNorthwind // found on the same server SmugglerDatabaseApi smugglerApi = new SmugglerDatabaseApi(new SmugglerDatabaseOptions { OperateOnTypes = ItemType.Documents | ItemType.Indexes, Incremental = false }); await smugglerApi.Between( new SmugglerBetweenOptions <RavenConnectionStringOptions> { From = new RavenConnectionStringOptions { Url = "http://localhost:8080", DefaultDatabase = "Northwind" }, To = new RavenConnectionStringOptions { Url = "http://localhost:8080", DefaultDatabase = "NewNorthwind" } }); #endregion }
public async Task ShouldWork() { using (var server1 = GetNewServer(port: 8079)) using (var store1 = NewRemoteDocumentStore(ravenDbServer: server1, databaseName: "Database1")) { await new UsersIndex().ExecuteAsync(store1.AsyncDatabaseCommands, new DocumentConvention()); await new UsersTransformer().ExecuteAsync(store1); using (var session = store1.OpenAsyncSession("Database1")) { await session.StoreAsync(new User { Name = "Oren Eini" }); await session.StoreAsync(new User { Name = "Fitzchak Yitzchaki" }); await session.SaveChangesAsync(); } await store1.AsyncDatabaseCommands.PutAttachmentAsync("ayende", null, new MemoryStream(new byte[] { 3 }), new RavenJObject()); await store1.AsyncDatabaseCommands.PutAttachmentAsync("fitzchak", null, new MemoryStream(new byte[] { 2 }), new RavenJObject()); using (var server2 = GetNewServer(port: 8078)) { using (var store2 = NewRemoteDocumentStore(ravenDbServer: server2, databaseName: "Database2")) { var smugglerApi = new SmugglerDatabaseApi(); await smugglerApi.Between(new SmugglerBetweenOptions <RavenConnectionStringOptions> { From = new RavenConnectionStringOptions { Url = "http://localhost:8079", DefaultDatabase = "Database1" }, To = new RavenConnectionStringOptions { Url = "http://localhost:8078", DefaultDatabase = "Database2" } }); await AssertDatabaseHasIndex <UsersIndex>(store2); await AssertDatabaseHasTransformer <UsersTransformer>(store2); using (var session2 = store2.OpenAsyncSession("Database2")) { Assert.Equal(2, await session2.Query <User>().CountAsync()); } var attachments = await store2.AsyncDatabaseCommands.GetAttachmentsAsync(0, Etag.Empty, 25); Assert.Equal(2, attachments.Length); Assert.Equal("ayende", attachments[0].Key); Assert.Equal("fitzchak", attachments[1].Key); } } } }
public async Task Filtering_between_with_subscriptions_should_work() { using (var serverFrom = GetNewServer(8090)) using (var serverTo = GetNewServer(8091)) using (var from = NewRemoteDocumentStore(ravenDbServer: serverFrom)) using (var to = NewRemoteDocumentStore(ravenDbServer: serverTo)) { using (var session = from.OpenSession()) { session.Store(new { Foo = "Bar" }, "foo/bar"); session.SaveChanges(); } from.Subscriptions.Create(new SubscriptionCriteria { KeyStartsWith = "foo/b" }); var filters = new FilterSetting { Values = new[] { "Raven/Subscriptions" }.ToList(), ShouldMatch = false, Path = "@name" }; var smuggler = new SmugglerDatabaseApi( new SmugglerDatabaseOptions { Incremental = false, Filters = new[] { filters }.ToList(), TransformScript = null, }); await smuggler.Between(new SmugglerBetweenOptions <RavenConnectionStringOptions> { From = new RavenConnectionStringOptions { Url = from.Url, DefaultDatabase = from.DefaultDatabase }, To = new RavenConnectionStringOptions { Url = to.Url, DefaultDatabase = to.DefaultDatabase } }); } }
public async Task Using_smuggler_between_servers_should_take_into_accound_files_related_while_smuggling() { using (var server1 = GetNewServer(8090)) using (var server2 = GetNewServer(8091)) using (var store1 = NewRemoteDocumentStore(ravenDbServer: server1)) using (var store2 = NewRemoteDocumentStore(ravenDbServer: server2)) { var smugglerApi = new SmugglerDatabaseApi(); var createdUsers = AddDocuments(store1); var users = new ConcurrentBag <User>(); foreach (var user in createdUsers) { users.Add(user); } var addDocsTask = Task.Run(() => { var createdUsersInParallel = AddDocuments(store1); foreach (var user in createdUsersInParallel) { users.Add(user); } }); var smugglingTask = smugglerApi.Between(new SmugglerBetweenOptions <RavenConnectionStringOptions> { From = new RavenConnectionStringOptions { Url = store1.Url, DefaultDatabase = store1.DefaultDatabase }, To = new RavenConnectionStringOptions { Url = store2.Url, DefaultDatabase = store2.DefaultDatabase } }); await smugglingTask; await addDocsTask; //not necessary -> smuggling task should effectively do this as well WaitForIndexing(store2); using (var session = store2.OpenSession()) Assert.Equal(users.Count, session.Query <User>().Count()); } }
public async Task ShouldSmuggleIdentitiesBetweenDatabases() { using (var server1 = GetNewServer(port: 8079)) using (var store1 = NewRemoteDocumentStore(ravenDbServer: server1, databaseName: "Database1")) { using (var session = store1.OpenAsyncSession("Database1")) { await session.StoreAsync(new User { Id = "users/", Name = "Arek" }); await session.SaveChangesAsync(); } store1.DatabaseCommands.SeedIdentityFor("users/", 10); using (var server2 = GetNewServer(port: 8078)) { using (var store2 = NewRemoteDocumentStore(ravenDbServer: server2, databaseName: "Database2")) { var smugglerApi = new SmugglerDatabaseApi(); await smugglerApi.Between(new SmugglerBetweenOptions <RavenConnectionStringOptions> { From = new RavenConnectionStringOptions { Url = "http://localhost:8079", DefaultDatabase = "Database1" }, To = new RavenConnectionStringOptions { Url = "http://localhost:8078", DefaultDatabase = "Database2" } }); using (var session = store2.OpenAsyncSession("Database2")) { await session.StoreAsync(new User { Id = "users/", Name = "Oren" }); await session.SaveChangesAsync(); } var documents = (await store2.AsyncDatabaseCommands.GetDocumentsAsync(0, 10)).OrderBy(x => x.Key).ToArray(); Assert.Equal(2, documents.Length); Assert.Equal("users/1", documents[0].Key); Assert.Equal("users/11", documents[1].Key); } } } }
public async Task CanUseBetween() { using (var server1 = new RavenDbServer(new RavenConfiguration() { Port = Port1, ServerName = ServerName1 }) { RunInMemory = true, UseEmbeddedHttpServer = true }.Initialize()) { var doc = MultiDatabase.CreateDatabaseDocument("db1"); ((ServerClient)server1.DocumentStore.DatabaseCommands.ForSystemDatabase()).GlobalAdmin.CreateDatabase(doc); using (var store1 = new DocumentStore { Url = "http://localhost:" + Port1, DefaultDatabase = "db1" }.Initialize()) { new Users_ByName().Execute(store1); new UsersTransformer().Execute(store1); using (var session = store1.OpenSession("db1")) { session.Store(new User { Name = "Name1", LastName = "LastName1" }); session.Store(new User { Name = "Name2", LastName = "LastName2" }); session.SaveChanges(); } store1.DatabaseCommands.PutAttachment("attachement1", null, new MemoryStream(new byte[] { 3 }), new RavenJObject()); using (var server2 = new RavenDbServer(new RavenConfiguration() { Port = Port2, ServerName = ServerName2 }) { RunInMemory = true, UseEmbeddedHttpServer = true }.Initialize()) { var doc2 = MultiDatabase.CreateDatabaseDocument("db2"); ((ServerClient)server2.DocumentStore.DatabaseCommands.ForSystemDatabase()).GlobalAdmin.CreateDatabase(doc2); using (var store2 = new DocumentStore { Url = "http://localhost:" + Port2, DefaultDatabase = "db2" }.Initialize()) { var smugglerApi = new SmugglerDatabaseApi(); await smugglerApi.Between(new SmugglerBetweenOptions <RavenConnectionStringOptions> { From = new RavenConnectionStringOptions { Url = "http://localhost:" + Port1, DefaultDatabase = "db1" }, To = new RavenConnectionStringOptions { Url = "http://localhost:" + Port2, DefaultDatabase = "db2" } }); var docs = store2.DatabaseCommands.GetDocuments(0, 10); Assert.Equal(3, docs.Length); var indexes = store2.DatabaseCommands.GetIndexes(0, 10); Assert.Equal(1, indexes.Length); var transformers = store2.DatabaseCommands.GetTransformers(0, 10); Assert.Equal(1, transformers.Length); var attachments = store2.DatabaseCommands.GetAttachments(0, new Etag(), 10); Assert.Equal(1, attachments.Length); } } } } }
public async Task Smuggler_filtering_next_etag() { using (var server = GetNewServer()) { using (var store = new DocumentStore { Url = server.SystemDatabase.Configuration.ServerUrl }.Initialize()) { store .DatabaseCommands .GlobalAdmin .CreateDatabase(new DatabaseDocument { Id = "Dba1", Settings = { { "Raven/DataDir", "Dba1" } } }); store.DatabaseCommands.EnsureDatabaseExists("Dba1"); store .DatabaseCommands .GlobalAdmin .CreateDatabase(new DatabaseDocument { Id = "Dba2", Settings = { { "Raven/DataDir", "Dba2" } } }); store.DatabaseCommands.EnsureDatabaseExists("Dba2"); } using (var store1 = new DocumentStore { Url = server.SystemDatabase.Configuration.ServerUrl, DefaultDatabase = "Dba1" }.Initialize()) { StoreWorkerseDba1(store1); using (var session = store1.OpenSession()) { var workers = session.Query <Worker>().ToList(); Assert.Equal(3, workers.Count); var index1 = store1.DatabaseCommands.GetIndex("WorkerByName"); var index2 = store1.DatabaseCommands.GetIndex("WorkerByAge"); var index3 = store1.DatabaseCommands.GetIndex("WorkerAccountNumber"); Assert.Equal("WorkerByName", index1.Name); Assert.Equal("WorkerByAge", index2.Name); Assert.Equal("WorkerAccountNumber", index3.Name); } } SmugglerDatabaseApi smugglerApi = new SmugglerDatabaseApi(new SmugglerDatabaseOptions { OperateOnTypes = ItemType.Documents | ItemType.Indexes, Incremental = false }); smugglerApi.Options.Filters.Add(new FilterSetting { Path = "Name", ShouldMatch = true, Values = { "worker/22", "worker/333" } }); await smugglerApi.Between( new SmugglerBetweenOptions <RavenConnectionStringOptions> { From = new RavenConnectionStringOptions { Url = server.SystemDatabase.Configuration.ServerUrl, DefaultDatabase = "Dba1" }, To = new RavenConnectionStringOptions { Url = server.SystemDatabase.Configuration.ServerUrl, DefaultDatabase = "Dba2" } }); using (var store2 = new DocumentStore { Url = server.SystemDatabase.Configuration.ServerUrl, DefaultDatabase = "Dba2" }.Initialize()) { using (var session = store2.OpenSession()) { var workers = session.Query <Worker>().ToList(); Assert.Equal(0, workers.Count); var index1 = store2.DatabaseCommands.GetIndex("WorkerByName"); var index2 = store2.DatabaseCommands.GetIndex("WorkerByAge"); var index3 = store2.DatabaseCommands.GetIndex("WorkerAccountNumber"); Assert.Equal("WorkerByName", index1.Name); Assert.Equal("WorkerByAge", index2.Name); Assert.Equal("WorkerAccountNumber", index3.Name); } } } }
public async Task ShouldSupportIncremental() { using (var server1 = GetNewServer(port: 8079)) using (var store1 = NewRemoteDocumentStore(ravenDbServer: server1, databaseName: "Database1")) { using (var session = store1.OpenAsyncSession("Database1")) { await session.StoreAsync(new User { Name = "Oren Eini" }); await session.StoreAsync(new User { Name = "Fitzchak Yitzchaki" }); await session.SaveChangesAsync(); } await store1.AsyncDatabaseCommands.PutAttachmentAsync("ayende", null, new MemoryStream(new byte[] { 3 }), new RavenJObject()); await store1.AsyncDatabaseCommands.PutAttachmentAsync("fitzchak", null, new MemoryStream(new byte[] { 2 }), new RavenJObject()); using (var server2 = GetNewServer(port: 8078)) { using (var store2 = NewRemoteDocumentStore(ravenDbServer: server2, databaseName: "Database2")) { var smugglerApi = new SmugglerDatabaseApi(new SmugglerDatabaseOptions { Incremental = true, }); await smugglerApi.Between(new SmugglerBetweenOptions <RavenConnectionStringOptions> { From = new RavenConnectionStringOptions { Url = "http://localhost:8079", DefaultDatabase = "Database1" }, To = new RavenConnectionStringOptions { Url = "http://localhost:8078", DefaultDatabase = "Database2" } }); using (var session = store1.OpenAsyncSession("Database1")) { var oren = await session.LoadAsync <User>("users/1"); oren.Name += " Changed"; await session.StoreAsync(new User { Name = "Daniel Dar" }); await session.SaveChangesAsync(); } await store1.AsyncDatabaseCommands.PutAttachmentAsync("ayende", null, new MemoryStream(new byte[] { 4 }), new RavenJObject()); await store1.AsyncDatabaseCommands.PutAttachmentAsync("daniel", null, new MemoryStream(new byte[] { 5 }), new RavenJObject()); using (var session2 = store2.OpenAsyncSession("Database2")) { var oren = await session2.LoadAsync <User>("users/2"); oren.Name += " Not Changed"; await session2.SaveChangesAsync(); } await store2.AsyncDatabaseCommands.PutAttachmentAsync("fitzchak", null, new MemoryStream(new byte[] { 6 }), new RavenJObject()); await smugglerApi.Between(new SmugglerBetweenOptions <RavenConnectionStringOptions> { From = new RavenConnectionStringOptions { Url = "http://localhost:8079", DefaultDatabase = "Database1" }, To = new RavenConnectionStringOptions { Url = "http://localhost:8078", DefaultDatabase = "Database2" } }); using (var session2 = store2.OpenAsyncSession("Database2")) { Assert.Equal(3, await session2.Query <User>().CountAsync()); Assert.Equal("Oren Eini Changed", (await session2.LoadAsync <User>("users/1")).Name); Assert.Equal("Fitzchak Yitzchaki Not Changed", (await session2.LoadAsync <User>("users/2")).Name); // Test that this value won't be overwritten by the export server } Assert.Equal(3, (await store2.AsyncDatabaseCommands.GetAttachmentsAsync(0, Etag.Empty, 25)).Length); await AssertAttachmentContent(store2, "ayende", new byte[] { 4 }); await AssertAttachmentContent(store2, "fitzchak", new byte[] { 6 }); // Test that this value won't be overwritten by the export server } } } }
public async Task ShouldSupportIncrementalFromTwoServers() { using (var server1 = GetNewServer(port: 8079)) using (var store1 = NewRemoteDocumentStore(ravenDbServer: server1, databaseName: "Database1")) { using (var session = store1.OpenAsyncSession("Database1")) { await session.StoreAsync(new User { Name = "Oren Eini" }); await session.StoreAsync(new User { Name = "Fitzchak Yitzchaki" }); await session.SaveChangesAsync(); } await store1.AsyncDatabaseCommands.PutAttachmentAsync("ayende", null, new MemoryStream(new byte[] { 13 }), new RavenJObject()); await store1.AsyncDatabaseCommands.PutAttachmentAsync("fitzchak", null, new MemoryStream(new byte[] { 12 }), new RavenJObject()); using (var server2 = GetNewServer(port: 8078)) using (var store2 = NewRemoteDocumentStore(ravenDbServer: server2, databaseName: "Database2")) { using (var session = store2.OpenAsyncSession("Database2")) { await session.StoreAsync(new User { Name = "Oren Eini Server 2" }); await session.SaveChangesAsync(); } await store2.AsyncDatabaseCommands.PutAttachmentAsync("ayende", null, new MemoryStream(new byte[] { 23 }), new RavenJObject()); using (var server3 = GetNewServer(port: 8077)) { using (var store3 = NewRemoteDocumentStore(ravenDbServer: server3, databaseName: "Database3")) { var smugglerApi = new SmugglerDatabaseApi(new SmugglerDatabaseOptions { Incremental = true, }); await smugglerApi.Between(new SmugglerBetweenOptions <RavenConnectionStringOptions> { From = new RavenConnectionStringOptions { Url = "http://localhost:8079", DefaultDatabase = "Database1" }, To = new RavenConnectionStringOptions { Url = "http://localhost:8077", DefaultDatabase = "Database3" } }); await smugglerApi.Between(new SmugglerBetweenOptions <RavenConnectionStringOptions> { From = new RavenConnectionStringOptions { Url = "http://localhost:8078", DefaultDatabase = "Database2" }, To = new RavenConnectionStringOptions { Url = "http://localhost:8077", DefaultDatabase = "Database3" } }); using (var session3 = store3.OpenAsyncSession("Database3")) { Assert.Equal(2, await session3.Query <User>().CountAsync()); Assert.Equal("Oren Eini Server 2", (await session3.LoadAsync <User>("users/1")).Name); Assert.Equal("Fitzchak Yitzchaki", (await session3.LoadAsync <User>("users/2")).Name); // Test that the value from Database1 is there } Assert.Equal(2, (await store3.AsyncDatabaseCommands.GetAttachmentsAsync(0, Etag.Empty, 25)).Length); await AssertAttachmentContent(store3, "ayende", new byte[] { 23 }); await AssertAttachmentContent(store3, "fitzchak", new byte[] { 12 }); // Test that the value from Database1 is there } } } } }
public async Task ShouldImportHiloWhenRavenEntityNameFilterIsUsed_Between() { using (var store1 = CreateStore()) using (var store2 = CreateStore()) { using (var session = store1.OpenSession()) { session.Store(new Person { Name = "John" }); session.Store(new Person { Name = "Edward" }); session.Store(new Address { Street = "Main Street" }); session.SaveChanges(); } using (var stream = new MemoryStream()) { var smugglerApi = new SmugglerDatabaseApi(new SmugglerDatabaseOptions { Filters = { new FilterSetting { Path = "@metadata.Raven-Entity-Name", ShouldMatch = true, Values = { "People" } } } }); await smugglerApi.Between(new SmugglerBetweenOptions <RavenConnectionStringOptions> { From = new RavenConnectionStringOptions { DefaultDatabase = store1.DefaultDatabase, Url = store1.Url }, To = new RavenConnectionStringOptions { DefaultDatabase = store2.DefaultDatabase, Url = store2.Url } }); } WaitForIndexing(store2); using (var session = store2.OpenSession()) { var people = session .Query <Person>() .ToList(); Assert.Equal(2, people.Count); var addresses = session .Query <Address>() .ToList(); Assert.Equal(0, addresses.Count); var hilo = session.Advanced.DocumentStore.DatabaseCommands.Get("Raven/Hilo/People"); Assert.NotNull(hilo); } } }
public async Task CanDisableVersioningDuringImport_Between_Remote() { using (var server = GetNewServer()) { using (var store = NewRemoteDocumentStore(ravenDbServer: server)) { store .DatabaseCommands .GlobalAdmin .CreateDatabase(new DatabaseDocument { Id = "Import", Settings = { { Constants.ActiveBundles, "Versioning" }, { "Raven/DataDir", NewDataPath() } } }); using (var session = store.OpenSession()) { for (int i = 0; i < 10; i++) { session.Store(new User()); session.Store(new Address()); } session.SaveChanges(); } var countOfDocuments = store.DatabaseCommands.GetStatistics().CountOfDocuments; store.DatabaseCommands.ForDatabase("Import").Put("Raven/Versioning/DefaultConfiguration", null, RavenJObject.FromObject(new Bundles.Versioning.Data.VersioningConfiguration { Exclude = false, Id = "Raven/Versioning/DefaultConfiguration", MaxRevisions = 5 }), new RavenJObject()); var smuggler = new SmugglerDatabaseApi(new SmugglerDatabaseOptions() { ShouldDisableVersioningBundle = true }); await smuggler.Between(new SmugglerBetweenOptions <RavenConnectionStringOptions>() { From = new RavenConnectionStringOptions() { Url = store.Url, DefaultDatabase = store.DefaultDatabase }, To = new RavenConnectionStringOptions() { Url = store.Url, DefaultDatabase = "Import" } }); var countOfDocsAfterImport = store.DatabaseCommands.ForDatabase("Import").GetStatistics().CountOfDocuments; Assert.Equal(countOfDocuments, countOfDocsAfterImport - 1); // one additional doc for versioning bundle configuration var metadata = store.DatabaseCommands.ForDatabase("Import").Get("users/1").Metadata; Assert.True(metadata.ContainsKey(Constants.RavenIgnoreVersioning) == false, "Metadata contains temporary " + Constants.RavenIgnoreVersioning + " marker"); // after import versioning should be active using (var session = store.OpenSession("Import")) { session.Store(new User(), "users/arek"); session.SaveChanges(); var revisionsFor = session.Advanced.GetRevisionsFor <User>("users/arek", 0, 10); Assert.Equal(1, revisionsFor.Length); } } } }