public void IntervalThrowsOutsideOf100Or10000() { var journal = new FileJournal("Interval", null); try { Assert.Throws <ArgumentException>(() => { journal.JournalIntervalSeconds = 17; }); Assert.Throws <ArgumentException>(() => { journal.JournalIntervalSeconds = 10003; }); Assert.DoesNotThrow(() => { journal.JournalIntervalSeconds = 259; }); } finally { journal.DeleteDatabase(); Directory.Delete("Interval"); } }
public void GetCollectionGetsObjectsOfType() { var index = new IndexStore("GetAll"); var fs = new FileDataStore("GetAll", index); var journal = new FileJournal("GetAll", fs); var store = new InMemoryDataStore(fs, journal.DirectoryPath); try { var sword = new Sword("Lego Sword", 13); var katana = new Sword("Lego Katana", 27); store.PutObject(sword, 1); store.PutObject(katana, 2); store.PutObject(new Car("Kia", "Aieeee", "Black"), 3); var actual = store.GetCollection <Sword>(); Assert.AreEqual(2, actual.Count); Assert.AreEqual(sword, actual.ElementAt(0)); Assert.AreEqual(katana, actual.ElementAt(1)); } finally { Directory.Delete("GetAll", true); } }
public async Task WriteTwoJournalBlocks() { var guid = Guid.NewGuid(); var journal = new FileJournal($"./{guid.ToString()}.txt"); await journal.Open(); var entries = new(JournalEntryType Type, byte[] Content, long TransactionId)[]
private void GenerateFileJournal(AcquisitionParameter parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } if (!Directory.Exists(this.JournalAbsoluteSavePath)) { return; } var now = DateTimePrecise.Now; var fileJournal = new FileJournal(); fileJournal.JournalHeader.CreationDateTime = now; fileJournal.JournalHeader.CreationSource = this.AgentUniversalName; fileJournal.JournalHeader.Id = parameters.SequenceId; fileJournal.JournalHeader.Sequenceur = parameters.SequenceId; fileJournal.JournalHeader.Root = Path.Combine(this.JournalRootPath, parameters.SequenceId); var filename = string.IsNullOrWhiteSpace(this.Configuration.Agent.Journalisation.CharacterizationFileName) ? this.AgentUniversalName : string.Format("{0}.{1}", this.Configuration.Agent.Journalisation.CharacterizationFileName, this.AgentUniversalName); var xmlCompleteFileName = Path.Combine(this.JournalAbsoluteSavePath, parameters.SequenceId + "." + filename + this.FileJournalFileExtension); int rootLength = 1 + Path.Combine(this.JournalRootPath, parameters.SequenceId).Length; using (var recorder = new JournalBufferedRecorder(xmlCompleteFileName, fileJournal, forceFlush: true)) { try { foreach (var file in SafeFileEnumerator.EnumerateFiles(this.JournalAbsoluteSavePath, "*.*", SearchOption.AllDirectories).Where(file => !Path.GetExtension(file).Equals(".fjx", StringComparison.InvariantCultureIgnoreCase))) { fileJournal.Add(new FileJournalEntry { FileName = Path.GetFileName(file), RelativePath = file.Substring(rootLength), DateTime = now }); } foreach (var journalEntry in _fileJournalEntries) { fileJournal.Add(journalEntry); } } finally { fileJournal.Close(); } } }
public LocalDatabase(string databaseName) { this.databaseName = databaseName.SantizeForDatabaseName(); string archiveName = GetDatabaseFileName(databaseName); if (File.Exists(archiveName)) { GzipHelper.DecompressFiles(archiveName); File.Delete(archiveName); } indexStore = new IndexStore(databaseName); fileStore = new FileDataStore(databaseName, indexStore); journal = new FileJournal(databaseName, fileStore); memoryStore = new InMemoryDataStore(fileStore, journal.DirectoryPath); }
public void RecordDeleteCreatesJournalEntry() { var journal = new FileJournal("Wrote", null); journal.JournalIntervalSeconds = 10000; string dir = string.Format(@"{0}\Journal", journal.DirectoryPath); try { Assert.AreEqual(0, Directory.GetFiles(dir).Length); journal.RecordDelete(1); Assert.AreEqual(1, Directory.GetFiles(dir).Length); } finally { journal.DeleteDatabase(); Directory.Delete("Wrote"); } }
public void InMemoryStoreCanPut1MillionObjectsWithoutCrashing() { var index = new IndexStore("1M"); var fs = new FileDataStore("1M", index); var journal = new FileJournal("1M", fs); var store = new InMemoryDataStore(fs, journal.DirectoryPath); try { Assert.DoesNotThrow(() => { for (int i = 0; i < 1000000; i++) { store.PutObject(new Sword("Exo-Sword " + i, 1), i); } }); } finally { Directory.Delete("1M", true); } }
public void GetReturnsPutObjects() { var index = new IndexStore("GetAndPut"); var fs = new FileDataStore("GetAndPut", index); var journal = new FileJournal("GetAndPut", fs); var store = new InMemoryDataStore(fs, journal.DirectoryPath); try { var sword = new Sword("Lego Sword", 13); var car = new Car("Kia", "Eeep", "Black"); store.PutObject(sword, 1); store.PutObject(car, 3); Assert.AreEqual(sword, store.GetObject <Sword>(1)); Assert.AreEqual(car, store.GetObject <Car>(3)); } finally { Directory.Delete("GetAndPut", true); } }