コード例 #1
0
        public void TestMergeMultiline3()
        {
            var source1   = new InMemoryLogFile();
            var source1Id = new LogLineSourceId(0);
            var source2   = new InMemoryLogFile();
            var source2Id = new LogLineSourceId(1);
            var merged    = new MergedLogFile(_taskScheduler, TimeSpan.Zero, source1, source2);

            var t1 = new DateTime(2017, 11, 26, 11, 45, 0);

            source1.AddEntry("Foo", LevelFlags.Info, t1);
            _taskScheduler.RunOnce();

            var t3 = new DateTime(2017, 11, 26, 11, 45, 2);

            source1.AddEntry("bar", LevelFlags.Warning, t3);
            _taskScheduler.RunOnce();

            var t2 = new DateTime(2017, 11, 26, 11, 45, 1);

            source2.AddMultilineEntry(LevelFlags.Debug, t2, "Hello,", "World!");
            _taskScheduler.RunOnce();

            merged.Count.Should().Be(4);
            merged.GetLine(0).Should().Be(new LogLine(0, 0, source1Id, "Foo", LevelFlags.Info, t1));
            merged.GetLine(1).Should().Be(new LogLine(1, 1, source2Id, "Hello,", LevelFlags.Debug, t2));
            merged.GetLine(2).Should().Be(new LogLine(2, 1, source2Id, "World!", LevelFlags.Debug, t2));
            merged.GetLine(3).Should().Be(new LogLine(3, 2, source1Id, "bar", LevelFlags.Warning, t3));
        }
コード例 #2
0
        public void TestManySources2()
        {
            const int sourceCount = 100;
            var       sources     = new InMemoryLogFile[sourceCount];

            for (int i = 0; i < sourceCount; ++i)
            {
                sources[i] = new InMemoryLogFile();
            }

            var merged = new MergedLogFile(_taskScheduler, TimeSpan.Zero, sources);
            var end    = new DateTime(2017, 11, 26, 17, 56, 0);

            for (int i = 0; i < sourceCount; ++i)
            {
                // Sources are modified in  reverse order: This is the worst case.
                // Reality is somewhere in between...
                sources[i].AddEntry(i.ToString(), LevelFlags.Info, end - TimeSpan.FromSeconds(i));
            }

            var changes = ListenToChanges(merged, sourceCount);

            _taskScheduler.RunOnce();

            // For once, we expect the content of the merged data source to be as expected...
            merged.Count.Should().Be(sourceCount, "because every source added one line");
            for (int i = 0; i < sourceCount; ++i)
            {
                int idx = sourceCount - i - 1;
                merged.GetLine(i).Should().Be(new LogLine(i, i, new LogLineSourceId((byte)idx),
                                                          idx.ToString(), LevelFlags.Info,
                                                          end - TimeSpan.FromSeconds(idx)));
            }

            // But then it should also have fired as few changes as possible!
            changes.Should().Equal(new object[]
            {
                LogFileSection.Reset,
                new LogFileSection(0, sourceCount)
            });
        }
コード例 #3
0
        public void TestManySources1()
        {
            const int sourceCount = 100;
            var       sources     = new InMemoryLogFile[sourceCount];

            for (int i = 0; i < sourceCount; ++i)
            {
                sources[i] = new InMemoryLogFile();
            }

            var merged = new MergedLogFile(_taskScheduler, TimeSpan.Zero, sources);
            var start  = new DateTime(2017, 11, 26, 17, 56, 0);

            for (int i = 0; i < sourceCount; ++i)
            {
                // Sources are modified in order with perfectly ascending timestamps:
                // This is a rather unrealistic scenario...
                sources[i].AddEntry(i.ToString(), LevelFlags.Info, start + TimeSpan.FromSeconds(i));
            }

            var changes = ListenToChanges(merged, sourceCount);

            _taskScheduler.RunOnce();

            // For once, we expect the content of the merged data source to be as expected...
            merged.Count.Should().Be(sourceCount, "because every source added one line");
            for (byte i = 0; i < sourceCount; ++i)
            {
                merged.GetLine(i).Should().Be(new LogLine(i, i, new LogLineSourceId(i),
                                                          i.ToString(), LevelFlags.Info,
                                                          start + TimeSpan.FromSeconds(i)));
            }

            // But then it should also have fired as few changes as possible!
            changes.Should().Equal(new object[]
            {
                LogFileSection.Reset,
                new LogFileSection(0, sourceCount)
            });
        }