public When_Using_Sharded_Servers() { server = "localhost"; port1 = 8080; port2 = 8081; path1 = GetPath("TestShardedDb1"); path2 = GetPath("TestShardedDb2"); RavenDbServer.EnsureCanListenToWhenInNonAdminContext(port1); RavenDbServer.EnsureCanListenToWhenInNonAdminContext(port2); company1 = new Company { Name = "Company1" }; company2 = new Company { Name = "Company2" }; server1 = GetNewServer(port1, path1); server2 = GetNewServer(port2, path2); shards = new Shards { new DocumentStore { Identifier = "Shard1", Url = "http://" + server + ":" + port1 }, new DocumentStore { Identifier = "Shard2", Url = "http://" + server + ":" + port2 } }; shardSelection = MockRepository.GenerateStub <IShardSelectionStrategy>(); shardSelection.Stub(x => x.ShardIdForNewObject(company1)).Return("Shard1"); shardSelection.Stub(x => x.ShardIdForNewObject(company2)).Return("Shard2"); shardResolution = MockRepository.GenerateStub <IShardResolutionStrategy>(); shardStrategy = MockRepository.GenerateStub <IShardStrategy>(); shardStrategy.Stub(x => x.ShardSelectionStrategy).Return(shardSelection); shardStrategy.Stub(x => x.ShardResolutionStrategy).Return(shardResolution); }
public void Can_get_documents() { using (var server = new RavenDbServer { RunInMemory = true }.Initialize()) { using (var session = server.DocumentStore.OpenSession()) { session.Store(new Company { Name = "Company A", Id = "1" }); session.Store(new Company { Name = "Company B", Id = "2" }); session.SaveChanges(); } JsonDocument[] jsonDocuments = server.DocumentStore.DatabaseCommands.GetDocuments(0, 10, true); Assert.Equal(2, jsonDocuments.Length); } }
public MoreLikeThisTests() { path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(MoreLikeThisTests)).CodeBase); path = Path.Combine(path, "TestDb").Substring(6); database::Raven.Database.Extensions.IOExtensions.DeleteDirectory("Data"); ravenDbServer = new RavenDbServer( new database::Raven.Database.Config.RavenConfiguration { Port = 8079, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, DataDirectory = path, Catalog = { Catalogs = { new AssemblyCatalog(typeof(MoreLikeThisResponder).Assembly) } }, }); documentStore = new DocumentStore { Url = "http://localhost:8079" }; documentStore.Initialize(); }
protected RavenDbServer GetNewServer(int port) { var dataDirectory = Path.Combine(NewDataPath(), "System"); var configuration = new RavenConfiguration { Port = port, DataDirectory = dataDirectory, AnonymousUserAccessMode = AnonymousUserAccessMode.Admin }; configuration.RunInMemory = configuration.DefaultStorageTypeName == InMemoryRavenConfiguration.VoronTypeName; var ravenDbServer = new RavenDbServer(configuration) { UseEmbeddedHttpServer = true }; ravenDbServer.Initialize(); return(ravenDbServer); }
private void CreateServer(bool initDocStore = false) { IOExtensions.DeleteDirectory("HiLoData"); server = new RavenDbServer(new RavenConfiguration { Port = 8079, DataDirectory = "HiLoData", RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, AnonymousUserAccessMode = AnonymousUserAccessMode.All }); if (initDocStore) { documentStore = new DocumentStore() { Url = "http://localhost:8079/" }; documentStore.Initialize(); } }
public TestServerFixture() { var configuration = new RavenConfiguration(); configuration.Port = Port; configuration.ServerName = ServerName; configuration.RunInMemory = configuration.DefaultStorageTypeName == InMemoryRavenConfiguration.VoronTypeName; configuration.DataDirectory = Path.Combine(configuration.DataDirectory, "Tests"); configuration.MaxSecondsForTaskToWaitForDatabaseToLoad = 10; IOExtensions.DeleteDirectory(configuration.DataDirectory); NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(Port); Server = new RavenDbServer(configuration) { UseEmbeddedHttpServer = true, RunInMemory = true }.Initialize(); }
protected RavenDbServer GetNewServer() { var ravenDbServer = new RavenDbServer(new RavenConfiguration { Port = 8080, RunInMemory = true, DataDirectory = "Data", AnonymousUserAccessMode = AnonymousUserAccessMode.All }); using (var documentStore = new DocumentStore { Url = "http://localhost:8080" }.Initialize()) { new RavenDocumentsByEntityName().Execute(documentStore); } return(ravenDbServer); }
protected AuthorizationTest() { database::Raven.Database.Extensions.IOExtensions.DeleteDirectory("Data"); server = new RavenDbServer(new database::Raven.Database.Config.RavenConfiguration { AnonymousUserAccessMode = database::Raven.Database.Server.AnonymousUserAccessMode.All, Catalog = { Catalogs = { new AssemblyCatalog(typeof(AuthorizationDecisions).Assembly) } }, DataDirectory = "Data", Port = 8079, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, }); store = new DocumentStore { Url = server.Database.Configuration.ServerUrl }; store.Initialize(); foreach (DictionaryEntry de in HttpRuntime.Cache) { HttpRuntime.Cache.Remove((string)de.Key); } }
public void CanInsertSeveralDocuments() { using (var server = new RavenDbServer { RunInMemory = true }.Initialize()) { var store = server.DocumentStore; var bulkInsertOperation = new RemoteBulkInsertOperation(new BulkInsertOptions(), (AsyncServerClient)store.AsyncDatabaseCommands, store.Changes()); bulkInsertOperation.Write("one", new RavenJObject(), new RavenJObject { { "test", "passed" } }); bulkInsertOperation.Write("two", new RavenJObject(), new RavenJObject { { "test", "passed" } }); bulkInsertOperation.Dispose(); Assert.Equal("passed", store.DatabaseCommands.Get("one").DataAsJson.Value <string>("test")); Assert.Equal("passed", store.DatabaseCommands.Get("two").DataAsJson.Value <string>("test")); } }
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(); }
private void StartServers_Click(object sender, EventArgs e) { Reset(); for (int i = 0; i < NumberOfServers.Value; i++) { var ravenDbServer = new RavenDbServer(new RavenConfiguration { Port = 8079 - i, RunInMemory = true, AnonymousUserAccessMode = AnonymousUserAccessMode.All }); var serverLog = new ServerLog { Server = ravenDbServer, Dock = DockStyle.Fill, Url = ravenDbServer.Server.Configuration.ServerUrl }; ServerTabs.TabPages.Add(serverLog.Url); var tabPage = ServerTabs.TabPages[ServerTabs.TabPages.Count - 1]; tabPage.Tag = serverLog; ravenDbServer.Server.BeforeDispatchingRequest = context => { var adaptHttpContext = AdaptHttpContext(context, serverLog); if (adaptHttpContext != null) { var increment = Interlocked.Increment(ref serverLog.NumOfRequests); BeginInvoke((Action)(() => { tabPage.Text = string.Format("{0} ({1})", serverLog.Url, increment); })); } return(adaptHttpContext); }; servers.Add(ravenDbServer); tabPage.Controls.Add(serverLog); } }
public Includes() { server = GetNewServer(8080, GetPath(DbName)); store = new DocumentStore { Url = "http://*****:*****@ayende.com", Name = "Oren" }; session.Store(customer); session.Store(new Order { Customer = new DenormalizedReference { Id = customer.Id, Name = customer.Name }, Name = (i + 1).ToString() }); } session.SaveChanges(); } }
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); }
protected RavenDbServer GetNewServer(int port = 8079, string dataDirectory = "Data", bool runInMemory = true) { var ravenConfiguration = new RavenConfiguration { Port = port, DataDirectory = dataDirectory, RunInMemory = runInMemory, AnonymousUserAccessMode = AnonymousUserAccessMode.All }; ModifyConfiguration(ravenConfiguration); if (ravenConfiguration.RunInMemory == false) { 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); }
private IDocumentStore CreateStoreAtPort(int port, bool enableCompressionBundle = false, bool removeDataDirectory = true, Action <DocumentStore> configureStore = null, AnonymousUserAccessMode anonymousUserAccessMode = AnonymousUserAccessMode.All) { Raven.Database.Server.NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port); var serverConfiguration = new Raven.Database.Config.RavenConfiguration { Settings = { { "Raven/ActiveBundles", "replication" + (enableCompressionBundle ? ";compression" : string.Empty) } }, AnonymousUserAccessMode = anonymousUserAccessMode, DataDirectory = "Data #" + servers.Count, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, RunInMemory = true, Port = port, DefaultStorageTypeName = RavenTest.GetDefaultStorageType() }; ConfigureServer(serverConfiguration); if (removeDataDirectory) { IOExtensions.DeleteDirectory(serverConfiguration.DataDirectory); } serverConfiguration.PostInit(); var ravenDbServer = new RavenDbServer(serverConfiguration); servers.Add(ravenDbServer); var documentStore = new DocumentStore { Url = ravenDbServer.Database.Configuration.ServerUrl }; ConfigureStore(documentStore); if (configureStore != null) { configureStore(documentStore); } documentStore.Initialize(); stores.Add(documentStore); ConfigureDatbase(ravenDbServer.Database); return(documentStore); }
private IDocumentStore CreateStoreAtPort(int port) { database::Raven.Database.Server.NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port); var ravenDbServer = new RavenDbServer(new database::Raven.Database.Config.RavenConfiguration { AnonymousUserAccessMode = database::Raven.Database.Server.AnonymousUserAccessMode.All, Catalog = { Catalogs = { new AssemblyCatalog(typeof(replication::Raven.Bundles.Replication.Triggers.AncestryPutTrigger).Assembly) } }, DataDirectory = "Data #" + servers.Count, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, Port = port }); servers.Add(ravenDbServer); var documentStore = new DocumentStore { Url = ravenDbServer.Database.Configuration.ServerUrl }; documentStore.Initialize(); stores.Add(documentStore); return(documentStore); }
protected override void ConfigureServer(RavenDbServer server, string fileSystemName) { if (server.SystemDatabase.Configuration.Port == Ports[1]) // setup only for destination { server.SystemDatabase.Documents.Put("Raven/ApiKeys/test", null, RavenJObject.FromObject(new ApiKeyDefinition { Name = Name, Secret = Secret, Enabled = true, Databases = new List <ResourceAccess> { new ResourceAccess { TenantId = Constants.SystemDatabase, Admin = true }, // required to create file system new ResourceAccess { TenantId = fileSystemName } } }), new RavenJObject(), null); } }
public Compression() { path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Versioning.Versioning)).CodeBase); path = Path.Combine(path, "TestDb").Substring(6); Raven.Database.Extensions.IOExtensions.DeleteDirectory(path); var config = new Raven.Database.Config.RavenConfiguration { Port = 8079, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, DataDirectory = path, Settings = { { "Raven/ActiveBundles", "Compression" } } }; config.PostInit(); ravenDbServer = new RavenDbServer(config); documentStore = new DocumentStore { Url = "http://localhost:8079" }; documentStore.Initialize(); }
public IDocumentStore NewRemoteDocumentStoreWithUrl(int port, bool fiddler = true, 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()); }
public string GetAccessToken(RavenDbServer server, string user = "******", string databases = "*", bool valid = true, bool expired = false) { var issued = (DateTime.UtcNow - DateTime.MinValue).TotalMilliseconds; if (expired) { issued -= TimeSpan.FromHours(1).TotalMilliseconds; } var authorizedDatabases = databases.Split(',').Select(tenantId => new DatabaseAccess { TenantId = tenantId }).ToList(); var body = RavenJObject.FromObject(new AccessTokenBody { UserId = user, AuthorizedDatabases = authorizedDatabases, Issued = issued }).ToString(Formatting.None); var signature = valid ? CertHelper.Sign(body, server.Database.Configuration.OAuthTokenCertificate) : "InvalidSignature"; var token = RavenJObject.FromObject(new { Body = body, Signature = signature }).ToString(Formatting.None); return(token); }
protected override void ConfigureServer(RavenDbServer server, string fileSystemName) { server.SystemDatabase.Documents.Put("Raven/ApiKeys/test", null, RavenJObject.FromObject(new ApiKeyDefinition { Name = "test", Secret = "ThisIsMySecret", Enabled = true, Databases = new List <DatabaseAccess> { new DatabaseAccess { TenantId = Constants.SystemDatabase, Admin = true }, // required to create file system }, FileSystems = new List <FileSystemAccess>() { new FileSystemAccess() { TenantId = fileSystemName } } }), new RavenJObject(), null); }
public MultiTenant() { ravenDbServer = GetNewServer(); _documentStore = new DocumentStore { Url = "http://localhost:8079", }.Initialize(); _documentStore.DatabaseCommands.EnsureDatabaseExists(_dbid); // Configure the default versioning configuration using (var session = _documentStore.OpenSession(_dbid)) { session.Store(new VersioningConfiguration { Id = "Raven/Versioning/DefaultConfiguration", MaxRevisions = 5 }); session.SaveChanges(); } // Add an entity, creating the first version. using (var session = _documentStore.OpenSession(_dbid)) { session.Store(new Ball { Id = "balls/1", Color = "Red" }); session.SaveChanges(); } // Change the entity, creating the second version. using (var session = _documentStore.OpenSession(_dbid)) { var ball = session.Load <Ball>("balls/1"); ball.Color = "Blue"; session.SaveChanges(); } }
public WhenUsingShardedServers() { const string server = "localhost"; const int port1 = 8079; const int port2 = 8081; company1 = new Company { Name = "Company1" }; company2 = new Company { Name = "Company2" }; server1 = GetNewServer(port1); server2 = GetNewServer(port2); shards = new List <IDocumentStore> { new DocumentStore { Identifier = "Shard1", Url = "http://" + server + ":" + port1 }, new DocumentStore { Identifier = "Shard2", Url = "http://" + server + ":" + port2 } }.ToDictionary(x => x.Identifier, x => x); shardResolution = MockRepository.GenerateStub <IShardResolutionStrategy>(); shardResolution.Stub(x => x.GenerateShardIdFor(Arg.Is(company1), Arg <ITransactionalDocumentSession> .Is.Anything)).Return("Shard1"); shardResolution.Stub(x => x.GenerateShardIdFor(Arg.Is(company2), Arg <ITransactionalDocumentSession> .Is.Anything)).Return("Shard2"); shardResolution.Stub(x => x.MetadataShardIdFor(company1)).Return("Shard1"); shardResolution.Stub(x => x.MetadataShardIdFor(company2)).Return("Shard1"); shardStrategy = new ShardStrategy(shards) { ShardResolutionStrategy = shardResolution }; }
public void Can_receive_changes_notification() { using (var server = new RavenDbServer { RunInMemory = true }.Initialize()) { var list = new BlockingCollection <DocumentChangeNotification>(); var taskObservable = server.DocumentStore.Changes(); taskObservable.Task.Wait(); var observableWithTask = taskObservable.ForDocument("items/1"); observableWithTask.Task.Wait(); observableWithTask.Subscribe(list.Add); using (var session = server.DocumentStore.OpenSession()) { session.Store(new ClientServer.Item(), "items/1"); session.SaveChanges(); } DocumentChangeNotification documentChangeNotification; Assert.True(list.TryTake(out documentChangeNotification, TimeSpan.FromSeconds(3))); } }
public void StartDatabase(int index) { var previousServer = servers[index]; Raven.Database.Server.NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(previousServer.Database.Configuration.Port); var serverConfiguration = new Raven.Database.Config.RavenConfiguration { Settings = { { "Raven/ActiveBundles", "replication" } }, AnonymousUserAccessMode = Raven.Database.Server.AnonymousUserAccessMode.All, DataDirectory = previousServer.Database.Configuration.DataDirectory, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, RunInMemory = previousServer.Database.Configuration.RunInMemory, Port = previousServer.Database.Configuration.Port, DefaultStorageTypeName = RavenTest.GetDefaultStorageType() }; ConfigureServer(serverConfiguration); serverConfiguration.PostInit(); var ravenDbServer = new RavenDbServer(serverConfiguration); servers[index] = ravenDbServer; }
private IDocumentStore CreateStoreAtPort(int port, Action <DocumentStore> configureStore = null) { database::Raven.Database.Server.NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port); var assemblyCatalog = new AssemblyCatalog(typeof(replication::Raven.Bundles.Replication.Triggers.AncestryPutTrigger).Assembly); var serverConfiguration = new database::Raven.Database.Config.RavenConfiguration { AnonymousUserAccessMode = database::Raven.Database.Server.AnonymousUserAccessMode.All, Catalog = { Catalogs = { assemblyCatalog } }, DataDirectory = "Data #" + servers.Count, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, RunInMemory = true, Port = port }; ConfigureServer(serverConfiguration); IOExtensions.DeleteDirectory(serverConfiguration.DataDirectory); serverConfiguration.PostInit(); var ravenDbServer = new RavenDbServer(serverConfiguration); ravenDbServer.Server.SetupTenantDatabaseConfiguration += configuration => configuration.Catalog.Catalogs.Add(assemblyCatalog); servers.Add(ravenDbServer); var documentStore = new DocumentStore { Url = ravenDbServer.Database.Configuration.ServerUrl }; ConfigureStore(documentStore); if (configureStore != null) { configureStore(documentStore); } documentStore.Initialize(); documentStore.JsonRequestFactory.EnableBasicAuthenticationOverUnsecureHttpEvenThoughPasswordsWouldBeSentOverTheWireInClearTextToBeStolenByHackers = true; stores.Add(documentStore); return(documentStore); }
public void DestinationServerDownTest() { server1 = CreateServer(8111, "D1"); store1 = new DocumentStore { DefaultDatabase = "Northwind", Url = "http://*****:*****@"~\D1\N" } } }); var db1Url = store1.Url + "/databases/Northwind"; SetupReplication(store1.DatabaseCommands, "http://localhost:8112/databases/Northwind"); var replicationDocument = store1.DatabaseCommands.Get("Raven/Replication/Destinations"); var request = store1.JsonRequestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(null, db1Url + "/admin/replicationInfo", "POST", new OperationCredentials(null, CredentialCache.DefaultCredentials), store1.Conventions)); request.Write(replicationDocument.DataAsJson.ToString(Formatting.None)); var result = request.ReadResponseJson() as RavenJArray; Assert.NotNull(result); Assert.Equal(1, result.Length); Assert.NotNull(result[0].Value <string>("Status")); Assert.Equal(-2, result[0].Value <int>("Code")); }
protected override void ConfigureServer(RavenDbServer server, string fileSystemName) { server.SystemDatabase.Documents.Put("Raven/Authorization/WindowsSettings", null, RavenJObject.FromObject(new WindowsAuthDocument { RequiredUsers = new List <WindowsAuthData> { new WindowsAuthData() { Name = string.Format("{0}\\{1}", domain, username), Enabled = true, Databases = new List <ResourceAccess> { new ResourceAccess { TenantId = Constants.SystemDatabase, Admin = true }, // required to create file system new ResourceAccess { TenantId = fileSystemName } } } } }), new RavenJObject(), null); }
public IDocumentStore NewRemoteDocumentStore(bool fiddler = false, RavenDbServer ravenDbServer = null, string databaseName = null, bool deleteDirectoryAfter = true, bool deleteDirectoryBefore = true, bool runInMemory = true) { ravenDbServer = ravenDbServer ?? GetNewServer(runInMemory: runInMemory, deleteDirectory: deleteDirectoryBefore); 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()); }
public EmbeddedDocumentStore() { server = new RavenDbServer(); }