public EmbeddableDocumentStore NewDocumentStore(string storageType, bool inMemory, int? allocatedMemory) { 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 = inMemory, } }; if (documentStore.Configuration.RunInMemory == false) IOExtensions.DeleteDirectory(path); documentStore.Initialize(); new RavenDocumentsByEntityName().Execute(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"); }
public void WillNotSerializeEvents() { IOExtensions.DeleteDirectory("Data"); try { using (var documentStore = new EmbeddableDocumentStore()) { documentStore.Configuration.DataDirectory = "Data"; documentStore.Conventions.CustomizeJsonSerializer = x => x.TypeNameHandling = TypeNameHandling.Auto; documentStore.Initialize(); var bar = new Bar(); var foo = new Foo(); foo.PropertyChanged += bar.FooChanged; using (var session = documentStore.OpenSession()) { session.Store(foo); session.SaveChanges(); } } } finally { IOExtensions.DeleteDirectory("Data"); } }
public void AllArchetypesShouldBeAbleToBeStored() { var store = new EmbeddableDocumentStore() { RunInMemory = true }; store.Initialize(); int count; using (new DocumentSessionScope(store.OpenSession())) { var archetypeRepository = new ArchetypeRepository(); count = Directory.GetFiles(@"Archetypes\xml\", "*.xml").ToList().Count; foreach (var file in Directory.GetFiles(@"Archetypes\xml\", "*.xml")) { Debug.WriteLine(file); var archetypeString = File.ReadAllText(file); var archetype = new ArchetypeXmlParser().Parse(archetypeString); archetypeRepository.Save(archetype); } } using (var session = store.OpenSession()) { var result = session.Advanced.LuceneQuery<Archetype>().WaitForNonStaleResults().Take(count).ToList(); var ravenCount = result.Count(); Assert.AreEqual(count, ravenCount); } }
public QueryResultCountsWithProjections() { store = new EmbeddableDocumentStore() { RunInMemory = true }; store.Initialize(); PopulateDatastore(); }
public void Install(IWindsorContainer container, IConfigurationStore store) { var documentStore = new EmbeddableDocumentStore { DataDirectory = "data" }; documentStore.Initialize(); container.Register(Component.For<IDocumentStore>().Instance(documentStore)); CreateIndexesForModules(documentStore); }
public void WontCreateDirectory() { var embeddableDocumentStore = new EmbeddableDocumentStore() { Url = "http://localhost:8080" }; embeddableDocumentStore.Initialize(); Assert.Null(embeddableDocumentStore.DocumentDatabase); }
public void Can_Store_and_Load_Dynamic_Documents() { //When running in the XUnit GUI strange things happen is we just create a path relative to //the .exe itself, so make our folder in the System temp folder instead ("<user>\AppData\Local\Temp") string directoryName = Path.Combine(Path.GetTempPath(), "ravendb.RavenDynamicDocs"); IOExtensions.DeleteDirectory(directoryName); dynamic person = new CustomDynamicClass(); person.FirstName = "Ellen"; person.LastName = "Adams"; dynamic employee = new ExpandoObject(); employee.Name = "John Smith"; employee.Age = 33; employee.Phones = new ExpandoObject(); employee.Phones.Home = "0111 123123"; employee.Phones.Office = "0772 321123"; employee.Prices = new List<decimal>() { 123.4M, 123432.54M }; using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); using (var session = db.OpenSession()) { session.Store(employee); string idEmployee = employee.Id; session.Store(person); string idPerson = person.Id; //Check that a field called "Id" is added to the dynamic object (as it doesn't already exist) //and that it has something in it (not null and not empty) Assert.False(String.IsNullOrEmpty(idEmployee)); Assert.False(String.IsNullOrEmpty(idPerson)); session.SaveChanges(); session.Advanced.Clear(); //Pull the docs back out of RavenDB and see if the values are the same dynamic employeeLoad = session.Load<object>(idEmployee); Assert.Equal("John Smith", employeeLoad.Name); Assert.Equal("0111 123123", employeeLoad.Phones.Home); Assert.Equal("0772 321123", employeeLoad.Phones.Office); Assert.Contains(123.4D, employeeLoad.Prices); Assert.Contains(123432.54D, employeeLoad.Prices); Assert.IsType<DynamicNullObject>(employeeLoad.Address); dynamic personLoad = session.Load<object>(idPerson); Assert.Equal("Ellen", personLoad.FirstName); Assert.Equal("Adams", personLoad.LastName); Assert.IsType<DynamicNullObject>(personLoad.Age); } } }
public void CreateStore() { store = new EmbeddableDocumentStore { Configuration = new RavenConfiguration { RunInMemory = true } }; store.Initialize(); IndexCreation.CreateIndexes(typeof(ImageTags_GroupByTagName).Assembly, store); }
public static IDocumentStore StartupDb() { NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8080); var store = new EmbeddableDocumentStore { DataDirectory = @"App_Data\RavenDB", UseEmbeddedHttpServer = true }; store.Initialize(); return store; }
public void CreateStore() { store = new EmbeddableDocumentStore { Configuration = new RavenConfiguration { RunInMemory = true } }; store.Initialize(); IndexCreation.CreateIndexes(typeof(MonoVersionIndex).Assembly, store); }
public void WontCreateDirectoryWhenSettingStorage() { var embeddableDocumentStore = new EmbeddableDocumentStore() { Configuration = { DefaultStorageTypeName = "munin" }, Url = "http://localhost:8080" }; embeddableDocumentStore.Initialize(); Assert.Null(embeddableDocumentStore.DocumentDatabase); }
public IDocumentStore CreateStore() { var documentStore = new EmbeddableDocumentStore { DataDirectory = "c:\\Raven", RunInMemory = true, UseEmbeddedHttpServer = true, }; documentStore.Initialize(); return documentStore; }
private DocumentStore NewDocumentStore() { path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentStoreServerTests)).CodeBase); path = Path.Combine(path, "TestDb").Substring(6); var documentStore = new EmbeddableDocumentStore { Configuration = { DataDirectory = path } }; documentStore.Initialize(); return documentStore; }
public void Can_perform_Skip_Take_Query() { using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); string indexName = "UserIndex"; using (var session = db.OpenSession()) { AddData(session); db.DatabaseCommands.DeleteIndex(indexName); db.DatabaseCommands.PutIndex<User, User>(indexName, new IndexDefinition<User, User>() { Map = docs => from doc in docs select new { doc.Name, doc.Age }, SortOptions = {{x=>x.Name, SortOptions.StringVal}} }, true); WaitForQueryToComplete(session, indexName); var allResults = session.Query<User>(indexName).OrderBy(x => x.Name) .Where(x => x.Age > 0); Assert.Equal(4, allResults.ToArray().Count()); var takeResults = session.Query<User>(indexName).OrderBy(x => x.Name) .Where(x => x.Age > 0) .Take(3); //There are 4 items of data in the db, but using Take(1) means we should only see 4 Assert.Equal(3, takeResults.ToArray().Count()); var skipResults = session.Query<User>(indexName).OrderBy(x => x.Name) .Where(x => x.Age > 0) .Skip(1); //Using Skip(1) means we should only see the last 3 Assert.Equal(3, skipResults.ToArray().Count()); Assert.DoesNotContain(firstUser, skipResults.ToArray()); var skipTakeResults = session.Query<User>(indexName).OrderBy(x => x.Name) .Where(x => x.Age > 0) .Skip(1) .Take(2); //Using Skip(1), Take(2) means we shouldn't see the 1st or 4th (last) users Assert.Equal(2, skipTakeResults.ToArray().Count()); Assert.DoesNotContain<User>(firstUser, skipTakeResults.ToArray()); Assert.DoesNotContain<User>(lastUser, skipTakeResults.ToArray()); } } }
private DocumentStore NewDocumentStore() { path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentStoreServerTests)).CodeBase); path = Path.Combine(path, "TestDb").Substring(6); var documentStore = new EmbeddableDocumentStore() { Configuration = { RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, DataDirectory = path } }; documentStore.Initialize(); return documentStore; }
private DocumentStore CreateDocumentStore() { var store = new EmbeddableDocumentStore { RunInMemory = _inMemory }; if (!_inMemory && _storeDirectory != null) store.DataDirectory = _storeDirectory; store.Initialize(); CreateIndices(store); return store; }
private DocumentStore NewDocumentStore() { path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(RavenDBEventStoreTests)).CodeBase); path = Path.Combine(path, "TestDb").Substring(6); if (Directory.Exists(path)) { File.SetAttributes(path, FileAttributes.Directory); Directory.Delete(path, true); } var documentStore = new EmbeddableDocumentStore { DataDirectory = path }; documentStore.Initialize(); return documentStore; }
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 CanRunSpatialQueriesInMemory() { var documentStore = new EmbeddableDocumentStore { RunInMemory = true }; documentStore.Initialize(); var def = new IndexDefinition<Listing> { Map = listings => from listingItem in listings select new { listingItem.ClassCodes, listingItem.Latitude, listingItem.Longitude, _ = SpatialIndex.Generate(listingItem.Latitude, listingItem.Longitude) } }; documentStore.DatabaseCommands.PutIndex("RadiusClassifiedSearch", def); }
public void AndEntirelyInMemoryForUberFastTestingHAHAHAHA() { // Application start-up IDocumentStore store = new EmbeddableDocumentStore() { Configuration = new Raven.Database.RavenConfiguration() { RunInMemory = true } }; store.Initialize(); // Per unit of work using (var session = store.OpenSession()) { } }
public static void Startup() { var documentStore = new EmbeddableDocumentStore { Configuration = new RavenConfiguration { DataDirectory = "App_Data\\RavenDB", } }; documentStore.Initialize(); ObjectFactory.Initialize(config => { config.AddRegistry(new CoreRegistry(documentStore)); }); IndexCreation.CreateIndexes(typeof(ImageTags_GroupByTagName).Assembly, documentStore); }
public static void Startup() { var documentStore = new EmbeddableDocumentStore { Configuration = new RavenConfiguration { DataDirectory = "App_Data\\RavenDB", } }; documentStore.Initialize(); IndexCreation.CreateIndexes(typeof(MonoVersionIndex).Assembly, documentStore); FubuApplication .For<WomRegistry>() .StructureMapObjectFactory(x=> x.AddRegistry(new CoreRegistry(documentStore))) .Bootstrap(RouteTable.Routes); }
public void AndICanAlsoCanRunInProcess() { // Application start-up IDocumentStore store = new EmbeddableDocumentStore() { Configuration = new Raven.Database.RavenConfiguration() { DataDirectory = "Data" } }; store.Initialize(); // Per unit of work using (var session = store.OpenSession()) { } }
public static void Main(string[] args) { Flickr flickr = new Flickr(); // PRIVATE KEY REMOVED var documentStore = new EmbeddableDocumentStore { Configuration = new RavenConfiguration { DataDirectory = RAVENPATH, } }; documentStore.Initialize(); using (var session = documentStore.OpenSession()) { PerformInitialSetup(session); session.Advanced.DatabaseCommands.DeleteByIndex("Raven/DocumentsByEntityName", new Raven.Database.Data.IndexQuery() { Query = "Tag:Images" }, true); FlickrImporter importer = new FlickrImporter(session, new ImageUploaderService( new RavenFileStorageService(documentStore), new ImageRepository(session)), new UserRepository(session)); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "dog"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "swan"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "computer"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "megaman"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "rainbow"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "sunset"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "raven"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "coffee"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "jumper"); } while (documentStore.DocumentDatabase.Statistics.StaleIndexes.Length > 0) { Thread.Sleep(1000); Console.WriteLine("Waiting for indexing to complete"); } }
private DocumentStore NewDocumentStore() { path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentStoreServerTests)).CodeBase); path = Path.Combine(path, "TestDb").Substring(6); var documentStore = new EmbeddableDocumentStore { Configuration = { RunInUnreliableYetFastModeThatIsNotSuitableForProduction =true, DataDirectory = path }, Conventions = { FindTypeTagName = type => typeof(IServer).IsAssignableFrom(type) ? "Servers" : null } }; documentStore.Initialize(); return documentStore; }
public EmbeddableDocumentStore NewDocumentStore() { path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentStoreServerTests)).CodeBase); path = Path.Combine(path, "TestDb").Substring(6); var documentStore = new EmbeddableDocumentStore() { Configuration = { DataDirectory = path, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true, } }; if (documentStore.Configuration.RunInMemory == false) IOExtensions.DeleteDirectory(path); documentStore.Initialize(); return documentStore; }
public void InMemoryDoesNotCreateDataDir() { if(Directory.Exists("Data")) Directory.Delete("Data", true); NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(8080); using (var store = new EmbeddableDocumentStore { RunInMemory = true, UseEmbeddedHttpServer = true, Configuration = { Port = 8080, RunInMemory = true } }) { store.Initialize(); Assert.False(Directory.Exists("Data")); } }
public void Can_perform_First_and_FirstOrDefault_Query() { using (var db = new EmbeddableDocumentStore() { RunInMemory = true}) { db.Initialize(); string indexName = "UserIndex"; using (var session = db.OpenSession()) { AddData(session); db.DatabaseCommands.DeleteIndex(indexName); var result = db.DatabaseCommands.PutIndex<User, User>(indexName, new IndexDefinition<User, User>() { Map = docs => from doc in docs select new { doc.Name, doc.Age }, SortOptions = {{x=>x.Name, SortOptions.StringVal}} }, true); WaitForQueryToComplete(session, indexName); var firstItem = session.Query<User>(indexName).OrderBy(x=>x.Name) .First(); Assert.Equal(firstUser, firstItem); //This should pull out the 1st parson ages 60, i.e. "Bob" var firstAgeItem = session.Query<User>(indexName) .First(x => x.Age == 60); Assert.Equal("Bob", firstAgeItem.Name); //No-one is aged 15, so we should get null var firstDefaultItem = session.Query<User>(indexName) .FirstOrDefault(x => x.Age == 15); Assert.Null(firstDefaultItem); } } }
public void Can_Use_Where() { //When running in the XUnit GUI strange things happen is we just create a path relative to //the .exe itself, so make our folder in the System temp folder instead ("<user>\AppData\Local\Temp") string directoryName = Path.Combine(Path.GetTempPath(), "ravendb.RavenWhereTests"); IOExtensions.DeleteDirectory(directoryName); using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); string indexName = "CommitByRevision"; using (var session = db.OpenSession()) { AddData(session); db.DatabaseCommands.DeleteIndex(indexName); var result = db.DatabaseCommands.PutIndex<CommitInfo, CommitInfo>(indexName, new IndexDefinition<CommitInfo, CommitInfo>() { Map = docs => from doc in docs select new { doc.Revision}, }, true); WaitForQueryToComplete(session, indexName); var Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision == 1); //There is one CommitInfo with Revision == 1 Assert.Equal(1, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision == 0); //There is not CommitInfo with Revision = 0 so hopefully we do not get any result Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision < 1 ); //There are 0 CommitInfos which has Revision <1 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision < 2); //There is one CommitInfo with Revision < 2 Assert.Equal(1, Results.ToArray().Count()); //Revision of resulted CommitInfo has to be 1 var cinfo = Results.ToArray()[0]; Assert.Equal(1, cinfo.Revision); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision <= 2); //There are 2 CommitInfos which has Revision <=2 Assert.Equal(2, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 7); //There are 0 CommitInfos which has Revision >7 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 6); //There are 1 CommitInfos which has Revision >6 Assert.Equal(1, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision >= 6); //There are 2 CommitInfos which has Revision >=6 Assert.Equal(2, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 6 && x.Revision < 6); //There are 0 CommitInfos which has Revision >6 && <6 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision >= 6 && x.Revision <= 6); //There are 1 CommitInfos which has Revision >=6 && <=6 Assert.Equal(1, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision >= 6 && x.Revision < 6); //There are 0 CommitInfos which has Revision >=6 && <6 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 6 && x.Revision <= 6); //There are 0 CommitInfos which has Revision >6 && <=6 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision >= 7 && x.Revision <= 1); //There are 0 CommitInfos which has Revision >=7 && <= 1 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 7 && x.Revision < 1); //There are 0 CommitInfos which has Revision >7 && < 1 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 7 || x.Revision < 1); //There are 0 CommitInfos which has Revision >7 || < 1 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision >= 7 || x.Revision < 1); //There are 1 CommitInfos which has Revision >=7 || < 1 Assert.Equal(1, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 7 || x.Revision <= 1); //There are 1 CommitInfos which has Revision >7 || <= 1 Assert.Equal(1, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision >= 7 || x.Revision <= 1); //There are 2 CommitInfos which has Revision >=7 || <= 1 Assert.Equal(2, Results.ToArray().Count()); } } }