Ejemplo n.º 1
0
        public void Can_extend_queries()
        {
            var documents =
                GetDocumentsFromString(
                    @"[{loc: 4, lang: 3, '@metadata': {'@id': 1}}]");
            var configuration = new InMemoryRavenConfiguration();

            configuration.Initialize();
            var transformer = new DynamicViewCompiler("pagesByTitle", new IndexDefinition
            {
                Map = @"
from doc in docs
select new { GeoHash = PerformingQueries.SampleGeoLocation.GeoHash(doc.loc, doc.lang) }
"
            },
                                                      new OrderedPartCollection <AbstractDynamicCompilationExtension>
            {
                new SampleDynamicCompilationExtension()
            }, ".", configuration);
            var compiledQuery = transformer.GenerateInstance();
            var actual        = compiledQuery.MapDefinitions[0](documents)
                                .Cast <object>().ToArray();
            var expected = new[]
            {
                "{ GeoHash = 4#3, __document_id = 1 }",
            };

            Assert.Equal(expected.Length, actual.Length);
            for (var i = 0; i < expected.Length; i++)
            {
                Assert.Equal(expected[i], actual[i].ToString());
            }
        }
Ejemplo n.º 2
0
 protected override void ModifyConfiguration(InMemoryRavenConfiguration configuration)
 {
     configuration.Settings["Raven/Esent/CircularLog"]                      = "false";
     configuration.Settings["Raven/Voron/AllowIncrementalBackups"]          = "true";
     configuration.RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false;
     configuration.Initialize();
 }
Ejemplo n.º 3
0
        protected override bool TryGetOrCreateResourceStore(string tenantId, out IResourceStore database)
        {
            if (ResourcesStoresCache.TryGetValue(tenantId, out database))
                return true;

            var jsonDocument = DefaultDatabase.Get("Raven/Databases/" + tenantId, null);

            if (jsonDocument == null)
                return false;

            var document = jsonDocument.DataAsJson.JsonDeserialization<DatabaseDocument>();

            database = ResourcesStoresCache.GetOrAdd(tenantId, s =>
            {
                var config = new InMemoryRavenConfiguration
                {
                    Settings = DefaultConfiguration.Settings,
                };
                config.Settings["Raven/VirtualDir"] = config.Settings["Raven/VirtualDir"] + "/" + tenantId;
                foreach (var setting in document.Settings)
                {
                    config.Settings[setting.Key] = setting.Value;
                }
                config.Initialize();
                return new DocumentDatabase(config);
            });
            return true;


        }
Ejemplo n.º 4
0
		protected override void ModifyConfiguration(InMemoryRavenConfiguration configuration)
		{
			configuration.Settings["Raven/Esent/CircularLog"] = "false";
			configuration.Settings["Raven/Voron/AllowIncrementalBackups"] = "true";
			configuration.RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false;
			configuration.Initialize();
		}
Ejemplo n.º 5
0
        protected InMemoryRavenConfiguration CreateConfiguration(
            string tenantId,
            FileSystemDocument document,
            string folderPropName,
            InMemoryRavenConfiguration parentConfiguration)
        {
            var config = new InMemoryRavenConfiguration
            {
                Settings = new NameValueCollection(parentConfiguration.Settings),
            };

            SetupTenantConfiguration(config);

            config.CustomizeValuesForFileSystemTenant(tenantId);
            config.Settings[Constants.FileSystem.Storage] = parentConfiguration.FileSystem.DefaultStorageTypeName;

            foreach (var setting in document.Settings)
            {
                config.Settings[setting.Key] = setting.Value;
            }
            Unprotect(document);

            foreach (var securedSetting in document.SecuredSettings)
            {
                config.Settings[securedSetting.Key] = securedSetting.Value;
            }

            config.Settings[folderPropName] = config.Settings[folderPropName].ToFullPath(parentConfiguration.FileSystem.DataDirectory);
            config.FileSystemName           = tenantId;

            config.Initialize();
            config.CopyParentSettings(parentConfiguration);
            return(config);
        }
Ejemplo n.º 6
0
        public void ChangingWorkingDirectoryShouldImpactPaths()
        {
            string WorkingDirectoryValue = "C:\\Raven\\";

            if (EnvironmentUtils.RunningOnPosix == true)
            {
                WorkingDirectoryValue = Environment.GetEnvironmentVariable("HOME") + @"\";
            }

            var inMemoryConfiguration = new InMemoryRavenConfiguration();

            inMemoryConfiguration.Settings["Raven/WorkingDir"] = WorkingDirectoryValue;
            inMemoryConfiguration.Initialize();

            var basePath         = FilePathTools.MakeSureEndsWithSlash(AppDomain.CurrentDomain.BaseDirectory.ToFullPath());
            var workingDirectory = inMemoryConfiguration.WorkingDirectory;

            Assert.Equal(WorkingDirectoryValue, inMemoryConfiguration.WorkingDirectory);
            Assert.NotEqual(basePath, workingDirectory);
            Assert.True(inMemoryConfiguration.AssembliesDirectory.StartsWith(WorkingDirectoryValue));
            Assert.True(inMemoryConfiguration.CompiledIndexCacheDirectory.StartsWith(WorkingDirectoryValue));
            Assert.True(inMemoryConfiguration.DataDirectory.StartsWith(WorkingDirectoryValue));
            Assert.True(inMemoryConfiguration.FileSystem.DataDirectory.StartsWith(WorkingDirectoryValue));
            Assert.True(inMemoryConfiguration.Counter.DataDirectory.StartsWith(WorkingDirectoryValue));
            Assert.True(inMemoryConfiguration.TimeSeries.DataDirectory.StartsWith(WorkingDirectoryValue));
        }
Ejemplo n.º 7
0
        private static ISignatureRepository CreateSignatureRepositoryFor(string fileName)
        {
            var configuration = new InMemoryRavenConfiguration();

            configuration.Initialize();
            return(new VolatileSignatureRepository(fileName, configuration));
        }
Ejemplo n.º 8
0
        public SigGeneratorTest()
        {
            configuration = new InMemoryRavenConfiguration();
            configuration.Initialize();

            TestDataGenerators.WriteNumbers(_stream, 10000);
            _stream.Position = 0;
        }
Ejemplo n.º 9
0
 public SubscriptionTests()
 {
     configuration = new InMemoryRavenConfiguration
     {
         RunInMemory = true
     };
     configuration.Initialize();
     ravenMqServer = new RavenMqServer(configuration);
 }
Ejemplo n.º 10
0
 public SubscriptionTests()
 {
     configuration = new InMemoryRavenConfiguration
     {
         RunInMemory = true
     };
     configuration.Initialize();
     ravenMqServer = new RavenMqServer(configuration);
 }
Ejemplo n.º 11
0
        protected bool TryGetOrCreateResourceStore(string tenantId, out DocumentDatabase database)
        {
            if (ResourcesStoresCache.TryGetValue(tenantId, out database))
            {
                return(true);
            }

            JsonDocument jsonDocument;

            using (DefaultResourceStore.DisableAllTriggersForCurrentThread())
                jsonDocument = DefaultResourceStore.Get("Raven/Databases/" + tenantId, null);

            if (jsonDocument == null ||
                jsonDocument.Metadata == null ||
                jsonDocument.Metadata.Value <bool>(Constants.RavenDocumentDoesNotExists))
            {
                return(false);
            }

            var document = jsonDocument.DataAsJson.JsonDeserialization <DatabaseDocument>();

            database = ResourcesStoresCache.GetOrAddAtomically(tenantId, s =>
            {
                var config = new InMemoryRavenConfiguration
                {
                    Settings = DefaultConfiguration.Settings,
                };
                foreach (var setting in document.Settings)
                {
                    config.Settings[setting.Key] = setting.Value;
                }
                var dataDir = config.Settings["Raven/DataDir"];
                if (dataDir == null)
                {
                    throw new InvalidOperationException("Could not find Raven/DataDir");
                }
                if (dataDir.StartsWith("~/") || dataDir.StartsWith(@"~\"))
                {
                    var baseDataPath = Path.GetDirectoryName(DefaultResourceStore.Configuration.DataDirectory);
                    if (baseDataPath == null)
                    {
                        throw new InvalidOperationException("Could not find root data path");
                    }
                    config.Settings["Raven/DataDir"] = Path.Combine(baseDataPath, dataDir.Substring(2));
                }
                config.Settings["Raven/VirtualDir"] = config.Settings["Raven/VirtualDir"] + "/" + tenantId;

                config.DatabaseName = tenantId;

                config.Initialize();
                var documentDatabase = new DocumentDatabase(config);
                documentDatabase.SpinBackgroundWorkers();
                return(documentDatabase);
            });
            return(true);
        }
Ejemplo n.º 12
0
        public static void ApplySettingsToConfiguration(InMemoryRavenConfiguration configuration)
        {
            var settings = Settings;

            foreach (var setting in settings)
            {
                configuration.Settings[setting.Key] = setting.Value;
            }

            configuration.Initialize();
        }
Ejemplo n.º 13
0
        public SynchronizationStorageTests()
        {
            configuration = new InMemoryRavenConfiguration();
            configuration.Initialize();

            source      = (IAsyncFilesCommandsImpl)NewAsyncClient(0);
            destination = (IAsyncFilesCommandsImpl)NewAsyncClient(1);

            sourceRfs      = GetFileSystem(0);
            destinationRfs = GetFileSystem(1);
        }
Ejemplo n.º 14
0
        private void Compile(string code)
        {
            var configuration = new InMemoryRavenConfiguration();

            configuration.Initialize();
            var dynamicViewCompiler = new DynamicViewCompiler("test", new IndexDefinition
            {
                Map = code
            }, new OrderedPartCollection <AbstractDynamicCompilationExtension>(), ".", configuration);

            dynamicViewCompiler.GenerateInstance();
        }
Ejemplo n.º 15
0
        public static void ApplySettingsToConfiguration(InMemoryRavenConfiguration configuration)
        {
            var settings = ServerSettings;

            foreach (var setting in settings)
            {
                Console.WriteLine("Applying external server setting: " + setting.Key);

                configuration.Settings[setting.Key] = setting.Value;
            }

            configuration.Initialize();
        }
Ejemplo n.º 16
0
        protected PrefetcherWithContext CreatePrefetcher(
            Action <InMemoryRavenConfiguration> modifyConfiguration = null,
            Action <WorkContext> modifyWorkContext = null,
            HashSet <string> entityNames           = null)
        {
            var configuration = new InMemoryRavenConfiguration
            {
                RunInMemory = true
            };

            configuration.Initialize();

            if (modifyConfiguration != null)
            {
                modifyConfiguration(configuration);
            }

            var transactionalStorage = new TransactionalStorage(configuration, () => { }, () => { }, () => { }, () => { });

            transactionalStorage.Initialize(new SequentialUuidGenerator {
                EtagBase = 0
            }, new OrderedPartCollection <AbstractDocumentCodec>());

            var workContext = new WorkContext
            {
                Configuration        = configuration,
                TransactionalStorage = transactionalStorage
            };

            if (modifyWorkContext != null)
            {
                modifyWorkContext(workContext);
            }

            var autoTuner = new IndexBatchSizeAutoTuner(workContext);

            var prefetchingBehavior = new PrefetchingBehavior(PrefetchingUser.Indexer, workContext, autoTuner, string.Empty, entityNames);

            var prefetcherWithContext = new PrefetcherWithContext
            {
                AutoTuner            = autoTuner,
                Configuration        = configuration,
                PrefetchingBehavior  = prefetchingBehavior,
                TransactionalStorage = transactionalStorage,
                WorkContext          = workContext
            };

            createdPrefetchers.Add(prefetcherWithContext);

            return(prefetcherWithContext);
        }
Ejemplo n.º 17
0
        public InMemoryRavenConfiguration CreateTenantConfiguration(string tenantId)
        {
            var document = GetTenantDatabaseDocument(tenantId);

            if (document == null)
            {
                return(null);
            }

            var config = new InMemoryRavenConfiguration
            {
                Settings = new NameValueCollection(SystemConfiguration.Settings),
            };

            SetupTenantDatabaseConfiguration(config);

            config.CustomizeValuesForTenant(tenantId);


            foreach (var setting in document.Settings)
            {
                config.Settings[setting.Key] = setting.Value;
            }
            Unprotect(document);

            foreach (var securedSetting in document.SecuredSettings)
            {
                config.Settings[securedSetting.Key] = securedSetting.Value;
            }

            var dataDir = document.Settings["Raven/DataDir"];

            if (dataDir.StartsWith("~/") || dataDir.StartsWith(@"~\"))
            {
                var baseDataPath = Path.GetDirectoryName(SystemDatabase.Configuration.DataDirectory);
                if (baseDataPath == null)
                {
                    throw new InvalidOperationException("Could not find root data path");
                }
                config.Settings["Raven/DataDir"] = Path.Combine(baseDataPath, dataDir.Substring(2));
            }
            config.Settings["Raven/VirtualDir"] = config.Settings["Raven/VirtualDir"] + "/" + tenantId;

            config.DatabaseName     = tenantId;
            config.IsTenantDatabase = true;

            config.Initialize();
            config.CopyParentSettings(SystemConfiguration);
            return(config);
        }
Ejemplo n.º 18
0
 public void When_connecting_to_the_server_endpoint_will_get_error()
 {
     var configuration = new InMemoryRavenConfiguration
     {
         RunInMemory = true
     };
     configuration.Initialize();
     using(new RavenMqServer(configuration))
     using (var c = new ClientConnection(new IPEndPoint(IPAddress.Loopback, 8181), new CaptureClientIntegration()))
     {
         var e = Assert.Throws<AggregateException>(() => c.Connect().Wait());
         Assert.Equal("Invalid response signature from server", e.InnerException.Message);
     }
 }
Ejemplo n.º 19
0
 protected override void ModifyConfiguration(InMemoryRavenConfiguration configuration)
 {
     if (useConfiguration)
     {
         configuration.CompiledIndexCacheDirectory = indexCachePath;
     }
     else
     {
         configuration.Settings = new NameValueCollection
         {
             { "Raven/CompiledIndexCacheDirectory", indexCachePath }
         };
         configuration.Initialize();
     }
 }
Ejemplo n.º 20
0
        public void CanUseAppDrivePrefixInWorkingDirectoryForAutoDriveLetterCalculations()
        {
            const string WorkingDirectoryValue = "appDrive:\\Raven\\";
            var          inMemoryConfiguration = new InMemoryRavenConfiguration();

            inMemoryConfiguration.Settings["Raven/WorkingDir"] = WorkingDirectoryValue;
            inMemoryConfiguration.Initialize();

            var basePath         = FilePathTools.MakeSureEndsWithSlash(AppDomain.CurrentDomain.BaseDirectory.ToFullPath());
            var rootPath         = Path.GetPathRoot(basePath);
            var workingDirectory = inMemoryConfiguration.WorkingDirectory;

            Assert.NotEqual(basePath, workingDirectory);
            Assert.True(workingDirectory.StartsWith(rootPath));
        }
Ejemplo n.º 21
0
        public void When_connecting_to_the_server_endpoint_will_get_error()
        {
            var configuration = new InMemoryRavenConfiguration
            {
                RunInMemory = true
            };

            configuration.Initialize();
            using (new RavenMqServer(configuration))
                using (var c = new ClientConnection(new IPEndPoint(IPAddress.Loopback, 8181), new CaptureClientIntegration()))
                {
                    var e = Assert.Throws <AggregateException>(() => c.Connect().Wait());
                    Assert.Equal("Invalid response signature from server", e.InnerException.Message);
                }
        }
Ejemplo n.º 22
0
        protected InMemoryRavenConfiguration CreateConfiguration(
            string tenantId,
            DatabaseDocument document,
            string folderPropName,
            InMemoryRavenConfiguration parentConfiguration)
        {
            var config = new InMemoryRavenConfiguration
            {
                Settings = new NameValueCollection(parentConfiguration.Settings),
            };

            if (config.Settings["Raven/CompiledIndexCacheDirectory"] == null)
            {
                var compiledIndexCacheDirectory = parentConfiguration.CompiledIndexCacheDirectory;
                config.Settings["Raven/CompiledIndexCacheDirectory"] = compiledIndexCacheDirectory;
            }

            SetupTenantConfiguration(config);

            config.CustomizeValuesForDatabaseTenant(tenantId);

            config.Settings["Raven/StorageEngine"] = parentConfiguration.DefaultStorageTypeName;

            foreach (var setting in document.Settings)
            {
                config.Settings[setting.Key] = setting.Value;
            }
            Unprotect(document);

            foreach (var securedSetting in document.SecuredSettings)
            {
                config.Settings[securedSetting.Key] = securedSetting.Value;
            }

            config.Settings[folderPropName] = config.Settings[folderPropName].ToFullPath(parentConfiguration.DataDirectory);

            config.Settings["Raven/Esent/LogsPath"]       = config.Settings["Raven/Esent/LogsPath"].ToFullPath(parentConfiguration.DataDirectory);
            config.Settings[Constants.RavenTxJournalPath] = config.Settings[Constants.RavenTxJournalPath].ToFullPath(parentConfiguration.DataDirectory);

            config.Settings["Raven/VirtualDir"] = config.Settings["Raven/VirtualDir"] + "/" + tenantId;

            config.DatabaseName     = tenantId;
            config.IsTenantDatabase = true;

            config.Initialize();
            config.CopyParentSettings(parentConfiguration);
            return(config);
        }
Ejemplo n.º 23
0
        public void NotChangingWorkingDirectoryShouldNotImpactPaths()
        {
            var inMemoryConfiguration = new InMemoryRavenConfiguration();

            inMemoryConfiguration.Initialize();

            var basePath         = FilePathTools.MakeSureEndsWithSlash(AppDomain.CurrentDomain.BaseDirectory.ToFullPath());
            var workingDirectory = inMemoryConfiguration.WorkingDirectory;

            Assert.Equal(basePath, workingDirectory);
            Assert.True(inMemoryConfiguration.AssembliesDirectory.StartsWith(basePath));
            Assert.True(inMemoryConfiguration.CompiledIndexCacheDirectory.StartsWith(basePath));
            Assert.True(inMemoryConfiguration.CountersDataDirectory.StartsWith(basePath));
            Assert.True(inMemoryConfiguration.DataDirectory.StartsWith(basePath));
            Assert.True(inMemoryConfiguration.FileSystem.DataDirectory.StartsWith(basePath));
        }
Ejemplo n.º 24
0
		public void When_HostOnAppDisposing_key_not_exist_then_should_not_throw()
		{
			string path = NewDataPath();
			var configuration = new InMemoryRavenConfiguration { Settings =
			{
				{ "Raven/DataDir", path },
				{ Constants.FileSystem.DataDirectory, Path.Combine(path, "FileSystem")}
			} };

			configuration.Initialize();

			using (var options = new RavenDBOptions(configuration))
			{
				Assert.DoesNotThrow(() => new AppBuilder().UseRavenDB(options));
			}
			
		}
Ejemplo n.º 25
0
        public void Isolated()
        {
            var ramDirectory = new RAMDirectory();

            using (new IndexWriter(ramDirectory, new StandardAnalyzer(Version.LUCENE_29), IndexWriter.MaxFieldLength.UNLIMITED)){}
            var inMemoryRavenConfiguration = new InMemoryRavenConfiguration();

            inMemoryRavenConfiguration.Initialize();

            var simpleIndex = new SimpleIndex(ramDirectory, 0, new IndexDefinition
            {
                Map =
                    @"from s in docs.Softs select new { s.f_platform, s.f_name, s.f_alias,s.f_License,s.f_totaldownload}",
                Analyzers =
                {
                    { "f_name",  typeof(KeywordAnalyzer).AssemblyQualifiedName },
                    { "f_alias", typeof(KeywordAnalyzer).AssemblyQualifiedName },
                },
                Indexes =
                {
                    { "f_platform",      FieldIndexing.NotAnalyzed },
                    { "f_License",       FieldIndexing.NotAnalyzed },
                    { "f_totaldownload", FieldIndexing.NotAnalyzed },
                    { "f_name",          FieldIndexing.Analyzed    },
                    { "f_alias",         FieldIndexing.Analyzed    },
                },
                SortOptions =
                {
                    { "f_totaldownload", SortOptions.Int },
                    { "f_License",       SortOptions.Int },
                }
            }, new MapOnlyView(), new WorkContext()
            {
                Configuration = inMemoryRavenConfiguration
            });

            var perFieldAnalyzerWrapper = simpleIndex.CreateAnalyzer(new LowerCaseKeywordAnalyzer(), new List <Action>());

            var tokenStream = perFieldAnalyzerWrapper.TokenStream("f_name", new StringReader("hello Shrek"));

            while (tokenStream.IncrementToken())
            {
                var attribute = (TermAttribute)tokenStream.GetAttribute <ITermAttribute>();
                Assert.Equal("hello Shrek", attribute.Term);
            }
        }
Ejemplo n.º 26
0
        public void When_HostOnAppDisposing_key_not_exist_then_should_not_throw()
        {
            string path          = NewDataPath();
            var    configuration = new InMemoryRavenConfiguration {
                Settings =
                {
                    { "Raven/DataDir",                    path          },
                    { Constants.FileSystem.DataDirectory, Path.Combine(path, "FileSystem")}
                }
            };

            configuration.Initialize();

            using (var options = new RavenDBOptions(configuration))
            {
                Assert.DoesNotThrow(() => new AppBuilder().UseRavenDB(options));
            }
        }
Ejemplo n.º 27
0
        public void ChangingWorkingDirectoryShouldNotImpactUNCPaths()
        {
            const string WorkingDirectoryValue = "C:\\Raven\\";
            var          inMemoryConfiguration = new InMemoryRavenConfiguration();

            inMemoryConfiguration.Settings["Raven/WorkingDir"] = WorkingDirectoryValue;
            inMemoryConfiguration.Settings["Raven/DataDir"]    = @"\\server1\ravendb\data";
            inMemoryConfiguration.Settings[Constants.FileSystem.DataDirectory] = @"\\server1\ravenfs\data";
            inMemoryConfiguration.Initialize();

            var basePath         = FilePathTools.MakeSureEndsWithSlash(AppDomain.CurrentDomain.BaseDirectory.ToFullPath());
            var workingDirectory = inMemoryConfiguration.WorkingDirectory;

            Assert.Equal(WorkingDirectoryValue, inMemoryConfiguration.WorkingDirectory);
            Assert.NotEqual(basePath, workingDirectory);
            Assert.True(inMemoryConfiguration.DataDirectory.StartsWith(@"\\"));
            Assert.True(inMemoryConfiguration.FileSystem.DataDirectory.StartsWith(@"\\"));
        }
Ejemplo n.º 28
0
		public void Isolated()
		{
			var ramDirectory = new RAMDirectory();
			using (new IndexWriter(ramDirectory, new StandardAnalyzer(Version.LUCENE_29), IndexWriter.MaxFieldLength.UNLIMITED)){}
			var inMemoryRavenConfiguration = new InMemoryRavenConfiguration();
			inMemoryRavenConfiguration.Initialize();
			;
			var simpleIndex = new SimpleIndex(ramDirectory, "test", new IndexDefinition
			{
				Map =
			                                                        	@"from s in docs.Softs select new { s.f_platform, s.f_name, s.f_alias,s.f_License,s.f_totaldownload}",
				Analyzers =
			                                                        	{
			                                                        		{"f_name", typeof (KeywordAnalyzer).AssemblyQualifiedName},
			                                                        		{"f_alias", typeof (KeywordAnalyzer).AssemblyQualifiedName},
			                                                        	},
				Indexes =
			                                                        	{
			                                                        		{"f_platform", FieldIndexing.NotAnalyzed},
			                                                        		{"f_License", FieldIndexing.NotAnalyzed},
			                                                        		{"f_totaldownload", FieldIndexing.NotAnalyzed},
			                                                        		{"f_name", FieldIndexing.Analyzed},
			                                                        		{"f_alias", FieldIndexing.Analyzed},
			                                                        	},
				SortOptions =
			                                                        	{
			                                                        		{"f_totaldownload", SortOptions.Int},
			                                                        		{"f_License", SortOptions.Int},
			                                                        	}

			}, new MapOnlyView(), new WorkContext()
			{
				Configuration = inMemoryRavenConfiguration
			});

			var perFieldAnalyzerWrapper = simpleIndex.CreateAnalyzer(new LowerCaseKeywordAnalyzer(), new List<Action>());

			var tokenStream = perFieldAnalyzerWrapper.TokenStream("f_name", new StringReader("hello Shrek"));
			while (tokenStream.IncrementToken())
			{
				var attribute = (TermAttribute) tokenStream.GetAttribute<ITermAttribute>();
				Assert.Equal("hello Shrek", attribute.Term);
			}
		}
Ejemplo n.º 29
0
        protected InMemoryRavenConfiguration CreateConfiguration(
            string tenantId,
            CounterStorageDocument document,
            string folderPropName,
            InMemoryRavenConfiguration parentConfiguration)
        {
            var config = new InMemoryRavenConfiguration
            {
                Settings = new NameValueCollection(parentConfiguration.Settings),
            };

            SetupTenantConfiguration(config);

            config.CustomizeValuesForCounterStorageTenant(tenantId);

            /*config.Settings[Constants.Counter.DataDirectory] = parentConfiguration.Counter.DataDirectory;
             * //config.Settings["Raven/StorageEngine"] = parentConfiguration.DefaultStorageTypeName;
             * //TODO: what counters storage dir path?
             * //config.Settings["Raven/Counters/Storage"] = parentConfiguration.FileSystem.DefaultStorageTypeName;*/

            foreach (var setting in document.Settings)
            {
                config.Settings[setting.Key] = setting.Value;
            }
            Unprotect(document);

            foreach (var securedSetting in document.SecuredSettings)
            {
                config.Settings[securedSetting.Key] = securedSetting.Value;
            }

            config.Settings[folderPropName] = config.Settings[folderPropName].ToFullPath(parentConfiguration.Counter.DataDirectory);
            //config.Settings["Raven/Esent/LogsPath"] = config.Settings["Raven/Esent/LogsPath"].ToFullPath(parentConfiguration.DataDirectory);
            config.Settings[Constants.RavenTxJournalPath] = config.Settings[Constants.RavenTxJournalPath].ToFullPath(parentConfiguration.DataDirectory);

            config.Settings["Raven/VirtualDir"] = config.Settings["Raven/VirtualDir"] + "/" + tenantId;

            config.CounterStorageName = tenantId;

            config.Initialize();
            config.CopyParentSettings(parentConfiguration);
            return(config);
        }
Ejemplo n.º 30
0
        public void ChangingWorkingDirectoryShouldImpactPaths()
        {
            const string WorkingDirectoryValue = "C:\\Raven\\";
            var          inMemoryConfiguration = new InMemoryRavenConfiguration();

            inMemoryConfiguration.Settings["Raven/WorkingDir"] = WorkingDirectoryValue;
            inMemoryConfiguration.Initialize();

            var basePath         = FilePathTools.MakeSureEndsWithSlash(AppDomain.CurrentDomain.BaseDirectory.ToFullPath());
            var workingDirectory = inMemoryConfiguration.WorkingDirectory;

            Assert.Equal(WorkingDirectoryValue, inMemoryConfiguration.WorkingDirectory);
            Assert.NotEqual(basePath, workingDirectory);
            Assert.True(inMemoryConfiguration.AssembliesDirectory.StartsWith(WorkingDirectoryValue));
            Assert.True(inMemoryConfiguration.CompiledIndexCacheDirectory.StartsWith(WorkingDirectoryValue));
            Assert.True(inMemoryConfiguration.CountersDataDirectory.StartsWith(WorkingDirectoryValue));
            Assert.True(inMemoryConfiguration.DataDirectory.StartsWith(WorkingDirectoryValue));
            Assert.True(inMemoryConfiguration.FileSystem.DataDirectory.StartsWith(WorkingDirectoryValue));
        }
Ejemplo n.º 31
0
        protected PrefetcherWithContext CreatePrefetcher(Action<InMemoryRavenConfiguration> modifyConfiguration = null, Action<WorkContext> modifyWorkContext = null)
        {
            var configuration = new InMemoryRavenConfiguration
            {
                RunInMemory = true
            };

            configuration.Initialize();

            if (modifyConfiguration != null)
                modifyConfiguration(configuration);

            var transactionalStorage = new TransactionalStorage(configuration, () => { }, () => { }, () => { }, () => { });
            transactionalStorage.Initialize(new SequentialUuidGenerator { EtagBase = 0 }, new OrderedPartCollection<AbstractDocumentCodec>());

            var workContext = new WorkContext
            {
                Configuration = configuration,
                TransactionalStorage = transactionalStorage
            };

            if (modifyWorkContext != null)
                modifyWorkContext(workContext);

            var autoTuner = new IndexBatchSizeAutoTuner(workContext);

            var prefetchingBehavior = new PrefetchingBehavior(PrefetchingUser.Indexer, workContext, autoTuner, string.Empty);

            var prefetcherWithContext = new PrefetcherWithContext
                                        {
                                            AutoTuner = autoTuner,
                                            Configuration = configuration,
                                            PrefetchingBehavior = prefetchingBehavior,
                                            TransactionalStorage = transactionalStorage,
                                            WorkContext = workContext
                                        };

            createdPrefetchers.Add(prefetcherWithContext);

            return prefetcherWithContext;
        }
Ejemplo n.º 32
0
        public InMemoryRavenConfiguration ConvertToRavenConfiguration()
        {
            var configuration = new InMemoryRavenConfiguration();

            foreach (var p in ConfigurationManager.AppSettings.AllKeys.Select(k => Tuple.Create(k, ConfigurationManager.AppSettings[k])))
            {
                configuration.Settings.Add(p.Item1, p.Item2);
            }

            foreach (var key in Settings.Keys)
            {
                configuration.Settings.Add(key, Settings[key]);
            }

            configuration.Initialize();

            configuration.Port = Port;
            configuration.RunInMemory = RunInMemory;
            configuration.DefaultStorageTypeName = DefaultStorageTypeName;

            return configuration;
        }
Ejemplo n.º 33
0
        public InMemoryRavenConfiguration ConvertToRavenConfiguration()
        {
            var configuration = new InMemoryRavenConfiguration();

            foreach (var p in ConfigurationManager.AppSettings.AllKeys.Select(k => Tuple.Create(k, ConfigurationManager.AppSettings[k])))
            {
                configuration.Settings.Add(p.Item1, p.Item2);
            }

            foreach (var key in Settings.Keys)
            {
                configuration.Settings.Add(key, Settings[key]);
            }

            configuration.Initialize();

            configuration.Port                   = Port;
            configuration.RunInMemory            = RunInMemory;
            configuration.DefaultStorageTypeName = DefaultStorageTypeName;

            return(configuration);
        }
Ejemplo n.º 34
0
        public void ChangingWorkingDirectoryShouldNotImpactUNCPaths()
        {
            string WorkingDirectoryValue = "C:\\Raven\\";

            if (EnvironmentUtils.RunningOnPosix == true)
            {
                WorkingDirectoryValue = Environment.GetEnvironmentVariable("HOME") + @"\";
            }

            var inMemoryConfiguration = new InMemoryRavenConfiguration();

            inMemoryConfiguration.Settings["Raven/WorkingDir"] = WorkingDirectoryValue;
            inMemoryConfiguration.Settings["Raven/DataDir"]    = @"\\server1\ravendb\data";
            inMemoryConfiguration.Settings[Constants.FileSystem.DataDirectory] = @"\\server1\ravenfs\data";
            inMemoryConfiguration.Settings[Constants.Counter.DataDirectory]    = @"\\server1\ravenfs\data";
            inMemoryConfiguration.Settings[Constants.TimeSeries.DataDirectory] = @"\\server1\ravenfs\data";
            inMemoryConfiguration.Initialize();

            var basePath         = FilePathTools.MakeSureEndsWithSlash(AppDomain.CurrentDomain.BaseDirectory.ToFullPath());
            var workingDirectory = inMemoryConfiguration.WorkingDirectory;

            Assert.Equal(WorkingDirectoryValue, inMemoryConfiguration.WorkingDirectory);
            Assert.NotEqual(basePath, workingDirectory);
            if (EnvironmentUtils.RunningOnPosix)
            {
                Assert.True(inMemoryConfiguration.DataDirectory.StartsWith(@"/"));
                Assert.True(inMemoryConfiguration.FileSystem.DataDirectory.StartsWith(@"/"));
                Assert.True(inMemoryConfiguration.Counter.DataDirectory.StartsWith(@"/"));
                Assert.True(inMemoryConfiguration.TimeSeries.DataDirectory.StartsWith(@"/"));
            }
            else
            {
                Assert.True(inMemoryConfiguration.DataDirectory.StartsWith(@"\\"));
                Assert.True(inMemoryConfiguration.FileSystem.DataDirectory.StartsWith(@"\\"));
                Assert.True(inMemoryConfiguration.Counter.DataDirectory.StartsWith(@"\\"));
                Assert.True(inMemoryConfiguration.TimeSeries.DataDirectory.StartsWith(@"\\"));
            }
        }
Ejemplo n.º 35
0
        protected InMemoryRavenConfiguration CreateConfiguration(
            string tenantId,
            DatabaseDocument document,
            string folderPropName,
            InMemoryRavenConfiguration parentConfiguration)
        {
            var config = new InMemoryRavenConfiguration
            {
                Settings = new NameValueCollection(parentConfiguration.Settings),
            };

            SetupTenantConfiguration(config);

            config.CustomizeValuesForTenant(tenantId);


            foreach (var setting in document.Settings)
            {
                config.Settings[setting.Key] = setting.Value;
            }
            Unprotect(document);

            foreach (var securedSetting in document.SecuredSettings)
            {
                config.Settings[securedSetting.Key] = securedSetting.Value;
            }

            config.Settings[folderPropName]     = config.Settings[folderPropName].ToFullPath(parentConfiguration.DataDirectory);
            config.Settings["Raven/VirtualDir"] = config.Settings["Raven/VirtualDir"] + "/" + tenantId;

            config.DatabaseName     = tenantId;
            config.IsTenantDatabase = true;

            config.Initialize();
            config.CopyParentSettings(parentConfiguration);
            return(config);
        }
Ejemplo n.º 36
0
        public void DefaultInMemoryRavenConfigurationShouldBeInitializedCorrectly()
        {
            var inMemoryConfiguration = new InMemoryRavenConfiguration();

            inMemoryConfiguration.Initialize();

            int defaultMaxNumberOfItemsToIndexInSingleBatch     = Environment.Is64BitProcess ? 128 * 1024 : 16 * 1024;
            int defaultInitialNumberOfItemsToIndexInSingleBatch = Environment.Is64BitProcess ? 512 : 256;

            var stronglyTypedConfiguration = new StronglyTypedRavenSettings(inMemoryConfiguration.Settings);

            stronglyTypedConfiguration.Setup(defaultMaxNumberOfItemsToIndexInSingleBatch, defaultInitialNumberOfItemsToIndexInSingleBatch);

            var configurationComparer = new ConfigurationComparer(inMemoryConfiguration, stronglyTypedConfiguration, propertyPathsToIgnore);

            configurationComparer.Assert(expected => expected.Replication.FetchingFromDiskTimeoutInSeconds.Value, actual => actual.Replication.FetchingFromDiskTimeoutInSeconds);
            configurationComparer.Assert(expected => expected.Prefetcher.MaximumSizeAllowedToFetchFromStorageInMb.Value, actual => actual.Prefetcher.MaximumSizeAllowedToFetchFromStorageInMb);
            configurationComparer.Assert(expected => expected.Prefetcher.FetchingDocumentsFromDiskTimeoutInSeconds.Value, actual => actual.Prefetcher.FetchingDocumentsFromDiskTimeoutInSeconds);
            configurationComparer.Assert(expected => expected.Voron.AllowIncrementalBackups.Value, actual => actual.Storage.Voron.AllowIncrementalBackups);
            configurationComparer.Assert(expected => expected.Voron.InitialFileSize.Value, actual => actual.Storage.Voron.InitialFileSize);
            configurationComparer.Assert(expected => expected.Voron.MaxBufferPoolSize.Value, actual => actual.Storage.Voron.MaxBufferPoolSize);
            configurationComparer.Assert(expected => expected.Voron.MaxScratchBufferSize.Value, actual => actual.Storage.Voron.MaxScratchBufferSize);
            configurationComparer.Assert(expected => expected.Voron.TempPath.Value, actual => actual.Storage.Voron.TempPath);
            configurationComparer.Assert(expected => expected.FileSystem.MaximumSynchronizationInterval.Value, actual => actual.FileSystem.MaximumSynchronizationInterval);
            configurationComparer.Assert(expected => expected.Encryption.EncryptionKeyBitsPreference.Value, actual => actual.Encryption.EncryptionKeyBitsPreference);
            configurationComparer.Assert(expected => expected.Encryption.UseFips.Value, actual => actual.Encryption.UseFips);
            configurationComparer.Assert(expected => expected.Encryption.UseSsl.Value, actual => actual.Encryption.UseSsl);
            configurationComparer.Assert(expected => expected.MaxConcurrentServerRequests.Value, actual => actual.MaxConcurrentServerRequests);
            configurationComparer.Assert(expected => expected.PrefetchingDurationLimit.Value, actual => actual.PrefetchingDurationLimit);
            configurationComparer.Assert(expected => expected.BulkImportBatchTimeout.Value, actual => actual.BulkImportBatchTimeout);
            configurationComparer.Assert(expected => expected.DatbaseOperationTimeout.Value, actual => actual.DatabaseOperationTimeout);
            configurationComparer.Assert(expected => expected.TimeToWaitBeforeRunningIdleIndexes.Value, actual => actual.TimeToWaitBeforeRunningIdleIndexes);
            configurationComparer.Assert(expected => expected.TimeToWaitBeforeRunningAbandonedIndexes.Value, actual => actual.TimeToWaitBeforeRunningAbandonedIndexes);
            configurationComparer.Assert(expected => expected.TimeToWaitBeforeMarkingIdleIndexAsAbandoned.Value, actual => actual.TimeToWaitBeforeMarkingIdleIndexAsAbandoned);
            configurationComparer.Assert(expected => expected.TimeToWaitBeforeMarkingAutoIndexAsIdle.Value, actual => actual.TimeToWaitBeforeMarkingAutoIndexAsIdle);
            configurationComparer.Assert(expected => expected.RedirectStudioUrl.Value, actual => actual.RedirectStudioUrl);
            configurationComparer.Assert(expected => expected.ResetIndexOnUncleanShutdown.Value, actual => actual.ResetIndexOnUncleanShutdown);
            configurationComparer.Assert(expected => expected.MaxPageSize.Value, actual => actual.MaxPageSize);
            configurationComparer.Assert(expected => expected.MemoryCacheLimitPercentage.Value, actual => actual.MemoryCacheLimitPercentage);
            configurationComparer.Assert(expected => expected.MemoryCacheLimitMegabytes.Value, actual => actual.MemoryCacheLimitMegabytes);
            configurationComparer.Assert(expected => expected.MemoryCacheLimitCheckInterval.Value, actual => actual.MemoryCacheLimitCheckInterval);
            configurationComparer.Assert(expected => expected.MaxNumberOfItemsToProcessInSingleBatch.Value, actual => actual.MaxNumberOfItemsToProcessInSingleBatch);
            configurationComparer.Assert(expected => expected.MaxNumberOfItemsToReduceInSingleBatch.Value, actual => actual.MaxNumberOfItemsToReduceInSingleBatch);
            configurationComparer.Assert(expected => expected.NumberOfItemsToExecuteReduceInSingleStep.Value, actual => actual.NumberOfItemsToExecuteReduceInSingleStep);
            configurationComparer.Assert(expected => expected.NewIndexInMemoryMaxMb.Value, actual => actual.NewIndexInMemoryMaxBytes);
            configurationComparer.Assert(expected => expected.HostName.Value, actual => actual.HostName);
            configurationComparer.Assert(expected => expected.AccessControlMaxAge.Value, actual => actual.AccessControlMaxAge);
            configurationComparer.Assert(expected => expected.AccessControlAllowMethods.Value, actual => actual.AccessControlAllowMethods);
            configurationComparer.Assert(expected => expected.AccessControlRequestHeaders.Value, actual => actual.AccessControlRequestHeaders);
            configurationComparer.Assert(expected => expected.HttpCompression.Value, actual => actual.HttpCompression);
            configurationComparer.Assert(expected => expected.AllowLocalAccessWithoutAuthorization.Value, actual => actual.AllowLocalAccessWithoutAuthorization);
            configurationComparer.Assert(expected => expected.RunInMemory.Value, actual => actual.RunInMemory);
            configurationComparer.Assert(expected => expected.DisableInMemoryIndexing.Value, actual => actual.DisableInMemoryIndexing);
            configurationComparer.Assert(expected => expected.WebDir.Value, actual => actual.WebDir);
            configurationComparer.Assert(expected => expected.DisableDocumentPreFetching.Value, actual => actual.DisableDocumentPreFetching);
            configurationComparer.Assert(expected => expected.MaxNumberOfItemsToPreFetch.Value, actual => actual.MaxNumberOfItemsToPreFetch);
            configurationComparer.Assert(expected => expected.MemoryCacheExpiration.Value, actual => actual.MemoryCacheExpiration);
            configurationComparer.Assert(expected => expected.CreateAutoIndexesForAdHocQueriesIfNeeded.Value, actual => actual.CreateAutoIndexesForAdHocQueriesIfNeeded);
            configurationComparer.Assert(expected => expected.MaxIndexCommitPointStoreTimeInterval.Value, actual => actual.MaxIndexCommitPointStoreTimeInterval);
            configurationComparer.Assert(expected => expected.MinIndexingTimeIntervalToStoreCommitPoint.Value, actual => actual.MinIndexingTimeIntervalToStoreCommitPoint);
            configurationComparer.Assert(expected => expected.MaxNumberOfStoredCommitPoints.Value, actual => actual.MaxNumberOfStoredCommitPoints);
            configurationComparer.Assert(expected => expected.MemoryLimitForProcessing.Value, actual => actual.MemoryLimitForProcessingInMb);
            configurationComparer.Assert(expected => expected.AvailableMemoryForRaisingBatchSizeLimit.Value, actual => actual.AvailableMemoryForRaisingBatchSizeLimit);
            configurationComparer.Assert(expected => expected.MaxProcessingRunLatency.Value, actual => actual.MaxProcessingRunLatency);
            configurationComparer.Assert(expected => expected.DisableClusterDiscovery.Value, actual => actual.DisableClusterDiscovery);
            configurationComparer.Assert(expected => expected.ServerName.Value, actual => actual.ServerName);
            configurationComparer.Assert(expected => expected.MaxStepsForScript.Value, actual => actual.MaxStepsForScript);
            configurationComparer.Assert(expected => expected.MaxRecentTouchesToRemember.Value, actual => actual.MaxRecentTouchesToRemember);
            configurationComparer.Assert(expected => expected.AdditionalStepsForScriptBasedOnDocumentSize.Value, actual => actual.AdditionalStepsForScriptBasedOnDocumentSize);
            configurationComparer.Assert(expected => expected.MaxIndexWritesBeforeRecreate.Value, actual => actual.MaxIndexWritesBeforeRecreate);
            configurationComparer.Assert(expected => expected.MaxIndexOutputsPerDocument.Value, actual => actual.MaxIndexOutputsPerDocument);
            configurationComparer.Assert(expected => expected.PrewarmFacetsOnIndexingMaxAge.Value, actual => actual.PrewarmFacetsOnIndexingMaxAge);
            configurationComparer.Assert(expected => expected.PrewarmFacetsSyncronousWaitTime.Value, actual => actual.PrewarmFacetsSyncronousWaitTime);
            configurationComparer.Assert(expected => expected.MaxNumberOfParallelProcessingTasks.Value, actual => actual.MaxNumberOfParallelProcessingTasks);
            configurationComparer.Assert(expected => FilePathTools.MakeSureEndsWithSlash(expected.DataDir.Value.ToFullPath(null)), actual => actual.DataDirectory);
            configurationComparer.Assert(expected => FilePathTools.MakeSureEndsWithSlash(expected.CountersDataDir.Value.ToFullPath(null)), actual => actual.CountersDataDirectory);
            configurationComparer.Assert(expected => expected.PluginsDirectory.Value.ToFullPath(null), actual => actual.PluginsDirectory);
            configurationComparer.Assert(expected => FilePathTools.MakeSureEndsWithSlash(expected.FileSystem.DataDir.Value.ToFullPath(null)), actual => actual.FileSystem.DataDirectory);
            configurationComparer.Assert(expected => FilePathTools.MakeSureEndsWithSlash(expected.FileSystem.DataDir.Value.ToFullPath(null)) + @"Indexes", actual => actual.FileSystem.IndexStoragePath);
            configurationComparer.Assert(expected => expected.FileSystem.DefaultStorageTypeName.Value, actual => actual.FileSystem.DefaultStorageTypeName);
            configurationComparer.Assert(expected => expected.MaxConcurrentMultiGetRequests.Value, actual => actual.MaxConcurrentMultiGetRequests);
            configurationComparer.Assert(expected => FilePathTools.MakeSureEndsWithSlash(expected.DataDir.Value.ToFullPath(null)) + @"Indexes", actual => actual.IndexStoragePath);
            configurationComparer.Assert(expected => expected.DefaultStorageTypeName.Value, actual => actual.DefaultStorageTypeName);
            configurationComparer.Assert(expected => expected.CompiledIndexCacheDirectory.Value.ToFullPath(null), actual => actual.CompiledIndexCacheDirectory);
            configurationComparer.Assert(expected => expected.JournalsStoragePath.Value, actual => actual.JournalsStoragePath);
            configurationComparer.Assert(expected => expected.FlushIndexToDiskSizeInMb.Value, actual => actual.FlushIndexToDiskSizeInMb);

            Assert.NotNull(inMemoryConfiguration.OAuthTokenKey);
            Assert.Equal("/", inMemoryConfiguration.VirtualDirectory);
            Assert.Empty(inMemoryConfiguration.AccessControlAllowOrigin);
            Assert.NotNull(inMemoryConfiguration.ServerUrl);
            Assert.NotNull(inMemoryConfiguration.OAuthTokenServer);
            Assert.True(inMemoryConfiguration.UseDefaultOAuthTokenServer);
            Assert.Empty(inMemoryConfiguration.HeadersToIgnore);
            Assert.Equal(null, inMemoryConfiguration.CustomTaskScheduler);
            Assert.Empty(inMemoryConfiguration.ActiveBundles);
            Assert.Equal("*", stronglyTypedConfiguration.Port.Value);
            Assert.True(inMemoryConfiguration.Port >= 8080);
            Assert.True(inMemoryConfiguration.CreateAnalyzersDirectoryIfNotExisting);
            Assert.True(inMemoryConfiguration.CreatePluginsDirectoryIfNotExisting);

            configurationComparer.Validate();
        }
Ejemplo n.º 37
0
        protected bool TryGetOrCreateResourceStore(string tenantId, out Task <DocumentDatabase> database)
        {
            if (ResourcesStoresCache.TryGetValue(tenantId, out database))
            {
                if (database.IsFaulted || database.IsCanceled)
                {
                    Task <DocumentDatabase> ignored;
                    ResourcesStoresCache.TryRemove(tenantId, out ignored);
                    DateTime time;
                    databaseLastRecentlyUsed.TryRemove(tenantId, out time);
                    //now go and re-create it.
                }
                else
                {
                    return(true);
                }
            }

            JsonDocument jsonDocument;

            using (DefaultResourceStore.DisableAllTriggersForCurrentThread())
                jsonDocument = DefaultResourceStore.Get("Raven/Databases/" + tenantId, null);

            if (jsonDocument == null ||
                jsonDocument.Metadata == null ||
                jsonDocument.Metadata.Value <bool>(Constants.RavenDocumentDoesNotExists) ||
                jsonDocument.Metadata.Value <bool>(Constants.RavenDeleteMarker))
            {
                return(false);
            }

            var document = jsonDocument.DataAsJson.JsonDeserialization <DatabaseDocument>();

            database = ResourcesStoresCache.GetOrAddAtomically(tenantId, s => Task.Factory.StartNew(() =>
            {
                var config = new InMemoryRavenConfiguration
                {
                    Settings = new NameValueCollection(DefaultConfiguration.Settings),
                };

                SetupTenantDatabaseConfiguration(config);

                config.CustomizeValuesForTenant(tenantId);

                var dataDir = document.Settings["Raven/DataDir"];
                if (dataDir == null)
                {
                    throw new InvalidOperationException("Could not find Raven/DataDir");
                }

                foreach (var setting in document.Settings)
                {
                    config.Settings[setting.Key] = setting.Value;
                }

                if (dataDir.StartsWith("~/") || dataDir.StartsWith(@"~\"))
                {
                    var baseDataPath = Path.GetDirectoryName(DefaultResourceStore.Configuration.DataDirectory);
                    if (baseDataPath == null)
                    {
                        throw new InvalidOperationException("Could not find root data path");
                    }
                    config.Settings["Raven/DataDir"] = Path.Combine(baseDataPath, dataDir.Substring(2));
                }
                config.Settings["Raven/VirtualDir"] = config.Settings["Raven/VirtualDir"] + "/" + tenantId;

                config.DatabaseName = tenantId;

                config.Initialize();
                config.CopyParentSettings(DefaultConfiguration);
                var documentDatabase = new DocumentDatabase(config);
                documentDatabase.SpinBackgroundWorkers();
                return(documentDatabase);
            })
                                                               .ContinueWith(task =>
            {
                if (task.Status == TaskStatus.Faulted)                                 // this observes the task exception
                {
                    logger.WarnException("Failed to create database " + tenantId, task.Exception);
                }
                return(task);
            }).Unwrap());
            return(true);
        }
Ejemplo n.º 38
0
        public static void ApplySettingsToConfiguration(InMemoryRavenConfiguration configuration)
        {
            var settings = Settings;
            foreach (var setting in settings)
            {
                configuration.Settings[setting.Key] = setting.Value;
            }

            configuration.Initialize();
        }
Ejemplo n.º 39
0
		public InMemoryRavenConfiguration CreateTenantConfiguration(string tenantId)
		{
			var document = GetTenantDatabaseDocument(tenantId);
			if (document == null)
				return null;

			var config = new InMemoryRavenConfiguration
			{
				Settings = new NameValueCollection(SystemConfiguration.Settings),
			};

			SetupTenantDatabaseConfiguration(config);

			config.CustomizeValuesForTenant(tenantId);


			foreach (var setting in document.Settings)
			{
				config.Settings[setting.Key] = setting.Value;
			}
			Unprotect(document);

			foreach (var securedSetting in document.SecuredSettings)
			{
				config.Settings[securedSetting.Key] = securedSetting.Value;
			}

			var dataDir = document.Settings["Raven/DataDir"];
			if (dataDir.StartsWith("~/") || dataDir.StartsWith(@"~\"))
			{
				var baseDataPath = Path.GetDirectoryName(SystemDatabase.Configuration.DataDirectory);
				if (baseDataPath == null)
					throw new InvalidOperationException("Could not find root data path");
				config.Settings["Raven/DataDir"] = Path.Combine(baseDataPath, dataDir.Substring(2));
			}
			config.Settings["Raven/VirtualDir"] = config.Settings["Raven/VirtualDir"] + "/" + tenantId;

			config.DatabaseName = tenantId;
			config.IsTenantDatabase = true;

			config.Initialize();
			config.CopyParentSettings(SystemConfiguration);
			return config;
		}
 public StorageSignatureRepositoryTests()
 {
     configuration = new InMemoryRavenConfiguration();
     configuration.Initialize();
 }
Ejemplo n.º 41
0
		protected override bool TryGetOrCreateResourceStore(string tenantId, out IResourceStore database)
		{
			if (ResourcesStoresCache.TryGetValue(tenantId, out database))
				return true;

			JsonDocument jsonDocument;

			using (DefaultDatabase.DisableAllTriggersForCurrentThread())
				jsonDocument = DefaultDatabase.Get("Raven/Databases/" + tenantId, null);

			if (jsonDocument == null)
				return false;

			var document = jsonDocument.DataAsJson.JsonDeserialization<DatabaseDocument>();

			database = ResourcesStoresCache.GetOrAddAtomically(tenantId, s =>
			{
				var config = new InMemoryRavenConfiguration
				{
					Settings = DefaultConfiguration.Settings,
				};
				foreach (var setting in document.Settings)
				{
					config.Settings[setting.Key] = setting.Value;
				}
				var dataDir = config.Settings["Raven/DataDir"];
				if (dataDir == null)
					throw new InvalidOperationException("Could not find Raven/DataDir");
				if (dataDir.StartsWith("~/") || dataDir.StartsWith(@"~\"))
				{
					var baseDataPath = Path.GetDirectoryName(DefaultDatabase.Configuration.DataDirectory);
					if (baseDataPath == null)
						throw new InvalidOperationException("Could not find root data path");
					config.Settings["Raven/DataDir"] = Path.Combine(baseDataPath, dataDir.Substring(2));
				}
				config.Settings["Raven/VirtualDir"] = config.Settings["Raven/VirtualDir"] + "/" + tenantId;

				config.DatabaseName = tenantId;

				config.Initialize();
				var documentDatabase = new DocumentDatabase(config);
				documentDatabase.SpinBackgroundWorkers();
				return documentDatabase;
			});
			return true;
		}
Ejemplo n.º 42
0
        public static void ApplySettingsToConfiguration(InMemoryRavenConfiguration configuration)
        {
            var settings = ServerSettings;
            foreach (var setting in settings)
            {
                Console.WriteLine("Applying external server setting: " + setting.Key);

                configuration.Settings[setting.Key] = setting.Value;
            }

            configuration.Initialize();
        }