コード例 #1
0
 protected void RecycleServer()
 {
     ravenDbServer.Dispose();
     ravenDbServer = new RavenDbServer(settings)
     {
         UseEmbeddedHttpServer = true
     };
     ravenDbServer.Initialize();
 }
コード例 #2
0
        private void CreateServer()
        {
            IOExtensions.DeleteDirectory("HiLoData");
            if (server != null)
            {
                server.Dispose();
            }

            server = GetNewServer();
        }
コード例 #3
0
        public IDocumentStore NewRemoteDocumentStore(bool fiddler = false, RavenDbServer ravenDbServer = null, string databaseName = null,
                                                     bool deleteDirectoryAfter  = true,
                                                     bool deleteDirectoryBefore = true,
                                                     bool runInMemory           = true,
                                                     string requestedStorage    = null,
                                                     bool enableAuthentication  = false)
        {
            ravenDbServer = ravenDbServer ?? GetNewServer(runInMemory: runInMemory, requestedStorage: requestedStorage, deleteDirectory: deleteDirectoryBefore, enableAuthentication: enableAuthentication);
            ModifyServer(ravenDbServer);
            var store = new DocumentStore
            {
                Url             = GetServerUrl(fiddler),
                DefaultDatabase = databaseName,
            };

            store.AfterDispose += (sender, args) =>
            {
                ravenDbServer.Dispose();
                if (deleteDirectoryAfter)
                {
                    ClearDatabaseDirectory();
                }
            };
            ModifyStore(store);
            return(store.Initialize());
        }
コード例 #4
0
        protected RavenDbServer GetNewServer(int port, string path)
        {
            var ravenDbServer = new RavenDbServer(new RavenConfiguration
            {
                Port                    = port,
                DataDirectory           = path,
                RunInMemory             = true,
                AnonymousUserAccessMode = AnonymousUserAccessMode.All
            });

            try
            {
                using (var documentStore = new DocumentStore
                {
                    Url = "http://localhost:" + port
                }.Initialize())
                {
                    new RavenDocumentsByEntityName().Execute(documentStore);
                }
            }
            catch
            {
                ravenDbServer.Dispose();
                throw;
            }
            return(ravenDbServer);
        }
コード例 #5
0
        public DocumentStore NewRemoteDocumentStore(bool fiddler                          = false, RavenDbServer ravenDbServer = null, [CallerMemberName] string databaseName = null,
                                                    bool runInMemory                      = true,
                                                    string dataDirectory                  = null,
                                                    string requestedStorage               = null,
                                                    bool enableAuthentication             = false,
                                                    bool ensureDatabaseExists             = true,
                                                    Action <DocumentStore> configureStore = null)
        {
            databaseName = NormalizeDatabaseName(databaseName);

            checkPorts    = true;
            ravenDbServer = ravenDbServer ?? GetNewServer(runInMemory: runInMemory, dataDirectory: dataDirectory, requestedStorage: requestedStorage, enableAuthentication: enableAuthentication, databaseName: databaseName);
            ModifyServer(ravenDbServer);
            var store = new DocumentStore
            {
                Url             = GetServerUrl(fiddler, ravenDbServer.SystemDatabase.ServerUrl),
                DefaultDatabase = databaseName
            };

            pathsToDelete.Add(Path.Combine(ravenDbServer.SystemDatabase.Configuration.DataDirectory, @"..\Databases"));
            stores.Add(store);
            store.AfterDispose += (sender, args) => ravenDbServer.Dispose();

            if (configureStore != null)
            {
                configureStore(store);
            }
            ModifyStore(store);

            store.Initialize(ensureDatabaseExists);
            return(store);
        }
コード例 #6
0
        public override void Dispose()
        {
            documentStore.Dispose();
            ravenDbServer.Dispose();

            base.Dispose();
        }
コード例 #7
0
        public override void Dispose()
        {
            store.Dispose();
            ravenDbServer.Dispose();

            base.Dispose();
        }
コード例 #8
0
 public override void Dispose()
 {
     documentStore.Dispose();
     server.Dispose();
     IOExtensions.DeleteDirectory(path);
     base.Dispose();
 }
コード例 #9
0
 public override void Dispose()
 {
     store.Dispose();
     ravenDbServer.Dispose();
     IOExtensions.DeleteDirectory(path);
     base.Dispose();
 }
コード例 #10
0
        public async Task Can_recover_from_shutdown_with_twoway_replication()
        {
            var           dataDirectory = "Data" + Guid.NewGuid();
            ICounterStore storeA        = null;
            RavenDbServer server        = null;

            try
            {
                server = GetNewServer(port: 8091, runInMemory: false, dataDirectory: dataDirectory);
                storeA = NewRemoteCountersStore(DefaultCounterStorageName + "A", ravenServer: server);

                using (var storeB = NewRemoteCountersStore(DefaultCounterStorageName + "B"))
                {
                    await SetupReplicationAsync(storeA, storeB);
                    await SetupReplicationAsync(storeB, storeA);

                    storeA.Dispose();
                    server.Dispose();
                    server = GetNewServer(port: 8091, runInMemory: false, dataDirectory: dataDirectory);
                    storeA = NewRemoteCountersStore(DefaultCounterStorageName + "A", ravenServer: server);

                    await storeA.ChangeAsync("group", "counter", 2);

                    await storeB.ChangeAsync("group", "counter", 3);

                    Assert.True(await WaitForReplicationBetween(storeA, storeB, "group", "counter"));
                }
            }
            finally
            {
                storeA?.Dispose();
                server?.Dispose();
                IOExtensions.DeleteDirectory(dataDirectory);
            }
        }
コード例 #11
0
        public void Dispose()
        {
            SystemTime.UtcDateTime = null;

            documentStore.Dispose();
            ravenDbServer.Dispose();
            Raven.Database.Extensions.IOExtensions.DeleteDirectory(path);
        }
コード例 #12
0
ファイル: RavenTestBase.cs プロジェクト: AndrewKL/ravendb
        protected RavenDbServer GetNewServer(int port                  = 8079,
                                             string dataDirectory      = null,
                                             bool runInMemory          = true,
                                             string requestedStorage   = null,
                                             bool enableAuthentication = false)
        {
            if (dataDirectory != null)
            {
                pathsToDelete.Add(dataDirectory);
            }

            var storageType        = GetDefaultStorageType(requestedStorage);
            var ravenConfiguration = new RavenConfiguration
            {
                Port                    = port,
                DataDirectory           = dataDirectory ?? NewDataPath(),
                RunInMemory             = storageType.Equals("esent", StringComparison.OrdinalIgnoreCase) == false && runInMemory,
                DefaultStorageTypeName  = storageType,
                AnonymousUserAccessMode = enableAuthentication ? AnonymousUserAccessMode.None : AnonymousUserAccessMode.Admin
            };

            ModifyConfiguration(ravenConfiguration);

            ravenConfiguration.PostInit();

            NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(ravenConfiguration.Port);
            var ravenDbServer = new RavenDbServer(ravenConfiguration);

            servers.Add(ravenDbServer);

            try
            {
                using (var documentStore = new DocumentStore
                {
                    Url = "http://localhost:" + port,
                    Conventions =
                    {
                        FailoverBehavior = FailoverBehavior.FailImmediately
                    },
                }.Initialize())
                {
                    CreateDefaultIndexes(documentStore);
                }
            }
            catch
            {
                ravenDbServer.Dispose();
                throw;
            }

            if (enableAuthentication)
            {
                EnableAuthentication(ravenDbServer.Database);
                ModifyConfiguration(ravenConfiguration);
            }

            return(ravenDbServer);
        }
コード例 #13
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 RavenConnectionStringOptions {
                Url = "http://localhost:8079/"
            });

            smugglerApi.ExportData(new SmugglerOptions {
                File = 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 {
                File = DumpFile
            });

            using (var session = documentStore.OpenSession())
            {
                var hilo = session.Load <HiLoKey>("Raven/Hilo/foos");
                Assert.NotNull(hilo);
                Assert.Equal(32, hilo.Max);
            }
        }
コード例 #14
0
        private void CreateServer()
        {
            IOExtensions.DeleteDirectory("HiLoData");
            if (server != null)
            {
                server.Dispose();
            }

            server = new RavenDbServer(new RavenConfiguration
            {
                Port          = 8079,
                DataDirectory = "HiLoData",
                RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
                AnonymousUserAccessMode = AnonymousUserAccessMode.Admin
            })
            {
                UseEmbeddedHttpServer = true
            };
            server.Initialize();
        }
コード例 #15
0
ファイル: Compression.cs プロジェクト: arelee/ravendb
        protected void Close()
        {
            if (closed)
            {
                return;
            }

            documentStore.Dispose();
            ravenDbServer.Dispose();
            closed = true;
        }
コード例 #16
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();
            }

            if (File.Exists("hilo-export.dump"))
            {
                File.Delete("hilo-export.dump");
            }
            Smuggler.Smuggler.ExportData(new Smuggler.Smuggler.ExportSpec("http://localhost:8079/", "hilo-export.dump", false, false));
            Assert.True(File.Exists("hilo-export.dump"));

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

            server.Dispose();
            CreateServer();

            Smuggler.Smuggler.ImportData("http://localhost:8079/", "hilo-export.dump");

            using (var session = documentStore.OpenSession()) {
                var hilo = session.Load <HiLoKey>("Raven/Hilo/foos");
                Assert.NotNull(hilo);
                Assert.Equal(32, hilo.Max);
            }
        }
コード例 #17
0
        public override void Dispose()
        {
            if (server1 != null)
            {
                server1.Dispose();
                if (server1.SystemDatabase != null)
                {
                    IOExtensions.DeleteDirectory(server1.SystemDatabase.Configuration.DataDirectory);
                }
            }

            if (store1 != null)
            {
                store1.Dispose();
            }
        }
コード例 #18
0
        public void Dispose()
        {
            server1.Dispose();
            server2.Dispose();

            Thread.Sleep(100);

            foreach (var path in new[] { path1, path2 })
            {
                try
                {
                    IOExtensions.DeleteDirectory(path);
                }
                catch (Exception) { }
            }
        }
コード例 #19
0
        public void Dispose()
        {
            server1.Dispose();
            server2.Dispose();

            Thread.Sleep(100);

            foreach (var path in new[] { path1, path2 })
            {
                try
                {
                    Directory.Delete(path, true);
                }
                catch (Exception) { }
            }
        }
コード例 #20
0
        public IDocumentStore NewRemoteDocumentStoreWithUrl(int port, bool fiddler    = false, RavenDbServer ravenDbServer = null, string databaseName = null,
                                                            bool runInMemory          = true,
                                                            string dataDirectory      = null,
                                                            string requestedStorage   = null,
                                                            bool enableAuthentication = false)
        {
            ravenDbServer = ravenDbServer ?? GetNewServer(runInMemory: runInMemory, dataDirectory: dataDirectory, requestedStorage: requestedStorage, enableAuthentication: enableAuthentication);
            ModifyServer(ravenDbServer);
            var store = new DocumentStore
            {
                Url             = GetServerUrl(port),
                DefaultDatabase = databaseName,
            };

            stores.Add(store);
            store.AfterDispose += (sender, args) => ravenDbServer.Dispose();
            ModifyStore(store);
            return(store.Initialize());
        }
コード例 #21
0
        protected RavenDbServer GetNewServer(int port = 8079, string dataDirectory = "Data", bool runInMemory = true, bool deleteDirectory = true)
        {
            var ravenConfiguration = new RavenConfiguration
            {
                Port                    = port,
                DataDirectory           = dataDirectory,
                RunInMemory             = runInMemory,
                AnonymousUserAccessMode = AnonymousUserAccessMode.Admin
            };

            ModifyConfiguration(ravenConfiguration);

            ravenConfiguration.PostInit();

            if (ravenConfiguration.RunInMemory == false && deleteDirectory)
            {
                IOExtensions.DeleteDirectory(ravenConfiguration.DataDirectory);
            }

            NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(ravenConfiguration.Port);
            var ravenDbServer = new RavenDbServer(ravenConfiguration);

            try
            {
                using (var documentStore = new DocumentStore
                {
                    Url = "http://localhost:" + port,
                    Conventions =
                    {
                        FailoverBehavior = FailoverBehavior.FailImmediately
                    },
                }.Initialize())
                {
                    CreateDefaultIndexes(documentStore);
                }
            }
            catch
            {
                ravenDbServer.Dispose();
                throw;
            }
            return(ravenDbServer);
        }
コード例 #22
0
        protected RavenDbServer GetNewServer(bool initializeDocumentsByEntitiyName = true)
        {
            var ravenConfiguration = new RavenConfiguration
            {
                Port                    = 8079,
                RunInMemory             = true,
                DataDirectory           = "Data",
                AnonymousUserAccessMode = AnonymousUserAccessMode.All
            };

            ConfigureServer(ravenConfiguration);

            if (ravenConfiguration.RunInMemory == false)
            {
                IOExtensions.DeleteDirectory(ravenConfiguration.DataDirectory);
            }

            NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(ravenConfiguration.Port);
            var ravenDbServer = new RavenDbServer(ravenConfiguration);

            if (initializeDocumentsByEntitiyName)
            {
                try
                {
                    using (var documentStore = new DocumentStore
                    {
                        Url = "http://localhost:8079"
                    }.Initialize())
                    {
                        new RavenDocumentsByEntityName().Execute(documentStore);
                    }
                }
                catch
                {
                    ravenDbServer.Dispose();
                    throw;
                }
            }

            return(ravenDbServer);
        }
コード例 #23
0
 /// <summary>
 ///     Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 /// <filterpriority>2</filterpriority>
 public void Dispose()
 {
     server.Dispose();
 }
コード例 #24
0
 public void Dispose()
 {
     store.Dispose();
     ravenDbServer.Dispose();
 }
コード例 #25
0
 public void Dispose()
 {
     documentStore.Dispose();
     ravenDbServer.Dispose();
     database::Raven.Database.Extensions.IOExtensions.DeleteDirectory(path);
 }
コード例 #26
0
 protected void RecycleServer()
 {
     ravenDbServer.Dispose();
     ravenDbServer = new RavenDbServer(settings);
 }
コード例 #27
0
 public void Dispose()
 {
     documentStore.Dispose();
     ravenDbServer.Dispose();
     IOExtensions.DeleteDirectory(path);
 }
コード例 #28
0
 public void Dispose()
 {
     store.Dispose();
     server.Dispose();
 }
コード例 #29
0
ファイル: RavenTestBase.cs プロジェクト: mynkow/ravendb
        protected RavenDbServer GetNewServer(int port                  = 8079,
                                             string dataDirectory      = null,
                                             bool runInMemory          = true,
                                             string requestedStorage   = null,
                                             bool enableAuthentication = false,
                                             string activeBundles      = null,
                                             Action <RavenDBOptions> configureServer             = null,
                                             Action <InMemoryRavenConfiguration> configureConfig = null,
                                             [CallerMemberName] string databaseName = null)
        {
            databaseName = NormalizeDatabaseName(databaseName != Constants.SystemDatabase ? databaseName : null);

            checkPorts = true;
            if (dataDirectory != null)
            {
                pathsToDelete.Add(dataDirectory);
            }

            var storageType        = GetDefaultStorageType(requestedStorage);
            var directory          = dataDirectory ?? NewDataPath(databaseName == Constants.SystemDatabase ? null : databaseName);
            var ravenConfiguration = new RavenConfiguration();

            ConfigurationHelper.ApplySettingsToConfiguration(ravenConfiguration);

            ravenConfiguration.Port          = port;
            ravenConfiguration.DataDirectory = Path.Combine(directory, "System");
            ravenConfiguration.RunInMemory   = runInMemory;
#if DEBUG
            ravenConfiguration.RunInUnreliableYetFastModeThatIsNotSuitableForProduction = runInMemory;
#endif
            ravenConfiguration.DefaultStorageTypeName  = storageType;
            ravenConfiguration.AnonymousUserAccessMode = enableAuthentication ? AnonymousUserAccessMode.None : AnonymousUserAccessMode.Admin;

            ravenConfiguration.FileSystem.DataDirectory = Path.Combine(directory, "FileSystem");
            ravenConfiguration.Encryption.UseFips       = ConfigurationHelper.UseFipsEncryptionAlgorithms;

            ravenConfiguration.Settings["Raven/StorageTypeName"] = ravenConfiguration.DefaultStorageTypeName;

            if (activeBundles != null)
            {
                ravenConfiguration.Settings["Raven/ActiveBundles"] = activeBundles;
            }

            if (configureConfig != null)
            {
                configureConfig(ravenConfiguration);
            }
            ModifyConfiguration(ravenConfiguration);

            ravenConfiguration.PostInit();

            NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(ravenConfiguration.Port);
            var ravenDbServer = new RavenDbServer(ravenConfiguration)
            {
                UseEmbeddedHttpServer = true,
            };
            ravenDbServer.Initialize(configureServer);
            servers.Add(ravenDbServer);

            try
            {
                using (var documentStore = new DocumentStore
                {
                    Url = "http://localhost:" + port,
                    Conventions =
                    {
                        FailoverBehavior = FailoverBehavior.FailImmediately
                    },
                    DefaultDatabase = databaseName
                }.Initialize())
                {
                    CreateDefaultIndexes(documentStore);
                }
            }
            catch
            {
                ravenDbServer.Dispose();
                throw;
            }

            if (enableAuthentication)
            {
                EnableAuthentication(ravenDbServer.SystemDatabase);
                ModifyConfiguration(ravenConfiguration);
                ravenConfiguration.PostInit();
            }

            return(ravenDbServer);
        }
コード例 #30
0
ファイル: RavenTestBase.cs プロジェクト: mynkow/ravendb
        /// <summary>
        /// Creates a new document store connecting to a remote RavenDb server.
        /// </summary>
        /// <param name="fiddler">Are all requests to the remote RavenDb server passed through Fiddler? (NOTE: This is only* for a localhost RavenDb server).</param>
        /// <param name="ravenDbServer">A RavenDb server.</param>
        /// <param name="databaseName">Name of the server that will show up on /admin/stats endpoint.</param>
        /// <param name="runInMemory">Whatever the database should run purely in memory. When running in memory, nothing is written to disk and if the server is restarted all data will be lost.<br/>Default: <b>true</b></param>
        /// <param name="dataDirectory">The path for the database directory. Can use ~\ as the root, in which case the path will start from the server base directory. <br/>Default: <b>~\Databases\System</b></param>
        /// <param name="requestedStorage">What storage type to use (see: RavenDB Storage engines).<br/>Allowed values: <b>vornon</b>, <b>esent</b>.<br/>Default: <b>voron</b></param>
        /// <param name="enableAuthentication"></param>
        /// <param name="ensureDatabaseExists">For a multi-tenant RavenDb server, creates the database if it doesn't already exist.</param>
        /// <param name="configureStore">An action delegate which allows you to configure the document store instance that is returned. eg. <code>configureStore: store => store.DefaultDatabase = "MasterDb"</code></param>
        /// <param name="activeBundles">Semicolon separated list of bundles names, such as: 'Replication;Versioning'.<br/>Default: no bundles turned on.</param>
        /// <param name="indexes">A collection of indexes to execute.</param>
        /// <param name="transformers">A collection of transformers to execute.</param>
        /// <param name="seedData">A collection of some fake data that will be automatically stored into the document store.</param>
        /// <param name="noStaleQueries">When you query an index, the query will wait for the index to complete it's indexing and not be stale -before- the query is executred.</param>
        /// <returns></returns>
        public DocumentStore NewRemoteDocumentStore(bool fiddler = false,
                                                    RavenDbServer ravenDbServer            = null,
                                                    [CallerMemberName] string databaseName = null,
                                                    bool runInMemory                                           = true,
                                                    string dataDirectory                                       = null,
                                                    string requestedStorage                                    = null,
                                                    bool enableAuthentication                                  = false,
                                                    bool ensureDatabaseExists                                  = true,
                                                    Action <DocumentStore> configureStore                      = null,
                                                    string activeBundles                                       = null,
                                                    IEnumerable <AbstractIndexCreationTask> indexes            = null,
                                                    IEnumerable <AbstractTransformerCreationTask> transformers = null,
                                                    IEnumerable <IEnumerable> seedData                         = null,
                                                    bool noStaleQueries                                        = false)
        {
            databaseName = NormalizeDatabaseName(databaseName);

            checkPorts    = true;
            ravenDbServer = ravenDbServer ?? GetNewServer(runInMemory: runInMemory,
                                                          dataDirectory: dataDirectory,
                                                          requestedStorage: requestedStorage,
                                                          enableAuthentication: enableAuthentication,
                                                          databaseName: databaseName,
                                                          activeBundles: activeBundles);
            ModifyServer(ravenDbServer);
            var documentStore = new DocumentStore
            {
                Url             = GetServerUrl(fiddler, ravenDbServer.SystemDatabase.ServerUrl),
                DefaultDatabase = databaseName
            };

            pathsToDelete.Add(Path.Combine(ravenDbServer.SystemDatabase.Configuration.DataDirectory, @"..\Databases"));
            stores.Add(documentStore);
            documentStore.AfterDispose += (sender, args) => ravenDbServer.Dispose();

            if (configureStore != null)
            {
                configureStore(documentStore);
            }

            ModifyStore(documentStore);

            documentStore.Initialize(ensureDatabaseExists);

            if (indexes != null)
            {
                ExecuteIndexes(indexes, documentStore);
            }

            if (noStaleQueries)
            {
                // When querying any map/reduce indexes, we'll wait until
                // the index has stopped being stale.
                documentStore.Listeners.RegisterListener(new NoStaleQueriesListener());
            }

            if (transformers != null)
            {
                ExecuteTransformers(transformers, documentStore);
            }

            if (seedData != null)
            {
                StoreSeedData(seedData, documentStore);
            }

            return(documentStore);
        }