public BackupRestoreTests()
        {
            DeleteTempFolders();

            var uniqueId = Guid.NewGuid();

            BackupDestinationDirectory += uniqueId;
            BackupSourceDirectory      += uniqueId;
            RestoreToDirectory         += uniqueId;
            DocumentDatabaseDirectory  += uniqueId;

            config = new RavenConfiguration
            {
                Port                    = 8090,
                DataDirectory           = DocumentDatabaseDirectory,
                RunInMemory             = false,
                DefaultStorageTypeName  = "Voron",
                AnonymousUserAccessMode = AnonymousUserAccessMode.Admin,
                Encryption              = { UseFips = ConfigurationHelper.UseFipsEncryptionAlgorithms },
            };

            config.Counter.DataDirectory             = BackupSourceDirectory;
            config.Settings["Raven/StorageTypeName"] = config.DefaultStorageTypeName;
            config.PostInit();

            storage = new CounterStorage("http://localhost:8080", "TestCounter", config);
            storage.Environment.Options.IncrementalBackupEnabled = true;
        }
Exemple #2
0
        public void StartDatabase(int index)
        {
            var previousServer = servers[index];

            NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(previousServer.SystemDatabase.Configuration.Port);
            var serverConfiguration = new RavenConfiguration
            {
                Settings = { { "Raven/ActiveBundles", "replication" } },
                AnonymousUserAccessMode = AnonymousUserAccessMode.Admin,
                DataDirectory           = previousServer.SystemDatabase.Configuration.DataDirectory,
                RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
                RunInMemory            = previousServer.SystemDatabase.Configuration.RunInMemory,
                Port                   = previousServer.SystemDatabase.Configuration.Port,
                DefaultStorageTypeName = GetDefaultStorageType()
            };

            serverConfiguration.Encryption.UseFips = SettingsHelper.UseFipsEncryptionAlgorithms;

            ModifyConfiguration(serverConfiguration);

            serverConfiguration.PostInit();
            var ravenDbServer = new RavenDbServer(serverConfiguration)
            {
                UseEmbeddedHttpServer = true
            };

            ravenDbServer.Initialize(ConfigureServer);

            servers[index] = ravenDbServer;
        }
Exemple #3
0
        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);
        }
        /// <summary>
        /// Initialize the document store access method to RavenDB
        /// </summary>
        protected override void InitializeInternal()
        {
            if (string.IsNullOrEmpty(Url) == false && string.IsNullOrEmpty(DataDirectory) == false)
            {
                throw new InvalidOperationException("You cannot specify both Url and DataDirectory at the same time. Url implies running in client/server mode against the remote server. DataDirectory implies running in embedded mode. Those two options are incompatible");
            }

            if (string.IsNullOrEmpty(DataDirectory) == false && string.IsNullOrEmpty(DefaultDatabase) == false)
            {
                throw new InvalidOperationException("You cannot specify DefaultDatabase value when the DataDirectory has been set, running in Embedded mode, the Default Database is not a valid option.");
            }

            if (configuration != null && Url == null)
            {
                configuration.PostInit();
                if (configuration.RunInMemory || configuration.RunInUnreliableYetFastModeThatIsNotSuitableForProduction)
                {
                    ResourceManagerId = Guid.NewGuid();                     // avoid conflicts
                }
                configuration.SetSystemDatabase();
                DocumentDatabase = new DocumentDatabase(configuration);
                DocumentDatabase.SpinBackgroundWorkers();
                if (UseEmbeddedHttpServer)
                {
                    SetStudioConfigToAllowSingleDb();
                    httpServer = new HttpServer(configuration, DocumentDatabase);
                    httpServer.StartListening();
                }
                else                 // we need to setup our own idle timer
                {
                    idleTimer = new Timer(state =>
                    {
                        try
                        {
                            DocumentDatabase.RunIdleOperations();
                        }
                        catch (Exception e)
                        {
                            log.WarnException("Error during database idle operations", e);
                        }
                    }, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
                }
                databaseCommandsGenerator      = () => new EmbeddedDatabaseCommands(DocumentDatabase, Conventions, currentSessionId, listeners.ConflictListeners);
                asyncDatabaseCommandsGenerator = () => new EmbeddedAsyncServerClient(this, DatabaseCommands);
            }
            else
            {
                base.InitializeInternal();
            }
        }
Exemple #5
0
        private DocumentStore CreateStoreAtPort(int port, bool enableCompressionBundle = false, bool removeDataDirectory = true, Action <DocumentStore> configureStore = null, AnonymousUserAccessMode anonymousUserAccessMode = AnonymousUserAccessMode.Admin, bool enableAuthorization = false, string requestedStorage = null)
        {
            NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port);

            var storageType = GetDefaultStorageType(requestedStorage);

            var serverConfiguration = new RavenConfiguration
            {
                Settings = { { "Raven/ActiveBundles", "replication" + (enableCompressionBundle ? ";compression" : string.Empty) } },
                AnonymousUserAccessMode = anonymousUserAccessMode,
                DataDirectory           = Path.Combine("Database #" + stores.Count, "SysDb"),
                RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
                RunInMemory            = storageType.Equals("esent", StringComparison.OrdinalIgnoreCase) == false,
                Port                   = port,
                DefaultStorageTypeName = storageType
            };

            ConfigureServer(serverConfiguration);
            if (removeDataDirectory)
            {
                IOExtensions.DeleteDirectory(serverConfiguration.DataDirectory);
            }

            serverConfiguration.PostInit();
            var ravenDbServer = new RavenDbServer(serverConfiguration);

            servers.Add(ravenDbServer);

            if (enableAuthorization)
            {
                EnableAuthentication(ravenDbServer.Database);
                ConfigureServer(serverConfiguration);
            }

            var documentStore = new DocumentStore {
                Url = ravenDbServer.Database.Configuration.ServerUrl
            };

            ConfigureStore(documentStore);
            if (configureStore != null)
            {
                configureStore(documentStore);
            }
            documentStore.Initialize();

            stores.Add(documentStore);

            ConfigureDatabase(ravenDbServer.Database);
            return(documentStore);
        }
Exemple #6
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);
        }
 /// <summary>
 /// Initialize the document store access method to RavenDB
 /// </summary>
 protected override void InitializeInternal()
 {
     if (configuration != null && Url == null)
     {
         configuration.PostInit();
         if (configuration.RunInMemory || configuration.RunInUnreliableYetFastModeThatIsNotSuitableForProduction)
         {
             ResourceManagerId = Guid.NewGuid();                     // avoid conflicts
         }
         DocumentDatabase = new DocumentDatabase(configuration);
         DocumentDatabase.SpinBackgroundWorkers();
         if (UseEmbeddedHttpServer)
         {
             httpServer = new HttpServer(configuration, DocumentDatabase);
             httpServer.StartListening();
         }
         databaseCommandsGenerator = () => new EmbeddedDatabaseCommands(DocumentDatabase, Conventions, currentSessionId);
     }
     else
     {
         base.InitializeInternal();
     }
 }
Exemple #8
0
        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);
        }
Exemple #9
0
        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;
        }
Exemple #10
0
		protected RavenDbServer GetNewServer(int port = 8079,
			string dataDirectory = null, 
			bool runInMemory = true,
			string requestedStorage = null,
			bool deleteDirectory = true, 
			bool enableAuthentication = false)
		{
			var storageType = GetDefaultStorageType(requestedStorage);
			var ravenConfiguration = new RavenConfiguration
			{
				Port = port,
				DataDirectory = dataDirectory ?? DataDir,
				RunInMemory = storageType.Equals("esent", StringComparison.OrdinalIgnoreCase) == false && runInMemory,
				DefaultStorageTypeName = storageType,
				AnonymousUserAccessMode = enableAuthentication ? AnonymousUserAccessMode.None : 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;
			}

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

			return ravenDbServer;
		}
Exemple #11
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;
		}