public void CanQueryMetadata() { using (var store = new EmbeddableDocumentStore { RunInMemory = true }) { store.Initialize(); using (var s = store.OpenSession()) { s.Store(new User { Metadata = { IsActive = true } }); s.SaveChanges(); } using (var s = store.OpenSession()) { var actual = s.Query <User>() .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite()) .Where(x => x.Metadata.IsActive == true) .Count(); Assert.Equal(1, actual); } } }
private static void DoTest(DateTime dt, DateTimeKind inKind, DateTimeKind outKind) { Assert.Equal(inKind, dt.Kind); using (var documentStore = new EmbeddableDocumentStore { RunInMemory = true }) { documentStore.Initialize(); using (var session = documentStore.OpenSession()) { session.Store(new Foo { Id = "foos/1", DateTime = dt }); session.SaveChanges(); } using (var session = documentStore.OpenSession()) { var foo = session.Query <Foo>() .Customize(x => x.WaitForNonStaleResults()) .FirstOrDefault(x => x.DateTime == dt); WaitForUserToContinueTheTest(documentStore); Assert.Equal(dt, foo.DateTime); Assert.Equal(outKind, foo.DateTime.Kind); } } }
public EmbeddableDocumentStore NewDocumentStore( bool runInMemory = true, string requestedStorage = null, ComposablePartCatalog catalog = null, bool deleteDirectory = true, bool deleteDirectoryOnDispose = true) { path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(RavenTestBase)).CodeBase); path = Path.Combine(path, DataDir).Substring(6); var storageType = GetDefaultStorageType(requestedStorage); var documentStore = new EmbeddableDocumentStore { Configuration = { DefaultStorageTypeName = storageType, DataDirectory = path, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, RunInMemory = storageType.Equals("esent", StringComparison.OrdinalIgnoreCase) == false && runInMemory, Port = 8079 } }; if (catalog != null) { documentStore.Configuration.Catalog.Catalogs.Add(catalog); } try { ModifyStore(documentStore); ModifyConfiguration(documentStore.Configuration); if (deleteDirectory) { IOExtensions.DeleteDirectory(path); } documentStore.Initialize(); CreateDefaultIndexes(documentStore); if (deleteDirectoryOnDispose) { documentStore.Disposed += ClearDatabaseDirectory; } return(documentStore); } catch { // We must dispose of this object in exceptional cases, otherwise this test will break all the following tests. documentStore.Dispose(); throw; } finally { stores.Add(documentStore); } }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register(Component.For <IDocumentStore>().UsingFactoryMethod(() => { var documentStore = new EmbeddableDocumentStore { DefaultDatabase = Constants.DatabaseName, DataDirectory = Constants.DataFolder, UseEmbeddedHttpServer = true, }; documentStore.Configuration.Port = 9090; documentStore.Initialize(); return(documentStore); }).LifestyleSingleton(), Component.For <IDocumentSession>().UsingFactoryMethod(kernel => { var documentStore = kernel.Resolve <IDocumentStore>(); return(documentStore.OpenSession()); }).LifestylePerWebRequest(), Component.For <IAsyncDocumentSession>().UsingFactoryMethod(kernel => { var documentStore = kernel.Resolve <IDocumentStore>(); return(documentStore.OpenAsyncSession()); }).LifestylePerWebRequest()); }
public override void Load() { Bind <IDocumentStore>() .ToMethod(context => { NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8080); var documentStore = new EmbeddableDocumentStore { DataDirectory = "App_Data", UseEmbeddedHttpServer = true, }; return(documentStore.Initialize()); }) .InSingletonScope(); Bind <IDocumentSession>().ToMethod(context => context.Kernel.Get <IDocumentStore>().OpenSession()) .InRequestScope() .OnDeactivation(x => { if (x == null) { return; } x.SaveChanges(); x.Dispose(); }); }
public void Should_retrieve_all_entities_using_connection_string() { using (var documentStore = new EmbeddableDocumentStore { ConnectionStringName = "Local", Configuration = { RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true } }) { path = documentStore.DataDirectory; documentStore.Initialize(); var session1 = documentStore.OpenSession(); session1.Store(new Company { Name = "Company 1" }); session1.Store(new Company { Name = "Company 2" }); session1.SaveChanges(); var session2 = documentStore.OpenSession(); var companyFound = session2.Advanced.LuceneQuery <Company>() .WaitForNonStaleResults() .ToArray(); Assert.Equal(2, companyFound.Length); } }
public void Setup() { var _store = new EmbeddableDocumentStore { RunInMemory = true }; _store.Initialize(); IndexCreation.CreateIndexes(typeof(ScheduleMessagesInCoordinatorIndex).Assembly, _store); Top1CoordinatorId = Guid.NewGuid(); var mostRecentCoordinators = new List <CoordinatorTrackingData> { new CoordinatorTrackingData(new List <MessageSendingStatus>()) { CoordinatorId = Top1CoordinatorId, MetaData = new SmsMetaData { Topic = "barry" }, CreationDateUtc = DateTime.Now.AddDays(-3), }, }; var scheduleTrackingData = new ScheduleTrackingData { CoordinatorId = Top1CoordinatorId, MessageStatus = MessageStatus.Sent }; SmsTrackingSession = _store.OpenSession(); foreach (var coordinatorTrackingData in mostRecentCoordinators) { SmsTrackingSession.Store(coordinatorTrackingData, coordinatorTrackingData.CoordinatorId.ToString()); } SmsTrackingSession.Store(scheduleTrackingData, Guid.NewGuid().ToString()); SmsTrackingSession.SaveChanges(); }
public EmbeddableDocumentStore NewDocumentStore(string storageType = "munin", bool inMemory = true, int?allocatedMemory = null) { path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentStoreServerTests)).CodeBase); path = Path.Combine(path, "TestDb").Substring(6); var documentStore = new EmbeddableDocumentStore { Configuration = { DataDirectory = path, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, DefaultStorageTypeName = storageType, RunInMemory = storageType == "munin" && inMemory, } }; ModifyStore(documentStore); ModifyConfiguration(documentStore.Configuration); if (documentStore.Configuration.RunInMemory == false) { IOExtensions.DeleteDirectory(path); } documentStore.Initialize(); CreateDefaultIndexes(documentStore); if (allocatedMemory != null && inMemory) { var transactionalStorage = ((TransactionalStorage)documentStore.DocumentDatabase.TransactionalStorage); transactionalStorage.EnsureCapacity(allocatedMemory.Value); } return(documentStore); }
public static Configure EmbeddedRavenSubscriptionStorage(this Configure config) { var store = new EmbeddableDocumentStore { ResourceManagerId = DefaultResourceManagerId, DataDirectory = DefaultDataDirectory }; store.Initialize(); return RavenSubscriptionStorage(config, store, "Default"); }
private EmbeddableDocumentStore CreateEmbeddableStoreAtPort(int port, bool enableCompressionBundle = false, bool removeDataDirectory = true, Action <DocumentStore> configureStore = null, AnonymousUserAccessMode anonymousUserAccessMode = AnonymousUserAccessMode.All) { NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port); var embeddedStore = new EmbeddableDocumentStore { UseEmbeddedHttpServer = true, Configuration = { Settings = { { "Raven/ActiveBundles", "replication" + (enableCompressionBundle ? ";compression" : string.Empty) } }, AnonymousUserAccessMode = anonymousUserAccessMode, DataDirectory = "Data #" + stores.Count, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, RunInMemory = true, Port = port, DefaultStorageTypeName = GetDefaultStorageType() }, }; if (removeDataDirectory) { IOExtensions.DeleteDirectory(embeddedStore.Configuration.DataDirectory); } ConfigureStore(embeddedStore); if (configureStore != null) { configureStore(embeddedStore); } embeddedStore.Initialize(); stores.Add(embeddedStore); return(embeddedStore); }
public void StandaloneTestForPostingOnStackOverflow() { var testDocument = new Cart { Email = "*****@*****.**" }; using (var documentStore = new EmbeddableDocumentStore { RunInMemory = true }) { documentStore.Initialize(); using (var session = documentStore.OpenSession()) { using (var transaction = new TransactionScope()) { session.Store(testDocument); session.SaveChanges(); transaction.Complete(); } } using (var session = documentStore.OpenSession()) { using (var transaction = new TransactionScope()) { var documentToDelete = session .Query <Cart>() .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite()) .First(c => c.Email == testDocument.Email); session.Delete(documentToDelete); session.SaveChanges(); transaction.Complete(); } } using (var session = documentStore.OpenSession()) { session.Advanced.AllowNonAuthoritativeInformation = false; RavenQueryStatistics statistics; Assert.Null(session .Query <Cart>() .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite()) .FirstOrDefault(c => c.Email == testDocument.Email)); // we force a wait here, because there is no way to wait for NonAuthoritativeInformation on a count var actualCount = session .Query <Cart>() .Statistics(out statistics) .Customize(x => x.WaitForNonStaleResultsAsOfLastWrite()) .Count(c => c.Email == testDocument.Email); Assert.False(statistics.IsStale); Assert.False(statistics.NonAuthoritativeInformation); Assert.Equal(0, actualCount); } } }
public void StartRaven(EmbeddableDocumentStore documentStore, Settings settings, bool maintenanceMode) { Settings = settings; Directory.CreateDirectory(settings.DbPath); if (settings.RunInMemory) { documentStore.RunInMemory = true; } else { documentStore.DataDirectory = settings.DbPath; documentStore.Configuration.CompiledIndexCacheDirectory = settings.DbPath; } documentStore.UseEmbeddedHttpServer = maintenanceMode || settings.ExposeRavenDB; documentStore.EnlistInDistributedTransactions = false; var localRavenLicense = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "RavenLicense.xml"); if (File.Exists(localRavenLicense)) { Logger.InfoFormat("Loading RavenDB license found from {0}", localRavenLicense); documentStore.Configuration.Settings["Raven/License"] = ReadAllTextWithoutLocking(localRavenLicense); } else { Logger.InfoFormat("Loading Embedded RavenDB license"); documentStore.Configuration.Settings["Raven/License"] = ReadLicense(); } //This is affects only remote access to the database in maintenace mode and enables access without authentication documentStore.Configuration.Settings["Raven/AnonymousAccess"] = "Admin"; documentStore.Configuration.Settings["Raven/Licensing/AllowAdminAnonymousAccessForCommercialUse"] = "true"; if (Settings.RunCleanupBundle) { documentStore.Configuration.Settings.Add("Raven/ActiveBundles", "CustomDocumentExpiration"); } documentStore.Configuration.DisableClusterDiscovery = true; documentStore.Configuration.ResetIndexOnUncleanShutdown = true; documentStore.Configuration.Port = settings.DatabaseMaintenancePort; documentStore.Configuration.HostName = settings.Hostname == "*" || settings.Hostname == "+" ? "localhost" : settings.Hostname; documentStore.Conventions.SaveEnumsAsIntegers = true; documentStore.Conventions.CustomizeJsonSerializer = serializer => serializer.Binder = MigratedTypeAwareBinder; documentStore.Configuration.Catalog.Catalogs.Add(new AssemblyCatalog(GetType().Assembly)); documentStore.Initialize(); Logger.Info("Index creation started"); IndexCreation.CreateIndexes(typeof(RavenBootstrapper).Assembly, documentStore); IndexCreation.CreateIndexes(typeof(SagaSnapshot).Assembly, documentStore); }
public void SetupRavenDb() { _documentStore = new EmbeddableDocumentStore { RunInMemory = true }; _documentStore.Initialize(); }
private static EmbeddableDocumentStore createStore() { var returnStore = new EmbeddableDocumentStore(); returnStore.DataDirectory = @"./PersistedData"; returnStore.Initialize(); return(returnStore); }
private void TryInitStore(string dataDirectory) { Store = new EmbeddableDocumentStore { DataDirectory = dataDirectory }; Store.Initialize(); }
public RavenDatabaseManager() { Database = new EmbeddableDocumentStore { DataDirectory = "Data" }; Database.Initialize(); }
public void SetUpContext() { DocumentStore = new EmbeddableDocumentStore { RunInMemory = true }; DocumentStore.Initialize(); }
protected void Setup() { DocumentStore = new EmbeddableDocumentStore { DataDirectory = "Data" }; DocumentStore.Initialize(); }
public DatabaseAccessService() { documentStore = new EmbeddableDocumentStore { DataDirectory = "Data" }; documentStore.Initialize(); }
/// <summary>Initializes static members of the <see cref="DocumentStore"/> class.</summary> static DocumentStore() { SingletonInstance = new EmbeddableDocumentStore { DataDirectory = DalUtils.GetDbPath() }; SingletonInstance.Initialize(); }
public AccountRepositoryTests() { _documentStore = new EmbeddableDocumentStore { Conventions = { IdentityPartsSeparator = "-" } }; _documentStore.Initialize(); _session = _documentStore.OpenSession(); }
public RavenRepository() { _documentStore = new EmbeddableDocumentStore() { ConnectionStringName = "RavenDB" }; _documentStore.Initialize(); }
public void RunInMemoryTest() { using (var documentStore = new EmbeddableDocumentStore { RunInMemory = true }) { documentStore.Initialize(); } }
protected override void InitializeDocumentStore(string connectionStringName) { DocumentStore = new EmbeddableDocumentStore { ConnectionStringName = connectionStringName }; DocumentStore.Initialize(); }
public IDocumentSession GetSession() { lock (isStoreSet) { if (!(bool)isStoreSet) { RavenConfiguration ravenConfiguration = null; bool webUIEnabled = false; int webUIPort = 0; var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var serviceConfigurationSection = config.GetSection("ServiceConfigurationSection") as ServiceConfigurationSection; if (serviceConfigurationSection != null) { ravenConfiguration = serviceConfigurationSection.ravendb; if (ravenConfiguration != null) { webUIEnabled = ravenConfiguration.WebUIEnabled; webUIPort = ravenConfiguration.WebUIPort; if (webUIEnabled) { if (webUIPort < 0 || webUIPort > 65535) { webUIEnabled = false; } else { webUIEnabled = CheckPortIsAvailable(webUIPort); } } } } documentStore = new EmbeddableDocumentStore(); documentStore.Configuration.DataDirectory = "Data\\RavenDB"; documentStore.Configuration.DefaultStorageTypeName = typeof(Raven.Storage.Esent.TransactionalStorage).AssemblyQualifiedName; documentStore.Conventions.FindIdentityProperty = x => x.Name == "Oid"; documentStore.Conventions.MaxNumberOfRequestsPerSession = 1000; documentStore.Initialize(); IndexCreation.CreateIndexes(GetType().Assembly, documentStore); if (webUIEnabled) { documentStore.Configuration.Port = webUIPort; var httpServer = new HttpServer(documentStore.Configuration, documentStore.DocumentDatabase); httpServer.Init(); httpServer.StartListening(); } isStoreSet = true; } } return(documentStore.OpenSession()); }
public void DistinctByValue() { var str = new EmbeddableDocumentStore { RunInMemory = true, Conventions = { IdentityPartsSeparator = "-" }, UseEmbeddedHttpServer = true, Configuration = { Port = 8079 } }; str.Configuration.Storage.Voron.AllowOn32Bits = true; using (var store = str .Initialize()) { using (var session = store.OpenSession()) { session.Store(new TestClass() { Value = "test1", Value2 = "" }); session.Store(new TestClass() { Value = "test2" }); session.Store(new TestClass() { Value = "test3" }); session.SaveChanges(); } using (var session = store.OpenSession()) { var hello = new List <TestClass>(); var values = session.Query <TestClass>() .Select(x => x.Value) .Distinct() .ToArray(); //this is passing Assert.True(values.Count() == 3); Assert.True(values.Contains("test2")); var values2 = session.Query <TestClass>() .Select(x => x.Value2) .Distinct() .ToArray(); //this is not passing Assert.False(values2.Contains("TestClasses-2")); Assert.Equal(2, values2.Count()); } } }
public void InitializeTest() { using (var documentStore = new EmbeddableDocumentStore { DataDirectory = "Data" }) { documentStore.Initialize(); documentStore.DataDirectory.Should().Contain("Data"); } }
public QueryResultCountsWithProjections() { store = new EmbeddableDocumentStore() { RunInMemory = true }; store.Initialize(); PopulateDatastore(); }
private void SetupRavenDB() { _logger.Info("Setting up document store..."); _documentStore = new EmbeddableDocumentStore { DataDirectory = Core.Settings.ApplicationDirectories.Database }; _documentStore.Initialize(); }
protected void Open() { Store = new EmbeddableDocumentStore { RunInMemory = true }; Store.Initialize(); }
[Fact] // See issue #145 (http://github.com/ravendb/ravendb/issues/#issue/145) public void Can_Use_Static_Fields_In_Where_Clauses() { using (var db = new EmbeddableDocumentStore() { RunInMemory = true }) { db.Initialize(); db.DatabaseCommands.PutIndex("DateTime", new IndexDefinition { Map = @"from info in docs.DateTimeInfos select new { info.TimeOfDay }" , }); var currentTime = SystemTime.Now; using (var s = db.OpenSession()) { s.Store(new DateTimeInfo { TimeOfDay = currentTime + TimeSpan.FromHours(1) }); s.Store(new DateTimeInfo { TimeOfDay = currentTime + TimeSpan.FromHours(2) }); s.Store(new DateTimeInfo { TimeOfDay = currentTime + TimeSpan.FromMinutes(1) }); s.Store(new DateTimeInfo { TimeOfDay = currentTime + TimeSpan.FromSeconds(10) }); s.SaveChanges(); } using (var s = db.OpenSession()) { //Just issue a blank query to make sure there are no stale results var test = s.Query <DateTimeInfo>("DateTime") .Customize(x => x.WaitForNonStaleResults()) .Where(x => x.TimeOfDay > currentTime) .ToArray(); IQueryable <DateTimeInfo> testFail = null; Assert.DoesNotThrow(() => { testFail = s.Query <DateTimeInfo>("DateTime").Where(x => x.TimeOfDay > DateTime.MinValue); // =====> Throws an exception }); Assert.NotEqual(null, testFail); var dt = DateTime.MinValue; var testPass = s.Query <DateTimeInfo>("DateTime").Where(x => x.TimeOfDay > dt); //=====>Works Assert.Equal(testPass.Count(), testFail.Count()); } } }
public void Setup() { var store = new EmbeddableDocumentStore { RunInMemory = true, DataDirectory = Guid.NewGuid().ToString() }; store.Initialize(); entity = new TestSaga(); entity.Id = Guid.NewGuid(); SetupEntity(entity); var persister = new RavenSagaPersister { Store = store }; persister.Save(entity); savedEntity = persister.Get<TestSaga>(entity.Id); }
public void Should_delete_the_saga() { var store = new EmbeddableDocumentStore { RunInMemory = true, DataDirectory = Guid.NewGuid().ToString() }; store.Initialize(); var saga = new TestSaga {Id = Guid.NewGuid()}; var persister = new RavenSagaPersister { Store = store }; persister.Save(saga); Assert.NotNull(persister.Get<TestSaga>(saga.Id)); persister.Complete(saga); Assert.Null(persister.Get<TestSaga>(saga.Id)); }
public RevisionDocumentDatabaseTests() { _documentStore = new EmbeddableDocumentStore { RunInMemory = true, }; _documentStore.Initialize(); _documentStore.DocumentDatabase.PutTriggers.Add(new RevisionDocumentPutTrigger { Database = _documentStore.DocumentDatabase }); _documentStore.DocumentDatabase.ReadTriggers.Add(new HideRevisionDocumentsFromIndexingReadTrigger { Database = _documentStore.DocumentDatabase }); }