public void TestManyEntries4() { var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero); _lines.Add(new LogLine(0, 0, "Foo", LevelFlags.None)); _lines.Add(new LogLine(1, 1, "INFO: Bar", LevelFlags.Info)); logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 2)); _taskScheduler.RunOnce(); logFile.GetSection(new LogFileSection(0, 2)) .Should().Equal(new object[] { new LogLine(0, 0, "Foo", LevelFlags.None), new LogLine(1, 1, "INFO: Bar", LevelFlags.Info) }); logFile.OnLogFileModified(_source.Object, LogFileSection.Invalidate(1, 1)); _taskScheduler.RunOnce(); logFile.Count.Should().Be(1); _lines[1] = new LogLine(1, 1, "Bar", LevelFlags.None); _lines.Add(new LogLine(2, 2, "INFO: Sup", LevelFlags.Info)); logFile.OnLogFileModified(_source.Object, new LogFileSection(1, 2)); _taskScheduler.RunOnce(); logFile.Count.Should().Be(3); logFile.GetSection(new LogFileSection(0, 3)) .Should().Equal(new object[] { new LogLine(0, 0, "Foo", LevelFlags.None), new LogLine(1, 0, "Bar", LevelFlags.None), new LogLine(2, 1, "INFO: Sup", LevelFlags.Info) }); }
public void TestManyEntries7() { var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero); logFile.AddListener(_listener.Object, TimeSpan.Zero, 3); _lines.Add(new LogLine(0, 0, "A", LevelFlags.None)); logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1)); _taskScheduler.RunOnce(); _lines.Add(new LogLine(1, 1, "B", LevelFlags.Info)); logFile.OnLogFileModified(_source.Object, new LogFileSection(1, 1)); _taskScheduler.RunOnce(); _lines[1] = new LogLine(1, 1, "B", LevelFlags.None); _lines.Add(new LogLine(2, 2, "C", LevelFlags.None)); logFile.OnLogFileModified(_source.Object, LogFileSection.Invalidate(1, 1)); logFile.OnLogFileModified(_source.Object, new LogFileSection(1, 2)); _taskScheduler.RunOnce(); logFile.GetSection(new LogFileSection(0, 3)) .Should().Equal( new LogLine(0, 0, "A", LevelFlags.None), new LogLine(1, 1, "B", LevelFlags.None), new LogLine(2, 2, "C", LevelFlags.None)); }
public void TestReset2() { var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero); _lines.Add(new LogLine(0, 0, "A", LevelFlags.Info)); _lines.Add(new LogLine(1, 1, "B", LevelFlags.Warning)); logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 2)); _taskScheduler.RunOnce(); logFile.Count.Should().Be(2); _lines.Clear(); logFile.OnLogFileModified(_source.Object, LogFileSection.Reset); _taskScheduler.RunOnce(); logFile.Count.Should().Be(0); _lines.Add(new LogLine(0, 0, "A", LevelFlags.Info)); _lines.Add(new LogLine(1, 1, "A continued", LevelFlags.None)); logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 2)); _taskScheduler.RunOnce(); logFile.GetSection(new LogFileSection(0, 2)).Should().Equal(new object[] { new LogLine(0, 0, "A", LevelFlags.Info), new LogLine(1, 0, "A continued", LevelFlags.Info) }, "because the log file should now represent the new content where both lines belong to the same entry"); }
public void Test2SmallSources() { using (var source0 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.File2Entries)) using (var source1 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.File2Lines)) using (var multi0 = new MultiLineLogFile(_scheduler, source0, TimeSpan.Zero)) using (var multi1 = new MultiLineLogFile(_scheduler, source1, TimeSpan.Zero)) using (var merged = new MergedLogFile(_scheduler, TimeSpan.Zero, multi0, multi1)) { source0.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(); source1.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(); multi0.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(); multi1.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(); merged.Property(x => x.Count).ShouldEventually().Be(8, TimeSpan.FromSeconds(5), "Because the merged file should've been finished"); merged.Property(x => x.GetValue(LogFileProperties.Size)).ShouldEventually().Be(source0.GetValue(LogFileProperties.Size) + source1.GetValue(LogFileProperties.Size)); merged.Property(x => x.GetValue(LogFileProperties.StartTimestamp)).ShouldEventually().Be(source1.GetValue(LogFileProperties.StartTimestamp)); LogLine[] source0Lines = multi0.GetSection(new LogFileSection(0, source0.Count)); LogLine[] source1Lines = multi1.GetSection(new LogFileSection(0, source1.Count)); LogLine[] mergedLines = merged.GetSection(new LogFileSection(0, merged.Count)); mergedLines[0].Should().Be(new LogLine(0, 0, new LogLineSourceId(1), source1Lines[0])); mergedLines[1].Should().Be(new LogLine(1, 1, new LogLineSourceId(0), source0Lines[0])); mergedLines[2].Should().Be(new LogLine(2, 1, new LogLineSourceId(0), source0Lines[1])); mergedLines[3].Should().Be(new LogLine(3, 1, new LogLineSourceId(0), source0Lines[2])); mergedLines[4].Should().Be(new LogLine(4, 2, new LogLineSourceId(1), source1Lines[1])); mergedLines[5].Should().Be(new LogLine(5, 3, new LogLineSourceId(0), source0Lines[3])); mergedLines[6].Should().Be(new LogLine(6, 3, new LogLineSourceId(0), source0Lines[4])); mergedLines[7].Should().Be(new LogLine(7, 3, new LogLineSourceId(0), source0Lines[5])); } }
public void TestManyEntries3() { var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero); _lines.AddRange(Enumerable.Range(0, 10001).Select(i => new LogLine(i, i, "", LevelFlags.Info))); _source.Setup(x => x.EndOfSourceReached).Returns(true); logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 10001)); _taskScheduler.RunOnce(); logFile.Count.Should().Be(10000, "because the log file should process a fixed amount of lines per tick"); logFile.EndOfSourceReached.Should().BeFalse("because the log file hasn't processed the entire source yet"); logFile.GetSection(new LogFileSection(0, 10000)) .Should().Equal(_lines.GetRange(0, 10000)); _taskScheduler.RunOnce(); logFile.Count.Should() .Be(10001, "because the log file should now have enough ticks elapsed to have processed the entire source"); logFile.EndOfSourceReached.Should().BeTrue("because the log file should've processed the entire source by now"); logFile.GetSection(new LogFileSection(0, 10001)) .Should().Equal(_lines); }
public void TestGetSection() { var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero); _lines.Add(new LogLine(0, 0, "A", LevelFlags.Debug)); _lines.Add(new LogLine(1, 1, "B", LevelFlags.Info)); _lines.Add(new LogLine(2, 2, "C", LevelFlags.Warning)); _lines.Add(new LogLine(3, 3, "D", LevelFlags.Error)); _lines.Add(new LogLine(4, 4, "E", LevelFlags.Fatal)); logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 5)); _taskScheduler.RunOnce(); logFile.GetSection(new LogFileSection(0, 5)).Should().Equal(new object[] { new LogLine(0, 0, "A", LevelFlags.Debug), new LogLine(1, 1, "B", LevelFlags.Info), new LogLine(2, 2, "C", LevelFlags.Warning), new LogLine(3, 3, "D", LevelFlags.Error), new LogLine(4, 4, "E", LevelFlags.Fatal) }); }