コード例 #1
0
ファイル: RavenDB_1603.cs プロジェクト: stvoidmain/ravendb
        public async Task CanPerformDumpWithLimitAndFilter_Smuggler()
        {
            var backupPath = NewDataPath("BackupFolder");

            using (var store = NewRemoteDocumentStore())
            {
                var counter = 0;
                counter = InsertUsers(store, counter, 1000);
                counter = InsertDevelopers(store, counter, 2);
                counter = InsertUsers(store, counter, 1000);
                InsertDevelopers(store, counter, 2);

                WaitForIndexing(store);

                var options = new SmugglerOptions
                {
                    Limit       = 5,
                    Incremental = true,
                    Filters     =
                    {
                        new FilterSetting
                        {
                            Path        = "@metadata.Raven-Entity-Name",
                            Values      = { "Developers" },
                            ShouldMatch = true,
                        }
                    }
                };

                var dumper = new SmugglerApi();
                await dumper.ExportData(new SmugglerExportOptions
                {
                    ToFile = backupPath,
                    From   = new RavenConnectionStringOptions
                    {
                        Url             = "http://localhost:8079",
                        DefaultDatabase = store.DefaultDatabase,
                    }
                }, options);
            }


            VerifyDump(backupPath, store =>
            {
                using (var session = store.OpenSession())
                {
                    Assert.Equal(4, session.Query <Developer>().Customize(x => x.WaitForNonStaleResultsAsOfNow()).Count());
                }
            });

            IOExtensions.DeleteDirectory(backupPath);
        }
コード例 #2
0
        public void CanExportImportTransformers()
        {
            var file = Path.GetTempFileName();

            try
            {
                using (var documentStore = NewRemoteDocumentStore())
                {
                    new ProductWithTransformerParameters().Execute(documentStore);

                    var smugglerApi = new SmugglerApi();

                    smugglerApi.ExportData(new SmugglerExportOptions
                    {
                        ToFile = file,
                        From   = new RavenConnectionStringOptions
                        {
                            Url             = documentStore.Url,
                            DefaultDatabase = documentStore.DefaultDatabase
                        }
                    }, new SmugglerOptions()).Wait(TimeSpan.FromSeconds(15));
                }

                using (var documentStore = NewRemoteDocumentStore())
                {
                    var smugglerApi = new SmugglerApi();

                    smugglerApi.ImportData(new SmugglerImportOptions
                    {
                        FromFile = file,
                        To       = new RavenConnectionStringOptions
                        {
                            Url             = documentStore.Url,
                            DefaultDatabase = documentStore.DefaultDatabase
                        }
                    }, new SmugglerOptions()).Wait(TimeSpan.FromSeconds(15));

                    var transformers = documentStore.DatabaseCommands.GetTransformers(0, 128);

                    Assert.NotNull(transformers);
                    Assert.Equal(1, transformers.Length);
                    Assert.Equal("ProductWithTransformerParameters", transformers[0].Name);
                }
            }
            finally
            {
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
            }
        }
コード例 #3
0
        public void Export_WithoutCredentials_WillReturnWithStatus401()
        {
            var smugglerApi = new SmugglerApi(new RavenConnectionStringOptions {
                Url = store.Url
            });

            var webException = Assert.Throws <WebException>(() => smugglerApi.ExportData(new SmugglerOptions {
                File = File
            }));

            Assert.Equal(WebExceptionStatus.ProtocolError, webException.Status);
            Assert.Equal(HttpStatusCode.Unauthorized, ((HttpWebResponse)webException.Response).StatusCode);
        }
コード例 #4
0
        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 SmugglerApi();
                            await smugglerApi.Between(new SmugglerBetweenOptions
                            {
                                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);
                        }
                    }
                }
        }
コード例 #5
0
        public void Export_And_Import_Incremental_Changed_Document()
        {
            IOExtensions.DeleteDirectory("Incremental");

            using (var session = documentStore.OpenSession())
            {
                var foo = new Foo {
                    Something = "Before Change", Id = "Test/1"
                };
                session.Store(foo);
                session.SaveChanges();
            }

            var smugglerApi = new SmugglerApi(new SmugglerOptions(), new  RavenConnectionStringOptions {
                Url = "http://localhost:8079/"
            });

            smugglerApi.ExportData(null, new SmugglerOptions
            {
                BackupPath     = "Incremental",
                OperateOnTypes = ItemType.Documents | ItemType.Indexes | ItemType.Attachments
            }, incremental: true).Wait(TimeSpan.FromSeconds(15));

            using (var session = documentStore.OpenSession())
            {
                var doc = session.Load <Foo>("Test/1");
                doc.Something = "After Change";
                session.SaveChanges();
            }

            smugglerApi.ExportData(null, new SmugglerOptions
            {
                BackupPath     = "Incremental",
                OperateOnTypes = ItemType.Documents | ItemType.Indexes | ItemType.Attachments
            }, incremental: true).Wait(TimeSpan.FromSeconds(15));

            server.Dispose();
            CreateServer();

            smugglerApi
            .ImportData(new SmugglerOptions {
                BackupPath = "Incremental"
            }, incremental: true)
            .Wait(TimeSpan.FromSeconds(15));

            using (var session = documentStore.OpenSession())
            {
                var doc = session.Load <Foo>("Test/1");
                Assert.Equal(doc.Something, "After Change");
            }
        }
コード例 #6
0
ファイル: SmugglerTests.cs プロジェクト: webmonger/ravendb
        public void DateTimePreserved()
        {
            var options = new SmugglerOptions {
                BackupPath = Path.GetTempFileName()
            };

            try
            {
                var docId = string.Empty;

                using (var documentStore = NewRemoteDocumentStore())
                {
                    using (var session = documentStore.OpenSession())
                    {
                        var foo = new Foo {
                            Created = DateTime.Today
                        };
                        session.Store(foo);
                        docId = foo.Id;
                        session.SaveChanges();
                    }
                    var smugglerApi = new SmugglerApi(options, new RavenConnectionStringOptions()
                    {
                        Url = documentStore.Url
                    });
                    smugglerApi.ExportData(options);
                }

                using (var documentStore = NewRemoteDocumentStore())
                {
                    var smugglerApi = new SmugglerApi(options, new RavenConnectionStringOptions()
                    {
                        Url = documentStore.Url
                    });
                    smugglerApi.ImportData(options);

                    using (var session = documentStore.OpenSession())
                    {
                        var created = session.Load <Foo>(docId).Created;
                        Assert.False(session.Advanced.HasChanges);
                    }
                }
            }
            finally
            {
                if (File.Exists(options.BackupPath))
                {
                    File.Delete(options.BackupPath);
                }
            }
        }
コード例 #7
0
        public void SmugglerWithExcludeExpiredDocumentsShouldWork1()
        {
            var path = Path.GetTempFileName();

            var options = new SmugglerOptions
            {
                ShouldExcludeExpired = true
            };

            try
            {
                using (var store = NewRemoteDocumentStore())
                {
                    Initialize(store);

                    var smuggler = new SmugglerApi();

                    smuggler.ExportData(new SmugglerExportOptions {
                        ToFile = path, From = new RavenConnectionStringOptions {
                            Url = store.Url, DefaultDatabase = store.DefaultDatabase
                        }
                    }, options).Wait(TimeSpan.FromSeconds(15));
                }

                using (var store = NewRemoteDocumentStore())
                {
                    var smuggler = new SmugglerApi();

                    smuggler.ImportData(new SmugglerImportOptions {
                        FromFile = path, To = new RavenConnectionStringOptions {
                            Url = store.Url, DefaultDatabase = store.DefaultDatabase
                        }
                    }, options).Wait(TimeSpan.FromSeconds(15));

                    using (var session = store.OpenSession())
                    {
                        var product1 = session.Load <Product>(1);
                        var product2 = session.Load <Product>(2);
                        var product3 = session.Load <Product>(3);

                        Assert.NotNull(product1);
                        Assert.Null(product2);
                        Assert.NotNull(product3);
                    }
                }
            }
            finally
            {
                IOExtensions.DeleteDirectory(path);
            }
        }
コード例 #8
0
        public void DateTimePreserved()
        {
            var file = Path.GetTempFileName();

            try
            {
                var docId = string.Empty;

                using (var documentStore = NewRemoteDocumentStore())
                {
                    using (var session = documentStore.OpenSession())
                    {
                        var foo = new Foo {
                            Created = DateTime.Today
                        };
                        session.Store(foo);
                        docId = foo.Id;
                        session.SaveChanges();
                    }
                    var smugglerApi = new SmugglerApi();
                    smugglerApi.ExportData(new SmugglerExportOptions {
                        ToFile = file, From = new RavenConnectionStringOptions {
                            Url = documentStore.Url, DefaultDatabase = documentStore.DefaultDatabase
                        }
                    }, new SmugglerOptions()).Wait(TimeSpan.FromSeconds(15));
                }

                using (var documentStore = NewRemoteDocumentStore())
                {
                    var smugglerApi = new SmugglerApi();
                    smugglerApi.ImportData(new SmugglerImportOptions {
                        FromFile = file, To = new RavenConnectionStringOptions {
                            Url = documentStore.Url, DefaultDatabase = documentStore.DefaultDatabase
                        }
                    }, new SmugglerOptions()).Wait(TimeSpan.FromSeconds(15));

                    using (var session = documentStore.OpenSession())
                    {
                        var created = session.Load <Foo>(docId).Created;
                        Assert.False(session.Advanced.HasChanges);
                    }
                }
            }
            finally
            {
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
            }
        }
コード例 #9
0
        public void Export_And_Import_Incremental_Indexes()
        {
            var file = Path.Combine(NewDataPath(), "Incremental");

            IOExtensions.DeleteDirectory(file);

            documentStore.DatabaseCommands.PutIndex("Index1", new IndexDefinition
            {
                Map = "from x in docs select new { x.Name, Count = 1}",
            });

            var connection = new RavenConnectionStringOptions {
                Url = "http://localhost:8079/"
            };
            var smugglerApi = new SmugglerApi {
                SmugglerOptions = { OperateOnTypes = ItemType.Documents | ItemType.Indexes | ItemType.Attachments, Incremental = true }
            };

            smugglerApi.ExportData(
                new SmugglerExportOptions
            {
                ToFile = file, From = connection,
            }).Wait(TimeSpan.FromSeconds(15));

            documentStore.DatabaseCommands.PutIndex("Index2", new IndexDefinition
            {
                Map = "from x in docs select new { x.Title, Count = 1}",
            });

            smugglerApi.ExportData(
                new SmugglerExportOptions
            {
                ToFile = file,
                From   = connection,
            }).Wait(TimeSpan.FromSeconds(15));

            server.Dispose();
            CreateServer();

            smugglerApi.SmugglerOptions.Incremental = true;
            smugglerApi.ImportData(new SmugglerImportOptions {
                FromFile = file, To = connection
            }).Wait(TimeSpan.FromSeconds(15));

            var index = documentStore.DatabaseCommands.GetIndex("Index1");

            Assert.NotNull(index);

            index = documentStore.DatabaseCommands.GetIndex("Index2");
            Assert.NotNull(index);
        }
コード例 #10
0
        public void Can_filter_documents()
        {
            using (var session = documentStore.OpenSession())
            {
                session.Store(new Foo {
                    Something = "something1"
                });
                session.Store(new Foo {
                    Something = "something2"
                });
                session.SaveChanges();
            }

            var connection = new RavenConnectionStringOptions {
                Url = "http://localhost:8079/"
            };
            var smugglerApi = new SmugglerApi();

            smugglerApi.ExportData(new SmugglerExportOptions
            {
                ToFile = DumpFile,
                From   = connection,
            }, new SmugglerOptions {
                Filters =
                {
                    new FilterSetting
                    {
                        Path        = "Something",
                        ShouldMatch = true,
                        Values      = new EquatableList <string> {
                            "Something1"
                        }
                    }
                }
            }).Wait(TimeSpan.FromSeconds(15));
            Assert.True(File.Exists(DumpFile));

            server.Dispose();
            CreateServer();

            smugglerApi.ImportData(new SmugglerImportOptions {
                FromFile = DumpFile, To = connection
            }, new SmugglerOptions()).Wait(TimeSpan.FromSeconds(15));

            using (var session = documentStore.OpenSession())
            {
                Assert.NotNull(session.Load <Foo>("foos/1"));
                Assert.Null(session.Load <Foo>("foos/2"));
            }
        }
コード例 #11
0
        public void Export_And_Import_Retains_HiLoState()
        {
            using (var session = documentStore.OpenSession())
            {
                var foo = new Foo {
                    Something = "something2"
                };
                Assert.Null(foo.Id);
                session.Store(foo);
                Assert.NotNull(foo.Id);
                session.SaveChanges();
            }

            var smugglerApi = new SmugglerApi {
                SmugglerOptions = { Incremental = false }
            };
            var connection = new RavenConnectionStringOptions {
                Url = "http://localhost:8079/"
            };

            smugglerApi.ExportData(
                new SmugglerExportOptions
            {
                From   = connection,
                ToFile = DumpFile
            }).Wait(TimeSpan.FromSeconds(15));
            Assert.True(File.Exists(DumpFile));

            using (var session = documentStore.OpenSession())
            {
                var hilo = session.Load <HiLoKey>("Raven/Hilo/foos");
                Assert.NotNull(hilo);
                Assert.Equal(32, hilo.Max);
            }

            server.Dispose();
            CreateServer();

            smugglerApi.ImportData(new SmugglerImportOptions {
                FromFile = DumpFile, To = connection
            }).Wait(TimeSpan.FromSeconds(15));

            using (var session = documentStore.OpenSession())
            {
                var hilo = session.Load <HiLoKey>("Raven/Hilo/foos");
                Assert.NotNull(hilo);
                Assert.Equal(32, hilo.Max);
            }
        }
コード例 #12
0
        public void SmugglerWithExcludeExpiredDocumentsShouldWork2()
        {
            var options = new SmugglerOptions
            {
                BackupPath           = Path.GetTempFileName(),
                ShouldExcludeExpired = true
            };

            try
            {
                using (var store = NewRemoteDocumentStore())
                {
                    Initialize(store);

                    var smuggler = new SmugglerApi(options, new RavenConnectionStringOptions {
                        Url = store.Url
                    });

                    smuggler.ExportData(null, options, false).Wait(TimeSpan.FromSeconds(15));
                }

                using (var store = NewRemoteDocumentStore())
                {
                    SystemTime.UtcDateTime = () => DateTime.Now.AddMinutes(10);

                    var smuggler = new SmugglerApi(options, new RavenConnectionStringOptions {
                        Url = store.Url
                    });

                    smuggler.ImportData(options).Wait(TimeSpan.FromSeconds(15));

                    using (var session = store.OpenSession())
                    {
                        var product1 = session.Load <Product>(1);
                        var product2 = session.Load <Product>(2);
                        var product3 = session.Load <Product>(3);

                        Assert.NotNull(product1);
                        Assert.Null(product2);
                        Assert.Null(product3);
                    }
                }
            }
            finally
            {
                IOExtensions.DeleteDirectory(options.BackupPath);
            }
        }
コード例 #13
0
ファイル: RavenDB_1603.cs プロジェクト: cocytus/ravendb
        public async Task CanDumpWhenHiddenDocsWithLimit_Smuggler()
        {
            var backupPath = NewDataPath("BackupFolder");

            using (GetNewServer())
            {
                using (var store = new DocumentStore {
                    Url = "http://localhost:8079"
                })
                {
                    store.Initialize();

                    InsertHidenUsers(store, 2000);

                    var user1 = store.DatabaseCommands.Get("users/1");
                    Assert.Null(user1);

                    InsertUsers(store, 1, 25);

                    // now perform full backup
                    var dumper = new SmugglerApi {
                        SmugglerOptions = { Incremental = true }
                    };
                    await dumper.ExportData(
                        new SmugglerExportOptions
                    {
                        ToFile = backupPath,
                        From   = new RavenConnectionStringOptions
                        {
                            Url             = "http://localhost:8079",
                            DefaultDatabase = store.DefaultDatabase,
                        }
                    });
                }
            }

            VerifyDump(backupPath, store =>
            {
                using (var session = store.OpenSession())
                {
                    Assert.Equal(25, session.Query <User>().Customize(x => x.WaitForNonStaleResultsAsOfNow()).Count());
                }
            });

            IOExtensions.DeleteDirectory(backupPath);
        }
コード例 #14
0
        public void MaxNumberOfItemsToProcessInSingleBatchShouldBeRespectedBySmuggler()
        {
            var path = Path.Combine(NewDataPath(forceCreateDir: true), "raven.dump");

            using (var server = GetNewServer(configureConfig: configuration => configuration.MaxNumberOfItemsToProcessInSingleBatch = 1234))
            {
                var smuggler = new SmugglerApi(options: new SmugglerOptions {
                    BatchSize = 4321
                });
                Assert.Equal(4321, smuggler.SmugglerOptions.BatchSize);

                smuggler.ExportData(new SmugglerExportOptions {
                    ToFile = path, From = new RavenConnectionStringOptions {
                        Url = server.Configuration.ServerUrl
                    }
                }).ResultUnwrap();

                Assert.Equal(1234, smuggler.SmugglerOptions.BatchSize);

                smuggler = new SmugglerApi(options: new SmugglerOptions {
                    BatchSize = 4321
                });
                Assert.Equal(4321, smuggler.SmugglerOptions.BatchSize);

                smuggler.ImportData(new SmugglerImportOptions {
                    FromFile = path, To = new RavenConnectionStringOptions {
                        Url = server.Configuration.ServerUrl
                    }
                }).Wait();

                Assert.Equal(1234, smuggler.SmugglerOptions.BatchSize);

                smuggler = new SmugglerApi(options: new SmugglerOptions {
                    BatchSize = 1000
                });
                Assert.Equal(1000, smuggler.SmugglerOptions.BatchSize);

                smuggler.ExportData(new SmugglerExportOptions {
                    ToFile = path, From = new RavenConnectionStringOptions {
                        Url = server.Configuration.ServerUrl
                    }
                }).ResultUnwrap();

                Assert.Equal(1000, smuggler.SmugglerOptions.BatchSize);
            }
        }
コード例 #15
0
        public void Can_filter_documents()
        {
            using (var session = documentStore.OpenSession())
            {
                session.Store(new Foo {
                    Something = "something1"
                });
                session.Store(new Foo {
                    Something = "something2"
                });
                session.SaveChanges();
            }

            var smugglerApi = new SmugglerApi(new SmugglerOptions(), new RavenConnectionStringOptions {
                Url = "http://localhost:8079/"
            });

            smugglerApi.ExportData(new SmugglerOptions
            {
                BackupPath = DumpFile,
                Filters    =
                {
                    new FilterSetting
                    {
                        Path        = "Something",
                        ShouldMatch = true,
                        Value       = "Something1"
                    }
                }
            });
            Assert.True(File.Exists(DumpFile));

            server.Dispose();
            CreateServer();

            smugglerApi.ImportData(new SmugglerOptions {
                BackupPath = DumpFile
            });

            using (var session = documentStore.OpenSession())
            {
                Assert.NotNull(session.Load <Foo>("foos/1"));
                Assert.Null(session.Load <Foo>("foos/2"));
            }
        }
コード例 #16
0
        public void CanExportImportTransformers()
        {
            var options = new SmugglerOptions
            {
                BackupPath = Path.GetTempFileName()
            };

            try
            {
                using (var documentStore = NewRemoteDocumentStore())
                {
                    new ProductWithQueryInput().Execute(documentStore);

                    var smugglerApi = new SmugglerApi(options, new RavenConnectionStringOptions
                    {
                        Url = documentStore.Url
                    });

                    smugglerApi.ExportData(null, options, false).Wait(TimeSpan.FromSeconds(15));
                }

                using (var documentStore = NewRemoteDocumentStore())
                {
                    var smugglerApi = new SmugglerApi(options, new RavenConnectionStringOptions
                    {
                        Url = documentStore.Url
                    });

                    smugglerApi.ImportData(options).Wait(TimeSpan.FromSeconds(15));

                    var transformers = documentStore.DatabaseCommands.GetTransformers(0, 128);

                    Assert.NotNull(transformers);
                    Assert.Equal(1, transformers.Length);
                    Assert.Equal("ProductWithQueryInput", transformers[0].Name);
                }
            }
            finally
            {
                if (File.Exists(options.BackupPath))
                {
                    File.Delete(options.BackupPath);
                }
            }
        }
コード例 #17
0
        public void Export_And_Import_Incremental_Attachments()
        {
            IOExtensions.DeleteDirectory("Incremental");

            documentStore.DatabaseCommands.PutAttachment("test", null, new MemoryStream(new byte[] { 1, 2, 3 }), new RavenJObject {
                { "Test", true }
            });

            var smugglerApi = new SmugglerApi(new RavenConnectionStringOptions {
                Url = "http://localhost:8079/"
            });

            smugglerApi.ExportData(new SmugglerOptions
            {
                File           = "Incremental",
                OperateOnTypes = ItemType.Documents | ItemType.Indexes | ItemType.Attachments
            }, incremental: true);

            documentStore.DatabaseCommands.PutAttachment("test2", null, new MemoryStream(new byte[] { 1, 2, 3 }), new RavenJObject {
                { "Test2", true }
            });

            smugglerApi.ExportData(new SmugglerOptions
            {
                File           = "Incremental",
                OperateOnTypes = ItemType.Documents | ItemType.Indexes | ItemType.Attachments
            }, incremental: true);

            server.Dispose();
            CreateServer();

            smugglerApi.ImportData(new SmugglerOptions {
                File = "Incremental"
            }, incremental: true);

            var attachment = documentStore.DatabaseCommands.GetAttachment("test");

            Assert.Equal(new byte[] { 1, 2, 3 }, attachment.Data().ReadData());
            Assert.True(attachment.Metadata.Value <bool>("Test"));

            attachment = documentStore.DatabaseCommands.GetAttachment("test2");
            Assert.Equal(new byte[] { 1, 2, 3 }, attachment.Data().ReadData());
            Assert.True(attachment.Metadata.Value <bool>("Test2"));
        }
コード例 #18
0
        public void Export_And_Import_Incremental_Indexes()
        {
            IOExtensions.DeleteDirectory("Incremental");

            documentStore.DatabaseCommands.PutIndex("Index1", new IndexDefinition
            {
                Map = "from x in docs select new { x.Name, Count = 1}",
            });

            var smugglerApi = new SmugglerApi(new RavenConnectionStringOptions {
                Url = "http://localhost:8079/"
            });

            smugglerApi.ExportData(new SmugglerOptions
            {
                File           = "Incremental",
                OperateOnTypes = ItemType.Documents | ItemType.Indexes | ItemType.Attachments
            }, incremental: true);

            documentStore.DatabaseCommands.PutIndex("Index2", new IndexDefinition
            {
                Map = "from x in docs select new { x.Title, Count = 1}",
            });

            smugglerApi.ExportData(new SmugglerOptions
            {
                File           = "Incremental",
                OperateOnTypes = ItemType.Documents | ItemType.Indexes | ItemType.Attachments
            }, incremental: true);

            server.Dispose();
            CreateServer();

            smugglerApi.ImportData(new SmugglerOptions {
                File = "Incremental"
            }, incremental: true);

            var index = documentStore.DatabaseCommands.GetIndex("Index1");

            Assert.NotNull(index);

            index = documentStore.DatabaseCommands.GetIndex("Index2");
            Assert.NotNull(index);
        }
コード例 #19
0
ファイル: Smuggler.cs プロジェクト: stjordanis/docs-1
 public Smuggler()
 {
     #region smuggler-api
     var connectionStringOptions = new RavenConnectionStringOptions
     {
         ApiKey          = "ApiKey",
         Credentials     = new NetworkCredential("username", "password", "domain"),
         DefaultDatabase = "database",
         Url             = "http://localhost:8080",
     };
     var smugglerApi = new SmugglerApi(connectionStringOptions);
     smugglerApi.ExportData(new SmugglerOptions {
         File = "dump.raven", OperateOnTypes = ItemType.Documents | ItemType.Indexes | ItemType.Attachments
     });
     smugglerApi.ImportData(new SmugglerOptions {
         File = "dump.raven", OperateOnTypes = ItemType.Documents | ItemType.Indexes
     });
     #endregion
 }
コード例 #20
0
ファイル: RavenDB_1603.cs プロジェクト: stvoidmain/ravendb
        public async Task CanPerformDumpWithLimit_Smuggler()
        {
            var         backupPath = NewDataPath("BackupFolder");
            List <User> generatedUsers;

            using (var store = NewRemoteDocumentStore())
            {
                InsertUsers(store, 0, 2000, out generatedUsers);

                var options = new SmugglerOptions
                {
                    Limit       = 1500,
                    Incremental = true,
                    Filters     =
                    {
                        new FilterSetting
                        {
                            Path        = "@metadata.Raven-Entity-Name",
                            Values      = { "Users" },
                            ShouldMatch = true,
                        }
                    }
                };

                var dumper = new SmugglerApi();
                await dumper.ExportData(new SmugglerExportOptions
                {
                    From = new RavenConnectionStringOptions {
                        DefaultDatabase = store.DefaultDatabase, Url = "http://localhost:8079"
                    },
                    ToFile = backupPath
                }, options);
            }

            VerifyDump(backupPath, store =>
            {
                using (var session = store.OpenSession())
                {
                    Assert.Equal(1500, session.Query <User>().Customize(x => x.WaitForNonStaleResultsAsOfNow()).Count());
                }
            });
            IOExtensions.DeleteDirectory(backupPath);
        }
コード例 #21
0
        public void Export_And_Import_Retains_HiLoState()
        {
            using (var session = documentStore.OpenSession())
            {
                var foo = new Foo {
                    Something = "something2"
                };
                Assert.Null(foo.Id);
                session.Store(foo);
                Assert.NotNull(foo.Id);
                session.SaveChanges();
            }

            var smugglerApi = new SmugglerApi(new SmugglerOptions(), new RavenConnectionStringOptions {
                Url = "http://localhost:8079/"
            });

            smugglerApi.ExportData(new SmugglerOptions {
                BackupPath = DumpFile
            });
            Assert.True(File.Exists(DumpFile));

            using (var session = documentStore.OpenSession())
            {
                var hilo = session.Load <HiLoKey>("Raven/Hilo/foos");
                Assert.NotNull(hilo);
                Assert.Equal(32, hilo.Max);
            }

            server.Dispose();
            CreateServer();

            smugglerApi.ImportData(new SmugglerOptions {
                BackupPath = DumpFile
            });

            using (var session = documentStore.OpenSession())
            {
                var hilo = session.Load <HiLoKey>("Raven/Hilo/foos");
                Assert.NotNull(hilo);
                Assert.Equal(32, hilo.Max);
            }
        }
コード例 #22
0
        public void Export_Incremental_not_overwrites_Files()
        {
            IOExtensions.DeleteDirectory("Incremental");

            var smugglerApi = new SmugglerApi(new RavenConnectionStringOptions {
                Url = "http://localhost:8079/"
            });

            for (int i = 0; i < 50; i++)
            {
                smugglerApi.ExportData(new SmugglerOptions
                {
                    File           = "Incremental",
                    OperateOnTypes = ItemType.Documents | ItemType.Indexes | ItemType.Attachments
                }, incremental: true);
            }

            Assert.Equal(Directory.GetFiles("Incremental").Length, 51);            //50 .dump.inc files and 1 LastEtags.txt
        }
コード例 #23
0
        public async Task CanDumpWhenHiddenDocs_Smuggler()
        {
            var backupPath = NewDataPath("BackupFolder");

            using (NewRemoteDocumentStore())
            {
                using (var store = new DocumentStore {
                    Url = "http://localhost:8079"
                }.Initialize())
                {
                    InsertHidenUsers(store, 2000);

                    var user1 = store.DatabaseCommands.Get("users/1");
                    Assert.Null(user1);

                    InsertUsers(store, 1, 25);

                    // now perform full backup
                    var options = new SmugglerOptions
                    {
                        BackupPath = backupPath,
                    };
                    var dumper = new SmugglerApi(options, new RavenConnectionStringOptions
                    {
                        Url = "http://localhost:8079",
                    });
                    var backupStatus = new PeriodicBackupStatus();
                    await dumper.ExportData(null, null, true, backupStatus);
                }
            }

            VerifyDump(backupPath, store =>
            {
                using (var session = store.OpenSession())
                {
                    Assert.Equal(25, session.Query <User>().Customize(x => x.WaitForNonStaleResultsAsOfNow()).Count());
                }
            });

            IOExtensions.DeleteDirectory(backupPath);
        }
コード例 #24
0
        public async Task CanPerformDumpWithLimit_Smuggler()
        {
            var backupPath = NewDataPath("BackupFolder");

            using (var store = NewRemoteDocumentStore())
            {
                InsertUsers(store, 0, 2000);

                var options = new SmugglerOptions
                {
                    Limit      = 1500,
                    BackupPath = backupPath,
                    Filters    =
                    {
                        new FilterSetting
                        {
                            Path        = "@metadata.Raven-Entity-Name",
                            Values      = { "Users" },
                            ShouldMatch = true,
                        }
                    }
                };
                var dumper = new SmugglerApi(options, new RavenConnectionStringOptions
                {
                    Url = "http://localhost:8079",
                });
                var backupStatus = new PeriodicBackupStatus();
                await dumper.ExportData(null, null, true, backupStatus);
            }


            VerifyDump(backupPath, store =>
            {
                using (var session = store.OpenSession())
                {
                    Assert.Equal(1500, session.Query <User>().Customize(x => x.WaitForNonStaleResultsAsOfNow()).Count());
                }
            });
            IOExtensions.DeleteDirectory(backupPath);
        }
コード例 #25
0
ファイル: RDBQA_6.cs プロジェクト: stvoidmain/ravendb
        public async Task SmugglerShouldThrowIfDatabaseDoesNotExist()
        {
            var path = Path.GetTempFileName();

            try
            {
                using (var store = NewRemoteDocumentStore())
                {
                    var smuggler = new SmugglerApi();

                    var e = await AssertAsync.Throws <SmugglerException>(() => smuggler.ImportData(new SmugglerImportOptions
                    {
                        FromFile = path,
                        To       = new RavenConnectionStringOptions
                        {
                            Url             = store.Url,
                            DefaultDatabase = "DoesNotExist"
                        }
                    }, new SmugglerOptions()));

                    Assert.Equal(string.Format("Smuggler does not support database creation (database 'DoesNotExist' on server '{0}' must exist before running Smuggler).", store.Url), e.Message);

                    e = await AssertAsync.Throws <SmugglerException>(() => smuggler.ExportData(new SmugglerExportOptions
                    {
                        ToFile = path,
                        From   = new RavenConnectionStringOptions
                        {
                            Url             = store.Url,
                            DefaultDatabase = "DoesNotExist"
                        }
                    }, new SmugglerOptions()));

                    Assert.Equal(string.Format("Smuggler does not support database creation (database 'DoesNotExist' on server '{0}' must exist before running Smuggler).", store.Url), e.Message);
                }
            }
            finally
            {
                IOExtensions.DeleteFile(path);
            }
        }
コード例 #26
0
ファイル: RDBQA_6.cs プロジェクト: stvoidmain/ravendb
        public async Task SmugglerShouldNotThrowIfDatabaseExist1()
        {
            var path = Path.GetTempFileName();

            try
            {
                using (var store = NewRemoteDocumentStore())
                {
                    store.DatabaseCommands.GlobalAdmin.EnsureDatabaseExists("DoesNotExist");

                    var smuggler = new SmugglerApi();

                    await smuggler.ImportData(new SmugglerImportOptions
                    {
                        FromFile = path,
                        To       = new RavenConnectionStringOptions
                        {
                            Url             = store.Url,
                            DefaultDatabase = "DoesNotExist"
                        }
                    }, new SmugglerOptions());

                    await smuggler.ExportData(new SmugglerExportOptions
                    {
                        ToFile = path,
                        From   = new RavenConnectionStringOptions
                        {
                            Url             = store.Url,
                            DefaultDatabase = "DoesNotExist"
                        }
                    }, new SmugglerOptions());
                }
            }
            finally
            {
                IOExtensions.DeleteFile(path);
            }
        }
コード例 #27
0
        public async Task SmugglerShouldNotThrowIfDatabaseExist2()
        {
            var path = Path.GetTempFileName();

            try
            {
                using (var store = NewRemoteDocumentStore())
                {
                    var connectionStringOptions = new RavenConnectionStringOptions {
                        Url = store.Url, DefaultDatabase = store.DefaultDatabase
                    };
                    var smuggler = new SmugglerApi();

                    await smuggler.ImportData(new SmugglerImportOptions { FromFile = path, To = connectionStringOptions });

                    await smuggler.ExportData(new SmugglerExportOptions { ToFile = path, From = connectionStringOptions });
                }
            }
            finally
            {
                IOExtensions.DeleteFile(path);
            }
        }
コード例 #28
0
ファイル: RavenDB_1603.cs プロジェクト: stvoidmain/ravendb
        public async Task CanDumpEmptyDatabase_Smuggler()
        {
            var backupPath = NewDataPath("BackupFolder");

            using (var store = NewRemoteDocumentStore())
            {
                // now perform full backup
                var dumper = new SmugglerApi();
                await dumper.ExportData(new SmugglerExportOptions
                {
                    ToFile = backupPath,
                    From   = new RavenConnectionStringOptions
                    {
                        Url             = "http://localhost:8079",
                        DefaultDatabase = store.DefaultDatabase,
                    }
                }, new SmugglerOptions { Incremental = true });
            }

            VerifyDump(backupPath, store => Assert.Equal(0, store.DocumentDatabase.Documents.GetDocuments(0, int.MaxValue, null, CancellationToken.None).Count()));

            IOExtensions.DeleteDirectory(backupPath);
        }
コード例 #29
0
ファイル: RavenDB_1603.cs プロジェクト: stvoidmain/ravendb
        public async Task CanDumpAttachmentsWithLimit_Smuggler()
        {
            var backupPath = NewDataPath("BackupFolder");

            using (var store = NewRemoteDocumentStore())
            {
                InsertAttachments(store, 328);

                var dumper = new SmugglerApi();
                await dumper.ExportData(new SmugglerExportOptions
                {
                    ToFile = backupPath,
                    From   = new RavenConnectionStringOptions
                    {
                        Url             = "http://localhost:8079",
                        DefaultDatabase = store.DefaultDatabase,
                    }
                }, new SmugglerOptions { Incremental = true, BatchSize = 100, Limit = 206 });
            }

            VerifyDump(backupPath, store => Assert.Equal(206, store.DatabaseCommands.GetAttachmentHeadersStartingWith("user", 0, 500).Count()));
            IOExtensions.DeleteDirectory(backupPath);
        }
コード例 #30
0
        public async Task CanDumpEmptyDatabase_Smuggler()
        {
            var backupPath = NewDataPath("BackupFolder");

            using (NewRemoteDocumentStore())
            {
                // now perform full backup
                var options = new SmugglerOptions
                {
                    BackupPath = backupPath,
                };
                var dumper = new SmugglerApi(options, new RavenConnectionStringOptions
                {
                    Url = "http://localhost:8079",
                });
                var backupStatus = new PeriodicBackupStatus();
                await dumper.ExportData(null, null, true, backupStatus);
            }

            VerifyDump(backupPath, store => Assert.Equal(0, store.DocumentDatabase.GetDocuments(0, int.MaxValue, null, CancellationToken.None).Count()));

            IOExtensions.DeleteDirectory(backupPath);
        }