Пример #1
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));
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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
            });
        }
Пример #5
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));
        }
Пример #6
0
        public void TestGetInvalid()
        {
            var index = new MergedLogFileIndex();

            index.Get(new LogFileSection(0, 1)).Should().Equal(new object[]
            {
                MergedLogLineIndex.Invalid
            });
        }
Пример #7
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);
        }
Пример #8
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
            });
        }
Пример #9
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
            });
        }
Пример #10
0
        public void TestAppendOneSourceOneLine()
        {
            var source = new InMemoryLogFile();

            source.AddEntry("Hello, World!", LevelFlags.Other, new DateTime(2019, 5, 28, 19, 55, 10));

            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)
            });

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

            indices.Count.Should().Be(1);
            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, 55, 10));
        }