Ejemplo n.º 1
0
        private static long RunTestJournalWriter(string path, int bufferSize)
        {
            if(File.Exists(path))
            {
                File.Delete(path);
            }

            long ioCount = 0;
            var blockWriter = new FileBlockWriter(path, bufferSize);
            using (var journalWriter = new JournalWriter(bufferSize, blockWriter))
            {
                var buffer = new ArraySegment<byte>(new byte[bufferSize]);
                var start = DateTime.UtcNow;

                while (DateTime.UtcNow - start < TimeSpan.FromSeconds(TestDuration)) // run the test for 10sec
                {
                    journalWriter.WriteBytes(buffer, true);
                    ioCount++;
                }

                var durationInMs = (DateTime.UtcNow - start).TotalMilliseconds;
                PrintReport("JournalWriter", bufferSize, ioCount, durationInMs);
            }
            return ioCount;
        }
Ejemplo n.º 2
0
        private static long RunTestJournalWriter(string path, int bufferSize)
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            long ioCount     = 0;
            var  blockWriter = new FileBlockWriter(path, bufferSize);

            using (var journalWriter = new JournalWriter(bufferSize, blockWriter))
            {
                var buffer = new ArraySegment <byte>(new byte[bufferSize]);
                var start  = DateTime.UtcNow;

                while (DateTime.UtcNow - start < TimeSpan.FromSeconds(TestDuration)) // run the test for 10sec
                {
                    journalWriter.WriteBytes(buffer, true);
                    ioCount++;
                }

                var durationInMs = (DateTime.UtcNow - start).TotalMilliseconds;
                PrintReport("JournalWriter", bufferSize, ioCount, durationInMs);
            }
            return(ioCount);
        }
Ejemplo n.º 3
0
        public void ReadAndWriteJournalFile()
        {
            string path = Path.GetFullPath("TestData\\RWJournal");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            JournalWriter jw = new JournalWriter(path, 324, false);

            List <KeyValuePair <Key, Value> > items = new List <KeyValuePair <Key, Value> > ();

            for (int i = 0; i < 10000; i++)
            {
                Key   randKey   = Key.Random(20);
                Value randValue = Value.Random(100);
                jw.Add(randKey, randValue);
                items.Add(new KeyValuePair <Key, Value> (randKey, randValue));
            }
            jw.Close();

            JournalReader jr = new JournalReader(path, 324);
            int           j  = 0;

            foreach (var pair in jr.Enumerate())
            {
                Assert.AreEqual(items [j].Key, pair.Key);
                Assert.AreEqual(items [j].Value, pair.Value);
                j++;
            }
            jr.Close();
        }
Ejemplo n.º 4
0
        public void RenameTag_ThrowsArgumentNullException_IfNewTagIsNullEmptyOrWhitespace(string newTag)
        {
            var fileSystem = new MockFileSystem();
            var writer     = new JournalWriter(fileSystem, "J:\\Current");
            var reader     = A.Fake <IJournalReader>();

            Assert.Throws <ArgumentNullException>(() => writer.RenameTag(reader, "valid-value", newTag));
        }
Ejemplo n.º 5
0
        public void Test_Append_Success()
        {
            using (var target = new JournalWriter("Journal.log"))
            {
                target.Append("sss");
            }

            Assert.True(File.Exists("Journal.log"));
        }
Ejemplo n.º 6
0
        protected override void RunJournalCommand()
        {
            if (Last)
            {
                var journal   = OpenJournal();
                var lastEntry = journal.CreateIndex <JournalEntryFile>().SelectMany(x => x.Entries).OrderByDescending(x => x.EntryDate).First();
                SystemProcess.Start(lastEntry.FilePath);
                return;
            }

            var       fileSystem    = new FileSystem();
            var       journalWriter = new JournalWriter(fileSystem, Location);
            string    path;
            LocalDate entryDate;

            switch (ParameterSetName)
            {
            case "Name":
            {
                entryDate = EntryName.EndsWith(".md") ? Journal.FileNameWithExtensionPattern.Parse(EntryName).Value : Journal.FileNamePattern.Parse(EntryName).Value;
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            case "Date":
            {
                entryDate = LocalDate.FromDateTime(Date);
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            case "DateOffset":
            {
                entryDate = Today.PlusDays(DateOffset);
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            case "Entry":
            {
                entryDate = Journal.FileNamePattern.Parse(Entry.EntryName).Value;
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            default:
                throw new NotSupportedException();
            }

            if (!fileSystem.File.Exists(path))
            {
                throw new PSInvalidOperationException($"An entry does not exist for '{entryDate}'.");
            }

            SystemProcess.Start(path);
        }
Ejemplo n.º 7
0
        public BatchRunJobExecutor(BatchJob job,
                                   Func <BatchJob, TextWriter, IProgressHandler, BatchRunner> batchRunnerFact)
        {
            m_Job = job;

            m_LogWriter = new JournalWriter(true);
            m_PrgHander = new ProgressHandler();

            m_BatchRunnerFact = batchRunnerFact;

            m_IsExecuting = false;
        }
Ejemplo n.º 8
0
        public IDocumentCollection <TDocument> CreateHighSecurityFileSystemCollection <TDocument>(string dirPath, byte[] key) where TDocument : AbstractDocument, new()
        {
            FileSystem fileSystem = new FileSystem();

            if (!fileSystem.DirectoryExists(dirPath))
            {
                fileSystem.CreateDirectory(dirPath);
            }
            string        path          = HashedPathGenerator.GetPath(dirPath, "_journal");
            JournalPlayer journalPlayer = new JournalPlayer(path, fileSystem);
            JournalWriter journalWriter = new JournalWriter(path, fileSystem);
            string        path2         = HashedPathGenerator.GetPath(dirPath, "_packedFile");
            string        path3         = HashedPathGenerator.GetPath(dirPath, "_packedFileMeta");
            PackedFile    packedFile    = new PackedFile(path2, path3, journalWriter, fileSystem);
            IndexFactory  indexFactory  = new IndexFactory(dirPath, journalWriter, fileSystem);

            return(new DocumentCollection <TDocument>(packedFile, indexFactory, key, journalPlayer, journalWriter));
        }
Ejemplo n.º 9
0
        public void ReadCorruptedJournalFile()
        {
            string path = Path.GetFullPath("TestData\\ReadCorruptedJournal");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            JournalWriter jw = new JournalWriter(path, 324, false);

            List <KeyValuePair <Key, Value> > items = new List <KeyValuePair <Key, Value> > ();

            for (int i = 0; i < 10; i++)
            {
                Key   randKey   = Key.Random(20);
                Value randValue = Value.Random(100);
                jw.Add(randKey, randValue);
                items.Add(new KeyValuePair <Key, Value> (randKey, randValue));
            }
            jw.Close();

            // Reopen the file and add a partial record
            var fileName = Config.JournalFile(path, 324);
            var writer   = new BinaryWriter(new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.None, 1024, false));
            Key key      = Key.Random(20);

            writer.Write7BitEncodedInt(key.Length);
            writer.Write(key.InternalBytes);
            writer.Write7BitEncodedInt(0);
            writer.Flush();
            writer.Close();

            JournalReader jr = new JournalReader(path, 324);
            int           j  = 0;

            foreach (var pair in jr.Enumerate())
            {
                Assert.AreEqual(items [j].Key, pair.Key);
                Assert.AreEqual(items [j].Value, pair.Value);
                j++;
            }
            jr.Close();
        }
Ejemplo n.º 10
0
        public void RenameTag_CombinesNewFrontMatterWithExistingBody_Always()
        {
            var fileSystem = new MockFileSystem();
            var filePath   = "J:\\JournalRoot\\2019\\03 March\\2019.01.01.md";

            fileSystem.AddFile(filePath, new MockFileData(TestEntries.WithTags1, Encoding.UTF8));
            var writer         = new JournalWriter(fileSystem, "J:\\Current");
            var originalReader = new JournalReader(fileSystem, filePath);

            originalReader.FrontMatter.Tags.Should().OnlyContain(x => new List <string> {
                "doh", "blah"
            }.Contains(x));

            writer.RenameTag(originalReader, "blah", "horseman");
            var newReader = new JournalReader(fileSystem, filePath);

            newReader.RawBody.Should().Be(originalReader.RawBody);
            newReader.FrontMatter.Tags.Should().OnlyContain(x => new List <string> {
                "doh", "horseman"
            }.Contains(x));
        }
Ejemplo n.º 11
0
        public void AddAndLookupItemsPersisted()
        {
            string path = Path.GetFullPath("TestData\\AddAndLookupItemsPersisted");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            JournalWriter jw = new JournalWriter("TestData\\AddAndLookupItemsPersisted", 523, false);

            List <KeyValuePair <Key, Value> > values = new List <KeyValuePair <Key, Value> >();

            for (int i = 0; i < 10000; i++)
            {
                var randomKey   = Key.Random(40);
                var randomValue = Value.Random(256);

                values.Add(new KeyValuePair <Key, Value>(randomKey, randomValue));
                jw.Add(randomKey, randomValue);
            }
            jw.Close();

            MemTable mtl = new MemTable();

            mtl.ReadFromJournal("TestData\\AddAndLookupItemsPersisted", 523);

            Value value;

            foreach (var pair in values)
            {
                Assert.IsTrue(mtl.Lookup(pair.Key, out value));
                Assert.AreEqual(pair.Value, value);
            }
            Assert.IsFalse(mtl.Lookup(Key.Random(40), out value));

            Assert.AreEqual(10000 * (40 + 256), mtl.Size);
            Assert.IsTrue(mtl.Full);
        }
Ejemplo n.º 12
0
        public async Task Export(ExportOptions opts)
        {
            m_CurrentCancellationToken = new CancellationTokenSource();

            var logWriter = new JournalWriter(true);
            var prgHander = new ProgressHandler();

            logWriter.Log             += OnLog;
            prgHander.JobScopeSet     += OnJobScopeSet;
            prgHander.ProgressChanged += OnProgressChanged;

            try
            {
                using (var exporter = new Exporter(logWriter, m_JobMgr, prgHander))
                {
                    await exporter.Export(opts, m_CurrentCancellationToken.Token).ConfigureAwait(false);
                }
            }
            finally
            {
                logWriter.Log             -= OnLog;
                prgHander.ProgressChanged -= OnProgressChanged;
            }
        }
Ejemplo n.º 13
0
        protected override void RunJournalCommand()
        {
            if (Last)
            {
                var journal   = OpenJournal();
                var lastEntry = journal.CreateIndex <JournalEntryFile>().SelectMany(x => x.Entries).OrderByDescending(x => x.EntryDate).FirstOrDefault();
                if (lastEntry == null)
                {
                    throw new PSInvalidOperationException("No entries found!");
                }
                SystemProcess.Start(lastEntry.FilePath);
                return;
            }

            var       fileSystem    = new FileSystem();
            var       journalWriter = new JournalWriter(fileSystem, Location);
            string    path;
            LocalDate entryDate;

            switch (ParameterSetName)
            {
            case "Name":
            {
                entryDate = EntryName.EndsWith(".md") ? Journal.FileNameWithExtensionPattern.Parse(EntryName).Value : Journal.FileNamePattern.Parse(EntryName).Value;
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            case "Date":
            {
                entryDate = LocalDate.FromDateTime(Date);
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            case "DateOffset":
            {
                entryDate = Today.PlusDays(DateOffset);
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            case "Entry":
            {
                entryDate = Journal.FileNamePattern.Parse(Entry.EntryName).Value;
                path      = journalWriter.GetJournalEntryFilePath(entryDate);
                break;
            }

            default:
                throw new NotSupportedException();
            }

            if (!fileSystem.File.Exists(path))
            {
                throw new PSInvalidOperationException($"An entry does not exist for '{entryDate}'.");
            }

            Commit(GitCommitType.PreOpenJournalEntry);
            SystemProcess.Start(path);

            if (Wait)
            {
                var result = Choice($"Reading entry for {entryDate}", "Continue on to next entry?", 0, "&Continue", "&Quit");
                Commit(GitCommitType.PostOpenJournalEntry);
                if (result == 1)
                {
                    ThrowTerminatingError("Pipeline terminated at user's request.", ErrorCategory.NotSpecified);
                }
            }
        }