示例#1
0
        public void TestOneSourceAppendReset()
        {
            var source1 = new InMemoryLogFile();

            source1.AddEntry("A", LevelFlags.None, new DateTime(2019, 5, 28, 00, 34, 0));

            var index   = new MergedLogFileIndex(source1);
            var changes = index.Process(new MergedLogFilePendingModification(source1, new LogFileSection(0, 1)));

            changes.Should().Equal(new object[]
            {
                new LogFileSection(0, 1)
            });

            changes = index.Process(new MergedLogFilePendingModification(source1, LogFileSection.Reset));
            changes.Should().Equal(new object[]
            {
                LogFileSection.Reset
            });
            index.Count.Should().Be(0);
            index.Get(new LogFileSection(0, 1)).Should().Equal(new object[]
            {
                MergedLogLineIndex.Invalid
            });
        }
示例#2
0
        public void TestAppendTwoSourcesWrongOrderSeparateChangesPartialInvalidation()
        {
            var source1 = new InMemoryLogFile();

            source1.AddEntry("A", LevelFlags.None, new DateTime(2019, 5, 28, 00, 34, 0));
            source1.AddEntry("C", LevelFlags.None, new DateTime(2019, 5, 28, 00, 36, 0));
            var source2 = new InMemoryLogFile();

            source2.AddEntry("B", LevelFlags.None, new DateTime(2019, 5, 28, 00, 35, 0));
            source2.AddEntry("D", LevelFlags.None, new DateTime(2019, 5, 28, 00, 37, 0));

            var index   = new MergedLogFileIndex(source1, source2);
            var changes = index.Process(new MergedLogFilePendingModification(source1, new LogFileSection(0, 2)));

            changes.Should().Equal(new object[]
            {
                new LogFileSection(0, 2)
            });

            changes = index.Process(new MergedLogFilePendingModification(source2, new LogFileSection(0, 2)));
            changes.Should().Equal(new object[]
            {
                LogFileSection.Invalidate(1, 1),
                new LogFileSection(1, 3)
            });
        }
示例#3
0
        public void TestAppendTwoSourcesInterlocked()
        {
            var source1 = new InMemoryLogFile();

            source1.AddEntry("A", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 0));
            source1.AddEntry("B", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 2));
            source1.AddEntry("C", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 4));
            source1.AddEntry("D", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 6));
            source1.AddEntry("E", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 8));
            var source2 = new InMemoryLogFile();

            source2.AddEntry("1", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 1));
            source2.AddEntry("2", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 3));
            source2.AddEntry("3", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 5));
            source2.AddEntry("4", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 7));
            source2.AddEntry("5", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 9));

            var index = new MergedLogFileIndex(source1, source2);

            index.Process(new MergedLogFilePendingModification(source1, new LogFileSection(0, 5)));
            index.Process(new MergedLogFilePendingModification(source2, new LogFileSection(0, 5)));

            var indices = index.Get(new LogFileSection(0, 10));

            indices[0].LogFileIndex.Should().Be(0);
            indices[0].SourceLineIndex.Should().Be(0);

            indices[1].LogFileIndex.Should().Be(1);
            indices[1].SourceLineIndex.Should().Be(0);

            indices[2].LogFileIndex.Should().Be(0);
            indices[2].SourceLineIndex.Should().Be(1);

            indices[3].LogFileIndex.Should().Be(1);
            indices[3].SourceLineIndex.Should().Be(1);

            indices[4].LogFileIndex.Should().Be(0);
            indices[4].SourceLineIndex.Should().Be(2);

            indices[5].LogFileIndex.Should().Be(1);
            indices[5].SourceLineIndex.Should().Be(2);

            indices[6].LogFileIndex.Should().Be(0);
            indices[6].SourceLineIndex.Should().Be(3);

            indices[7].LogFileIndex.Should().Be(1);
            indices[7].SourceLineIndex.Should().Be(3);

            indices[8].LogFileIndex.Should().Be(0);
            indices[8].SourceLineIndex.Should().Be(4);

            indices[9].LogFileIndex.Should().Be(1);
            indices[9].SourceLineIndex.Should().Be(4);
        }
示例#4
0
        public void TestAppendOneSourceThreeOneLinesOneWithoutTimestamp()
        {
            var source = new InMemoryLogFile();

            source.AddEntry("A", LevelFlags.None, new DateTime(2019, 5, 28, 19, 30, 1));
            source.AddEntry("B", LevelFlags.None);
            source.AddEntry("C", LevelFlags.None, new DateTime(2019, 5, 28, 19, 30, 42));

            var index   = new MergedLogFileIndex(source);
            var changes = index.Process(new MergedLogFilePendingModification(source, new LogFileSection(0, 3)));

            changes.Should().Equal(new object[] { new LogFileSection(0, 2) });

            index.Count.Should().Be(2);

            var indices = index.Get(new LogFileSection(0, 2));

            indices.Count.Should().Be(2);
            indices[0].LogFileIndex.Should().Be(0);
            indices[0].SourceLineIndex.Should().Be(0);
            indices[0].OriginalLogEntryIndex.Should().Be(0);
            indices[0].MergedLogEntryIndex.Should().Be(0);
            indices[0].Timestamp.Should().Be(new DateTime(2019, 5, 28, 19, 30, 1));

            indices[1].LogFileIndex.Should().Be(0);
            indices[1].SourceLineIndex.Should().Be(2);
            indices[1].OriginalLogEntryIndex.Should().Be(2);
            indices[1].MergedLogEntryIndex.Should().Be(1);
            indices[1].Timestamp.Should().Be(new DateTime(2019, 5, 28, 19, 30, 42));
        }
示例#5
0
        public void TestOneSourceManySameTimestamps()
        {
            var source = new InMemoryLogFile();

            source.AddEntry("A", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 053));
            source.AddEntry("B", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 100));
            source.AddEntry("C", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 100));
            source.AddEntry("D", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 100));
            source.AddEntry("E", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 115));
            source.AddEntry("F", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 115));
            source.AddEntry("G", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 115));
            source.AddEntry("H", LevelFlags.None, new DateTime(2017, 9, 20, 15, 09, 02, 115));

            var index = new MergedLogFileIndex(source);

            index.Process(new MergedLogFilePendingModification(source, new LogFileSection(0, 8)));

            var indices = index.Get(new LogFileSection(0, 8));

            indices[0].SourceLineIndex.Should().Be(0);
            indices[1].SourceLineIndex.Should().Be(1);
            indices[2].SourceLineIndex.Should().Be(2);
            indices[3].SourceLineIndex.Should().Be(3);
            indices[4].SourceLineIndex.Should().Be(4);
            indices[5].SourceLineIndex.Should().Be(5);
            indices[6].SourceLineIndex.Should().Be(6);
            indices[7].SourceLineIndex.Should().Be(7);
        }
示例#6
0
        public void TestAppendOneSourceTwoIdenticalTimestamps()
        {
            var source = new InMemoryLogFile();

            source.AddEntry("A", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 0));
            source.AddEntry("B", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 2));
            source.AddEntry("C1", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 4));
            source.AddEntry("C2", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 4));
            source.AddEntry("D", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 6));
            source.AddEntry("E", LevelFlags.None, new DateTime(2019, 5, 29, 00, 11, 8));

            var index = new MergedLogFileIndex(source);

            index.Process(new MergedLogFilePendingModification(source, new LogFileSection(0, 6)));

            var indices = index.Get(new LogFileSection(0, 6));

            indices[0].LogFileIndex.Should().Be(0);
            indices[0].SourceLineIndex.Should().Be(0);

            indices[1].LogFileIndex.Should().Be(0);
            indices[1].SourceLineIndex.Should().Be(1);

            indices[2].LogFileIndex.Should().Be(0);
            indices[2].SourceLineIndex.Should().Be(2);

            indices[3].LogFileIndex.Should().Be(0);
            indices[3].SourceLineIndex.Should().Be(3);

            indices[4].LogFileIndex.Should().Be(0);
            indices[4].SourceLineIndex.Should().Be(4);

            indices[5].LogFileIndex.Should().Be(0);
            indices[5].SourceLineIndex.Should().Be(5);
        }
示例#7
0
        public void TestAppendTwoSourcesWrongOrder()
        {
            var source1 = new InMemoryLogFile();

            source1.AddEntry("B", LevelFlags.None, new DateTime(2019, 5, 27, 23, 10, 0));
            var source2 = new InMemoryLogFile();

            source2.AddEntry("A", LevelFlags.None, new DateTime(2019, 5, 27, 23, 09, 0));

            var index   = new MergedLogFileIndex(source1, source2);
            var changes = index.Process(new MergedLogFilePendingModification(source1, new LogFileSection(0, 1)),
                                        new MergedLogFilePendingModification(source2, new LogFileSection(0, 1)));

            changes.Should().Equal(new object[]
            {
                new LogFileSection(0, 2)
            });

            var indices = index.Get(new LogFileSection(0, 2));

            indices.Count.Should().Be(2);
            indices[0].LogFileIndex.Should().Be(1);
            indices[0].SourceLineIndex.Should().Be(0);
            indices[0].OriginalLogEntryIndex.Should().Be(0);
            indices[0].MergedLogEntryIndex.Should().Be(0);
            indices[0].Timestamp.Should().Be(new DateTime(2019, 5, 27, 23, 9, 0));

            indices[1].LogFileIndex.Should().Be(0);
            indices[1].SourceLineIndex.Should().Be(0);
            indices[1].OriginalLogEntryIndex.Should().Be(0);
            indices[1].MergedLogEntryIndex.Should().Be(1);
            indices[1].Timestamp.Should().Be(new DateTime(2019, 5, 27, 23, 10, 0));
        }
示例#8
0
        public void TestOneSourceResetEmpty()
        {
            var source1 = new InMemoryLogFile();

            source1.AddEntry("A", LevelFlags.None, new DateTime(2019, 5, 28, 00, 34, 0));

            var index   = new MergedLogFileIndex(source1);
            var changes = index.Process(new MergedLogFilePendingModification(source1, LogFileSection.Reset));

            changes.Should().BeEmpty("because the index itself is empty and thus its source resetting itself doesn't require any change");
        }
示例#9
0
        public void TestAppendOneSourceTwoLines()
        {
            var source = new InMemoryLogFile();

            source.AddEntry("Hello,", LevelFlags.None, new DateTime(2019, 5, 27, 23, 37, 0));

            var index   = new MergedLogFileIndex(source);
            var changes = index.Process(new MergedLogFilePendingModification(source, new LogFileSection(0, 1)));

            changes.Should().Equal(new object[]
            {
                new LogFileSection(0, 1)
            });

            source.AddEntry("Hello,", LevelFlags.None, new DateTime(2019, 5, 27, 23, 38, 0));
            changes = index.Process(new MergedLogFilePendingModification(source, new LogFileSection(1, 1)));
            changes.Should().Equal(new object[]
            {
                new LogFileSection(1, 1)
            });

            var indices = index.Get(new LogFileSection(0, 2));

            indices.Count.Should().Be(2);
            indices[0].LogFileIndex.Should().Be(0);
            indices[0].SourceLineIndex.Should().Be(0);
            indices[0].OriginalLogEntryIndex.Should().Be(0);
            indices[0].MergedLogEntryIndex.Should().Be(0);
            indices[0].Timestamp.Should().Be(new DateTime(2019, 5, 27, 23, 37, 0));

            indices[1].LogFileIndex.Should().Be(0);
            indices[1].SourceLineIndex.Should().Be(1);
            indices[1].OriginalLogEntryIndex.Should().Be(1);
            indices[1].MergedLogEntryIndex.Should().Be(1);
            indices[1].Timestamp.Should().Be(new DateTime(2019, 5, 27, 23, 38, 0));
        }
示例#10
0
        public void TestGetPartialInvalid()
        {
            var source = new InMemoryLogFile();

            source.AddEntry("Hello, World!", LevelFlags.None, new DateTime(2019, 5, 28, 0, 53, 0));

            var index = new MergedLogFileIndex(source);

            index.Process(new MergedLogFilePendingModification(source, new LogFileSection(0, 1)));

            index.Get(new LogFileSection(0, 2)).Should().Equal(new object[]
            {
                new MergedLogLineIndex(0, 0, 0, 0, new DateTime(2019, 5, 28, 0, 53, 0)),
                MergedLogLineIndex.Invalid
            });
        }
示例#11
0
        public void TestAppendOneSourceOneLineWithoutTimestamp()
        {
            var source = new InMemoryLogFile();

            source.AddEntry("Hello, World!", LevelFlags.None);

            var index   = new MergedLogFileIndex(source);
            var changes = index.Process(new MergedLogFilePendingModification(source, new LogFileSection(0, 1)));

            changes.Should().BeEmpty("because the only added line doesn't have a timestamp and thus cannot be added to the merged log file");

            index.Count.Should().Be(0);
            index.Get(new LogFileSection(0, 1)).Should().Equal(new object[]
            {
                MergedLogLineIndex.Invalid
            });
        }
示例#12
0
        public void TestOneSourceResetAndAppend()
        {
            var source1 = new InMemoryLogFile();

            source1.AddEntry("A", LevelFlags.None, new DateTime(2019, 5, 28, 00, 34, 0));

            var index   = new MergedLogFileIndex(source1);
            var changes = index.Process(
                new MergedLogFilePendingModification(source1, new LogFileSection(0, 2)),
                new MergedLogFilePendingModification(source1, LogFileSection.Reset),
                new MergedLogFilePendingModification(source1, new LogFileSection(0, 1))
                );

            changes.Should().Equal(new object[]
            {
                new LogFileSection(0, 1)
            }, "because the index shouldn't process changes belonging to source1 prior to the last reset");
            index.Count.Should().Be(1);
        }
示例#13
0
        /// <inheritdoc />
        protected override TimeSpan RunOnce(CancellationToken token)
        {
            // Every Process() invocation locks the sync root until
            // the changes have been processed. The goal is to minimize
            // total process time and to prevent locking for too long.
            // The following number has been empirically determined
            // via testing and it felt alright :P
            const int maxLineCount = 5 * MaximumBatchSizePerSource;

            while (TryDequeueUpTo(maxLineCount, out var modifications))
            {
                var changes = _index.Process(modifications);
                UpdateProperties();
                NotifyListeners(changes);
            }

            _progress = Percentage.HundredPercent;
            SetEndOfSourceReached();

            return(_maximumWaitTime);
        }