Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
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
            });
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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)
            });
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Initializes this object.
        /// </summary>
        /// <remarks>
        ///    Plugin authors are deliberately prevented from calling this constructor directly because it's signature may change
        ///    over time. In order to create an instance of this type, simply call <see cref="IServiceContainer.CreateMergedLogFile"/>.
        /// </remarks>
        /// <param name="scheduler"></param>
        /// <param name="maximumWaitTime"></param>
        /// <param name="sources"></param>
        internal MergedLogFile(ITaskScheduler scheduler, TimeSpan maximumWaitTime, params ILogFile[] sources)
            : base(scheduler)
        {
            if (sources == null)
            {
                throw new ArgumentNullException(nameof(sources));
            }
            if (sources.Any(x => x == null))
            {
                throw new ArgumentException("sources.Any(x => x == null)", nameof(sources));
            }
            if (sources.Length > LogLineSourceId.MaxSources)
            {
                throw new ArgumentException(string.Format("Only up to {0} sources are supported ({1} were given)", LogLineSourceId.MaxSources, sources.Length));
            }

            _sources = sources;
            _index   = new MergedLogFileIndex(sources);
            _pendingModifications = new ConcurrentQueue <MergedLogFilePendingModification>();
            var logFileIndices = new Dictionary <ILogFile, byte>();

            _maximumWaitTime = maximumWaitTime;
            _properties      = new LogFilePropertyList(LogFileProperties.Minimum);

            byte idx = 0;

            foreach (var logFile in _sources)
            {
                logFile.AddListener(this, maximumWaitTime, MaximumBatchSizePerSource);
                logFileIndices.Add(logFile, idx);

                ++idx;
            }
            StartTask();
        }
Ejemplo n.º 8
0
        public void TestGetInvalid()
        {
            var index = new MergedLogFileIndex();

            index.Get(new LogFileSection(0, 1)).Should().Equal(new object[]
            {
                MergedLogLineIndex.Invalid
            });
        }
Ejemplo n.º 9
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");
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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
            });
        }
Ejemplo n.º 12
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
            });
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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));
        }