public void TestMerge6() { var source0 = new InMemoryLogFile(); var source1 = new InMemoryLogFile(); var merged = new MergedLogFile(_taskScheduler, TimeSpan.Zero, source0, source1); var data = Listen(merged); var changes = ListenToChanges(merged, 1); merged.OnLogFileModified(source0, LogFileSection.Reset); merged.OnLogFileModified(source0, LogFileSection.Reset); merged.OnLogFileModified(source0, LogFileSection.Reset); merged.OnLogFileModified(source0, LogFileSection.Reset); merged.OnLogFileModified(source0, LogFileSection.Reset); merged.OnLogFileModified(source0, LogFileSection.Reset); merged.OnLogFileModified(source1, LogFileSection.Reset); DateTime timestamp = DateTime.Now; source1.AddEntry("Hello World", LevelFlags.Info, timestamp); _taskScheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); data.Should().Equal(new object[] { new LogLine(0, 0, new LogLineSourceId(1), "Hello World", LevelFlags.Info, timestamp) }); int count = changes.Count; changes.ElementAt(count - 2).Should().Equal(LogFileSection.Reset); changes.ElementAt(count - 1).Should().Equal(new LogFileSection(0, 1)); }
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)); }
public void TestGetLineNumbersByIndices() { var source1 = new InMemoryLogFile(); source1.Add(new LogEntry2 { Timestamp = new DateTime(2017, 12, 20, 23, 1, 0) }); var source2 = new InMemoryLogFile(); source1.Add(new LogEntry2 { Timestamp = new DateTime(2017, 12, 20, 23, 0, 0) }); var logFile = new MergedLogFile(_taskScheduler, TimeSpan.Zero, source1, source2); _taskScheduler.RunOnce(); logFile.Count.Should().Be(2); var lineNumbers = logFile.GetColumn(new LogLineIndex[] { 1, 0 }, LogFileColumns.LineNumber); lineNumbers[0].Should().Be(2); lineNumbers[1].Should().Be(1); lineNumbers = logFile.GetColumn(new LogLineIndex[] { 1, 0 }, LogFileColumns.OriginalLineNumber); lineNumbers[0].Should().Be(2); lineNumbers[1].Should().Be(1); }
public void TestMerge5() { var source0 = new InMemoryLogFile(); var source1 = new InMemoryLogFile(); var merged = new MergedLogFile(_taskScheduler, TimeSpan.Zero, source0, source1); var data = Listen(merged); var later = new DateTime(2016, 2, 16); var earlier = new DateTime(2016, 2, 15); source0.AddEntry("a", LevelFlags.Warning, later); _taskScheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); source1.AddEntry("c", LevelFlags.Error, earlier); _taskScheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); merged.Count.Should().Be(2); data.Should().Equal(new object[] { new LogLine(0, 0, new LogLineSourceId(1), "c", LevelFlags.Error, earlier), new LogLine(1, 1, new LogLineSourceId(0), "a", LevelFlags.Warning, later) }); }
public void TestGetTimestampsOneSource2([Range(0, 3)] int offset) { var source = new InMemoryLogFile(); var logFile = new MergedLogFile(_taskScheduler, TimeSpan.Zero, source); source.AddEntry("", LevelFlags.Other, new DateTime(2017, 12, 14, 23, 27, 0)); source.AddEntry("", LevelFlags.Other, new DateTime(2017, 12, 14, 23, 28, 23)); source.AddEntry("", LevelFlags.Other, new DateTime(2017, 12, 14, 23, 29, 1)); int count = source.Count; _taskScheduler.Run(2); var buffer = new DateTime?[offset + count]; for (int i = 0; i < offset + count; ++i) { buffer[i] = DateTime.MinValue; } logFile.GetColumn(new LogLineIndex[] { 2, 1 }, LogFileColumns.Timestamp, buffer, offset); for (int i = 0; i < offset; ++i) { buffer[i].Should().Be(DateTime.MinValue, "because we've specified an offset and thus values before that offset shouldn't have been touched"); } buffer[offset + 0].Should().Be(source.GetLine(2).Timestamp); buffer[offset + 1].Should().Be(source.GetLine(1).Timestamp); }
public void TestMerge3() { var source0 = new InMemoryLogFile(); var source1 = new InMemoryLogFile(); var merged = new MergedLogFile(_taskScheduler, TimeSpan.Zero, source0, source1); var data = Listen(merged); DateTime timestamp = DateTime.Now; source0.AddEntry("a", LevelFlags.Info, timestamp); _taskScheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); source1.AddEntry("b", LevelFlags.Debug, timestamp); _taskScheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); merged.Count.Should().Be(2); data.Should().Equal(new object[] { new LogLine(0, 0, 0, new LogLineSourceId(0), "a", LevelFlags.Info, timestamp), new LogLine(1, 1, 1, new LogLineSourceId(1), "b", LevelFlags.Debug, timestamp) }); }
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 TestMerge3() { var source0 = new List <LogLine>(); Mock <ILogFile> logFile0 = CreateLogFile(source0); var source1 = new List <LogLine>(); Mock <ILogFile> logFile1 = CreateLogFile(source1); var merged = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), logFile0.Object, logFile1.Object); var data = Listen(merged); DateTime timestamp = DateTime.Now; source0.Add(new LogLine(0, "a", LevelFlags.Info, timestamp)); merged.OnLogFileModified(logFile0.Object, new LogFileSection(0, 1)); _taskScheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); source1.Add(new LogLine(1, "b", LevelFlags.Debug, timestamp)); merged.OnLogFileModified(logFile1.Object, new LogFileSection(0, 1)); _taskScheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); merged.Count.Should().Be(2); data.Should().Equal(new object[] { new LogLine(new LogLineSourceId(0), source0[0]), new LogLine(new LogLineSourceId(1), source1[0]) }); }
public void TestMerge6() { var source0 = new List <LogLine>(); Mock <ILogFile> logFile0 = CreateLogFile(source0); var source1 = new List <LogLine>(); DateTime timestamp = DateTime.Now; source1.Add(new LogLine(0, 0, "Hello World", LevelFlags.Info, timestamp)); Mock <ILogFile> logFile1 = CreateLogFile(source1); var merged = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), logFile0.Object, logFile1.Object); var data = Listen(merged); var changes = ListenToChanges(merged, 1); merged.OnLogFileModified(logFile0.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile0.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile0.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile0.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile0.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile0.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile1.Object, new LogFileSection(0, 1)); _taskScheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); data.Should().Equal(new LogLine(new LogLineSourceId(1), source1[0])); int count = changes.Count; changes.ElementAt(count - 2).Should().Equal(LogFileSection.Reset); changes.ElementAt(count - 1).Should().Equal(new LogFileSection(0, 1)); }
public void TestMerge5() { var source0 = new List <LogLine>(); Mock <ILogFile> logFile1 = CreateLogFile(source0); var source1 = new List <LogLine>(); Mock <ILogFile> logFile2 = CreateLogFile(source1); var merged = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), logFile1.Object, logFile2.Object); var data = Listen(merged); var later = new DateTime(2016, 2, 16); var earlier = new DateTime(2016, 2, 15); source0.Add(new LogLine(0, "a", LevelFlags.Warning, later)); merged.OnLogFileModified(logFile1.Object, new LogFileSection(0, 1)); _taskScheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); source1.Add(new LogLine(0, "c", LevelFlags.Error, earlier)); merged.OnLogFileModified(logFile2.Object, new LogFileSection(0, 1)); _taskScheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); merged.Count.Should().Be(2); data.Should().Equal(new object[] { new LogLine(0, 0, new LogLineSourceId(1), source1[0]), new LogLine(1, 1, new LogLineSourceId(0), source0[0]) }); }
public void Test2SmallSources() { using (var source1 = new LogFile(_scheduler, LogFileTest.File2Entries)) using (var source2 = new LogFile(_scheduler, LogFileTest.File2Lines)) using (var merged = new MergedLogFile(_scheduler, TimeSpan.Zero, source1, source2)) { source1.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(); source2.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.FileSize).ShouldEventually().Be(source1.FileSize + source2.FileSize); merged.Property(x => x.StartTimestamp).ShouldEventually().Be(source1.StartTimestamp); LogLine[] source1Lines = source1.GetSection(new LogFileSection(0, source1.Count)); LogLine[] source2Lines = source2.GetSection(new LogFileSection(0, source2.Count)); LogLine[] mergedLines = merged.GetSection(new LogFileSection(0, merged.Count)); mergedLines[0].Should().Be(new LogLine(0, 0, source1Lines[0])); mergedLines[1].Should().Be(new LogLine(1, 0, source1Lines[1])); mergedLines[2].Should().Be(new LogLine(2, 0, source1Lines[2])); mergedLines[3].Should().Be(new LogLine(3, 1, source2Lines[0])); mergedLines[4].Should().Be(new LogLine(4, 2, source1Lines[3])); mergedLines[5].Should().Be(new LogLine(5, 2, source1Lines[4])); mergedLines[6].Should().Be(new LogLine(6, 2, source1Lines[5])); mergedLines[7].Should().Be(new LogLine(7, 3, source2Lines[1])); } }
public void TestMergeMultiline4() { var source = new InMemoryLogFile(); var merged = new MergedLogFile(_taskScheduler, TimeSpan.Zero, source); source.AddMultilineEntry(LevelFlags.Other, new DateTime(2017, 12, 3, 11, 59, 30), new [] { "2017-12-03 11:59:30 Hello, ", "World!" }); _taskScheduler.RunOnce(); merged.Count.Should().Be(2); var entries = merged.GetEntries(new[] { new LogLineIndex(0), new LogLineIndex(1) }, new ILogFileColumn[] { LogFileColumns.LineNumber, LogFileColumns.LogEntryIndex, LogFileColumns.Timestamp, LogFileColumns.RawContent }); var line = entries[0]; line.GetValue(LogFileColumns.LineNumber).Should().Be(1); line.GetValue(LogFileColumns.LogEntryIndex).Should().Be(0); line.RawContent.Should().Be("2017-12-03 11:59:30 Hello, "); line = entries[1]; line.GetValue(LogFileColumns.LineNumber).Should().Be(2); line.GetValue(LogFileColumns.LogEntryIndex).Should().Be(0); line.RawContent.Should().Be("World!"); }
public void TestCtor2() { var sources = Enumerable.Range(0, LogLineSourceId.MaxSources) .Select(unused => new Mock <ILogFile>().Object).ToArray(); var logFile = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), sources); logFile.Sources.Should().Equal(sources); }
private void UpdateProxy() { var merged = new MergedLogFile(_taskScheduler, _maximumWaitTime, _logFiles); _logFile.InnerLogFile = merged; }
protected override ILogFile CreateFromContent(IReadOnlyLogEntries content) { var source = new InMemoryLogFile(content); var merged = new MergedLogFile(_taskScheduler, TimeSpan.Zero, source); _taskScheduler.RunOnce(); return(merged); }
public void TestDispose1() { var source1 = new Mock<ILogFile>(); var source2 = new Mock<ILogFile>(); var logFile = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), source1.Object, source2.Object); new Action(logFile.Dispose).ShouldNotThrow(); }
public void TestEndOfSourceReached1() { var source = new Mock<ILogFile>(); var logFile = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), source.Object); source.Verify(x => x.EndOfSourceReached, Times.Never); logFile.EndOfSourceReached.Should().BeFalse("because the original source hasn't reached its end"); source.Verify(x => x.EndOfSourceReached, Times.Once); }
public void TestEndOfSourceReached1() { var source = new Mock <ILogFile>(); var logFile = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), source.Object); source.Verify(x => x.EndOfSourceReached, Times.Never); logFile.EndOfSourceReached.Should().BeFalse("because the original source hasn't reached its end"); source.Verify(x => x.EndOfSourceReached, Times.Once); }
public void TestDispose1() { var source1 = new Mock <ILogFile>(); var source2 = new Mock <ILogFile>(); var logFile = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), source1.Object, source2.Object); new Action(logFile.Dispose).Should().NotThrow(); }
public void TestCtor1() { var source1 = new Mock<ILogFile>(); var source2 = new Mock<ILogFile>(); MergedLogFile logFile = null; new Action(() => logFile = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), source1.Object, source2.Object)) .ShouldNotThrow(); logFile.Should().NotBeNull(); }
public void TestCtor1() { var source1 = new Mock <ILogFile>(); var source2 = new Mock <ILogFile>(); MergedLogFile logFile = null; new Action(() => logFile = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), source1.Object, source2.Object)) .Should().NotThrow(); logFile.Should().NotBeNull(); }
public void TestDispose2() { var source1 = new Mock <ILogFile>(); var source2 = new Mock <ILogFile>(); var logFile = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), source1.Object, source2.Object); source1.Verify(x => x.AddListener(logFile, It.IsAny <TimeSpan>(), It.IsAny <int>()), Times.Once); source2.Verify(x => x.AddListener(logFile, It.IsAny <TimeSpan>(), It.IsAny <int>()), Times.Once); logFile.Dispose(); source1.Verify(x => x.RemoveListener(logFile), Times.Once, "because a merged log file is supposed to remove itself as a listener from its sources when its being disposed of"); source2.Verify(x => x.RemoveListener(logFile), Times.Once, "because a merged log file is supposed to remove itself as a listener from its sources when its being disposed of"); }
public void TestMerge1() { var source = new List<LogLine>(); Mock<ILogFile> source1 = CreateLogFile(source); var source2 = new Mock<ILogFile>(); source2.Setup(x => x.EndOfSourceReached).Returns(true); var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), source1.Object, source2.Object); IEnumerable<LogLine> data = Listen(merged); source.Add(new LogLine(0, 0, "foobar", LevelFlags.Info, DateTime.Now)); merged.OnLogFileModified(source1.Object, new LogFileSection(0, 1)); _scheduler.RunOnce(); merged.Count.Should().Be(1); data.Should().Equal(source); }
public void Test() { using (var source1 = new LogFile(_scheduler, LogFileTest.File2Entries)) using (var source2 = new LogFile(_scheduler, LogFileTest.File2Lines)) { var sources = new List<ILogFile> {source1, source2}; using (var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(10), sources)) { var filter = new SubstringFilter("foo", true); using (var filtered = new FilteredLogFile(_scheduler, TimeSpan.FromMilliseconds(10), merged, filter)) { filtered.Property(x => x.Count).ShouldEventually().Be(1, TimeSpan.FromSeconds(5)); } } } }
public void TestMerge1() { var source1 = new InMemoryLogFile(); var source2 = new InMemoryLogFile(); var merged = new MergedLogFile(_taskScheduler, TimeSpan.Zero, source1, source2); IEnumerable <LogLine> data = Listen(merged); source1.AddEntry("foobar", LevelFlags.Info, new DateTime(2019, 5, 28, 20, 31, 1)); _taskScheduler.RunOnce(); merged.Count.Should().Be(1); data.Should().Equal(new object[] { new LogLine(0, 0, "foobar", LevelFlags.Info, new DateTime(2019, 5, 28, 20, 31, 1)) }); }
public void TestMerge1() { var source = new List <LogLine>(); Mock <ILogFile> source1 = CreateLogFile(source); var source2 = new Mock <ILogFile>(); source2.Setup(x => x.EndOfSourceReached).Returns(true); var merged = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), source1.Object, source2.Object); IEnumerable <LogLine> data = Listen(merged); source.Add(new LogLine(0, 0, "foobar", LevelFlags.Info, DateTime.Now)); merged.OnLogFileModified(source1.Object, new LogFileSection(0, 1)); _taskScheduler.RunOnce(); merged.Count.Should().Be(1); data.Should().Equal(source); }
public void TestGetDeltaTimesOneSource2() { var source = new InMemoryLogFile(); var logFile = new MergedLogFile(_taskScheduler, TimeSpan.Zero, source); source.AddEntry("", LevelFlags.Other, new DateTime(2017, 12, 14, 23, 27, 0)); source.AddEntry("", LevelFlags.Other, new DateTime(2017, 12, 14, 23, 28, 23)); _taskScheduler.Run(2); var deltaTimes = logFile.GetColumn(new LogLineIndex[] { 1, 0 }, LogFileColumns.DeltaTime); deltaTimes.Should().Equal(new object[] { TimeSpan.FromSeconds(83), null }); }
public void Test() { using (var source1 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.File2Entries)) using (var source2 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.File2Lines)) { var sources = new List <ILogFile> { source1, source2 }; using (var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(10), sources)) { var filter = new SubstringFilter("foo", true); using (var filtered = new FilteredLogFile(_scheduler, TimeSpan.FromMilliseconds(10), merged, null, filter)) { filtered.Property(x => x.Count).ShouldEventually().Be(1, TimeSpan.FromSeconds(5)); } } } }
public void TestMerge4() { var source1 = new InMemoryLogFile(); var source2 = new InMemoryLogFile(); var merged = new MergedLogFile(_taskScheduler, TimeSpan.Zero, source1, source2); var data = Listen(merged); source1.AddEntry("a", LevelFlags.Warning, new DateTime(2019, 5, 28, 22, 40, 0)); source1.AddEntry("b", LevelFlags.Info); source1.AddEntry("c", LevelFlags.Error, new DateTime(2019, 5, 28, 22, 41, 0)); _taskScheduler.RunOnce(); merged.Count.Should().Be(2); data.Should().Equal(new object[] { new LogLine(0, 0, 0, "a", LevelFlags.Warning, new DateTime(2019, 5, 28, 22, 40, 0)), new LogLine(1, 1, 1, "c", LevelFlags.Error, new DateTime(2019, 5, 28, 22, 41, 0)) }); }
public void TestMerge4() { var source1Lines = new List <LogLine>(); Mock <ILogFile> source1 = CreateLogFile(source1Lines); var source2 = new Mock <ILogFile>(); source2.Setup(x => x.EndOfSourceReached).Returns(true); var merged = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), source1.Object, source2.Object); var data = Listen(merged); source1Lines.Add(new LogLine(0, "a", LevelFlags.Warning, DateTime.Now)); source1Lines.Add(new LogLine(1, "b", LevelFlags.Info)); source1Lines.Add(new LogLine(2, "c", LevelFlags.Error, DateTime.Now)); merged.OnLogFileModified(source1.Object, new LogFileSection(0, 3)); _taskScheduler.RunOnce(); merged.Count.Should().Be(2); data.Should().Equal(new LogLine(0, 0, new LogLineSourceId(0), source1Lines[0]), new LogLine(1, 1, new LogLineSourceId(0), source1Lines[2])); }
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) }); }
public void TestStart1() { var source = new Mock <ILogFile>(); var listeners = new List <Tuple <ILogFileListener, TimeSpan, int> >(); source.Setup(x => x.AddListener(It.IsAny <ILogFileListener>(), It.IsAny <TimeSpan>(), It.IsAny <int>())) .Callback( (ILogFileListener listener, TimeSpan maximumWaitTime, int maximumLineCount) => listeners.Add(Tuple.Create(listener, maximumWaitTime, maximumLineCount))); TimeSpan waitTime = TimeSpan.FromSeconds(1); var logFile = new MergedLogFile(_taskScheduler, TimeSpan.FromSeconds(1), source.Object); listeners.Count.Should() .Be(1, "Because the merged file should have registered exactly 1 listener with the source file"); listeners[0].Item1.Should().NotBeNull(); listeners[0].Item2.Should().Be(waitTime); listeners[0].Item3.Should().BeGreaterThan(0); GC.KeepAlive(logFile); }
private void UpdateUnfilteredLogFile() { _unfilteredLogFile?.Dispose(); OriginalSources = _dataSources.ToList(); IReadOnlyList <ILogFile> logFiles; if (IsSingleLine) { logFiles = OriginalSources.Select(x => x.OriginalLogFile).ToList(); } else { logFiles = OriginalSources.Select(x => x.UnfilteredLogFile).ToList(); } _unfilteredLogFile = new MergedLogFile(TaskScheduler, MaximumWaitTime, logFiles); OnUnfilteredLogFileChanged(); }
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) }); }
public void Test20Mb() { using (var source = new LogFile(_scheduler, LogFileTest.File20Mb)) using (var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), source)) { source.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(); merged.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(); merged.Count.Should().Be(source.Count); merged.FileSize.Should().Be(source.FileSize); merged.StartTimestamp.Should().Be(source.StartTimestamp); LogLine[] sourceLines = source.GetSection(new LogFileSection(0, source.Count)); LogLine[] mergedLines = merged.GetSection(new LogFileSection(0, merged.Count)); for (int i = 0; i < source.Count; ++i) { LogLine mergedLine = mergedLines[i]; LogLine sourceLine = sourceLines[i]; mergedLine.Should().Be(sourceLine); } } }
public void Test20Mb() { using (var source = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.File20Mb)) using (var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), source)) { source.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(); merged.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(); merged.Count.Should().Be(source.Count); merged.GetValue(LogFileProperties.Size).Should().Be(source.GetValue(LogFileProperties.Size)); merged.GetValue(LogFileProperties.StartTimestamp).Should().Be(source.GetValue(LogFileProperties.StartTimestamp)); LogLine[] sourceLines = source.GetSection(new LogFileSection(0, source.Count)); LogLine[] mergedLines = merged.GetSection(new LogFileSection(0, merged.Count)); for (int i = 0; i < source.Count; ++i) { LogLine mergedLine = mergedLines[i]; LogLine sourceLine = sourceLines[i]; mergedLine.Should().Be(sourceLine); } } }
public void TestMerge4() { var source = new List<LogLine>(); Mock<ILogFile> source1 = CreateLogFile(source); var source2 = new Mock<ILogFile>(); source2.Setup(x => x.EndOfSourceReached).Returns(true); var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), source1.Object, source2.Object); var data = Listen(merged); source.Add(new LogLine(0, "a", LevelFlags.Warning, DateTime.Now)); source.Add(new LogLine(1, "b", LevelFlags.Info)); source.Add(new LogLine(2, "c", LevelFlags.Error, DateTime.Now)); merged.OnLogFileModified(source1.Object, new LogFileSection(0, 3)); _scheduler.RunOnce(); merged.Count.Should().Be(2); data.Should().Equal(new[] { new LogLine(0, 0, source[0]), new LogLine(1, 1, source[2]) }); }
public void TestLive1And2() { using (var source1 = new LogFile(_scheduler, LogFileTest.FileTestLive1)) using (var source2 = new LogFile(_scheduler, LogFileTest.FileTestLive2)) using (var merged = new MergedLogFile(_scheduler, TimeSpan.Zero, source1, source2)) { merged.Property(x => x.Count).ShouldEventually().Be(19, TimeSpan.FromSeconds(5), "Because the merged file should've been finished"); merged.Property(x => x.FileSize).ShouldEventually().Be(source1.FileSize + source2.FileSize); merged.Property(x => x.StartTimestamp).ShouldEventually().Be(source1.StartTimestamp); LogLine[] mergedLines = merged.GetSection(new LogFileSection(0, merged.Count)); mergedLines[0].Should() .Be(new LogLine(0, 0, "2016-02-17 22:57:51,449 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Test.BusinessLogic.LogFileTest - Test", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 51, 449))); mergedLines[1].Should() .Be(new LogLine(1, 1, "2016-02-17 22:57:51,559 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Test.BusinessLogic.LogFileTest - Hello", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 51, 559))); mergedLines[2].Should() .Be(new LogLine(2, 2, "2016-02-17 22:57:51,560 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Test.BusinessLogic.LogFileTest - Hello", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 51, 560))); mergedLines[3].Should() .Be(new LogLine(3, 3, "2016-02-17 22:57:51,664 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Test.BusinessLogic.LogFileTest - world!", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 51, 664))); mergedLines[4].Should() .Be(new LogLine(4, 4, "2016-02-17 22:57:51,665 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Test.BusinessLogic.LogFileTest - world!", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 51, 665))); mergedLines[5].Should() .Be(new LogLine(5, 5, "2016-02-17 22:57:59,284 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 284))); mergedLines[6].Should() .Be(new LogLine(6, 6, "2016-02-17 22:57:59,284 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 284))); mergedLines[7].Should() .Be(new LogLine(7, 7, "2016-02-17 22:57:59,299 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 299))); mergedLines[8].Should() .Be(new LogLine(8, 8, "2016-02-17 22:57:59,299 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 299))); mergedLines[9].Should() .Be(new LogLine(9, 9, @"2016-02-17 22:57:59,302 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Settings.DataSource - Data Source 'E:\Code\Tailviewer\bin\Debug\TestClear1.log' doesn't have an ID yet, setting it to: b62ea0a3-c495-4f3f-b7c7-d1a0a66e361e", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 59, 302))); mergedLines[10].Should() .Be(new LogLine(10, 10, @"2016-02-17 22:57:59,303 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Settings.DataSource - Data Source 'E:\Code\Tailviewer\bin\Debug\TestClear1.log' doesn't have an ID yet, setting it to: b62ea0a3-c495-4f3f-b7c7-d1a0a66e361e", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 59, 303))); mergedLines[11].Should() .Be(new LogLine(11, 11, @"2016-02-17 22:57:59,304 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Settings.DataSource - Data Source 'E:\Code\Tailviewer\bin\Debug\TestClear2.log' doesn't have an ID yet, setting it to: 0ff1c032-0754-405f-8193-2fa4dbfb7d07", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 59, 304))); mergedLines[12].Should() .Be(new LogLine(12, 12, @"2016-02-17 22:57:59,305 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Settings.DataSource - Data Source 'E:\Code\Tailviewer\bin\Debug\TestClear2.log' doesn't have an ID yet, setting it to: 0ff1c032-0754-405f-8193-2fa4dbfb7d07", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 59, 305))); mergedLines[13].Should() .Be(new LogLine(13, 13, "2016-02-17 22:57:59,306 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 306))); mergedLines[14].Should() .Be(new LogLine(14, 14, "2016-02-17 22:57:59,307 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 307))); mergedLines[15].Should() .Be(new LogLine(15, 15, "2016-02-17 22:57:59,310 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 310))); mergedLines[16].Should() .Be(new LogLine(16, 16, "2016-02-17 22:57:59,311 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 311))); mergedLines[17].Should() .Be(new LogLine(17, 17, @"2016-02-17 22:57:59,863 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.BusinessLogic.DataSources - DataSource 'foo (ec976867-195b-4adf-a819-a1427f0d9aac)' is assigned a parent 'f671f235-7084-4e57-b06a-d253f750fae6' but we don't know that one", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 863))); mergedLines[18].Should() .Be(new LogLine(18, 18, @"2016-02-17 22:57:59,864 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.BusinessLogic.DataSources - DataSource 'foo (ec976867-195b-4adf-a819-a1427f0d9aac)' is assigned a parent 'f671f235-7084-4e57-b06a-d253f750fae6' but we don't know that one", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 864))); } }
public void TestMerge3() { var source1 = new List<LogLine>(); Mock<ILogFile> logFile1 = CreateLogFile(source1); var source2 = new List<LogLine>(); Mock<ILogFile> logFile2 = CreateLogFile(source2); var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), logFile1.Object, logFile2.Object); var data = Listen(merged); DateTime timestamp = DateTime.Now; source1.Add(new LogLine(0, "a", LevelFlags.Info, timestamp)); merged.OnLogFileModified(logFile1.Object, new LogFileSection(0, 1)); _scheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); source2.Add(new LogLine(1, "b", LevelFlags.Debug, timestamp)); merged.OnLogFileModified(logFile2.Object, new LogFileSection(0, 1)); _scheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); merged.Count.Should().Be(2); data.Should().Equal(new object[] {source1[0], source2[0]}); }
public void TestLive1And2() { using (var source0 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.FileTestLive1)) using (var source1 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.FileTestLive2)) using (var merged = new MergedLogFile(_scheduler, TimeSpan.Zero, source0, source1)) { merged.Property(x => x.Count).ShouldEventually().Be(19, 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(source0.GetValue(LogFileProperties.StartTimestamp)); LogLine[] mergedLines = merged.GetSection(new LogFileSection(0, merged.Count)); mergedLines[0].Should() .Be(new LogLine(0, 0, "2016-02-17 22:57:51,449 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Test.BusinessLogic.LogFileTest - Test", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 51, 449))); mergedLines[1].Should() .Be(new LogLine(1, 1, "2016-02-17 22:57:51,559 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Test.BusinessLogic.LogFileTest - Hello", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 51, 559))); mergedLines[2].Should() .Be(new LogLine(2, 2, 2, new LogLineSourceId(1), "2016-02-17 22:57:51,560 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Test.BusinessLogic.LogFileTest - Hello", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 51, 560))); mergedLines[3].Should() .Be(new LogLine(3, 3, "2016-02-17 22:57:51,664 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Test.BusinessLogic.LogFileTest - world!", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 51, 664))); mergedLines[4].Should() .Be(new LogLine(4, 4, 4, new LogLineSourceId(1), "2016-02-17 22:57:51,665 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Test.BusinessLogic.LogFileTest - world!", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 51, 665))); mergedLines[5].Should() .Be(new LogLine(5, 5, "2016-02-17 22:57:59,284 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 284))); mergedLines[6].Should() .Be(new LogLine(6, 6, 6, new LogLineSourceId(1), "2016-02-17 22:57:59,285 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 285))); mergedLines[7].Should() .Be(new LogLine(7, 7, "2016-02-17 22:57:59,298 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 298))); mergedLines[8].Should() .Be(new LogLine(8, 8, 8, new LogLineSourceId(1), "2016-02-17 22:57:59,299 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 299))); mergedLines[9].Should() .Be(new LogLine(9, 9, @"2016-02-17 22:57:59,302 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Settings.DataSource - Data Source 'E:\Code\Tailviewer\bin\Debug\TestClear1.log' doesn't have an ID yet, setting it to: b62ea0a3-c495-4f3f-b7c7-d1a0a66e361e", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 59, 302))); mergedLines[10].Should() .Be(new LogLine(10, 10, 10, new LogLineSourceId(1), @"2016-02-17 22:57:59,303 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Settings.DataSource - Data Source 'E:\Code\Tailviewer\bin\Debug\TestClear1.log' doesn't have an ID yet, setting it to: b62ea0a3-c495-4f3f-b7c7-d1a0a66e361e", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 59, 303))); mergedLines[11].Should() .Be(new LogLine(11, 11, @"2016-02-17 22:57:59,304 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Settings.DataSource - Data Source 'E:\Code\Tailviewer\bin\Debug\TestClear2.log' doesn't have an ID yet, setting it to: 0ff1c032-0754-405f-8193-2fa4dbfb7d07", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 59, 304))); mergedLines[12].Should() .Be(new LogLine(12, 12, 12, new LogLineSourceId(1), @"2016-02-17 22:57:59,305 [CurrentAppDomainHost.ExecuteNodes] INFO Tailviewer.Settings.DataSource - Data Source 'E:\Code\Tailviewer\bin\Debug\TestClear2.log' doesn't have an ID yet, setting it to: 0ff1c032-0754-405f-8193-2fa4dbfb7d07", LevelFlags.Info, new DateTime(2016, 2, 17, 22, 57, 59, 305))); mergedLines[13].Should() .Be(new LogLine(13, 13, "2016-02-17 22:57:59,306 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 306))); mergedLines[14].Should() .Be(new LogLine(14, 14, 14, new LogLineSourceId(1), "2016-02-17 22:57:59,307 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 307))); mergedLines[15].Should() .Be(new LogLine(15, 15, 15, new LogLineSourceId(1), "2016-02-17 22:57:59,310 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 310))); mergedLines[16].Should() .Be(new LogLine(16, 16, "2016-02-17 22:57:59,311 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.Settings.DataSources - Selected item '00000000-0000-0000-0000-000000000000' not found in data-sources, ignoring it...", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 311))); mergedLines[17].Should() .Be(new LogLine(17, 17, @"2016-02-17 22:57:59,863 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.BusinessLogic.DataSources - DataSource 'foo (ec976867-195b-4adf-a819-a1427f0d9aac)' is assigned a parent 'f671f235-7084-4e57-b06a-d253f750fae6' but we don't know that one", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 863))); mergedLines[18].Should() .Be(new LogLine(18, 18, 18, new LogLineSourceId(1), @"2016-02-17 22:57:59,864 [CurrentAppDomainHost.ExecuteNodes] WARN Tailviewer.BusinessLogic.DataSources - DataSource 'foo (ec976867-195b-4adf-a819-a1427f0d9aac)' is assigned a parent 'f671f235-7084-4e57-b06a-d253f750fae6' but we don't know that one", LevelFlags.Warning, new DateTime(2016, 2, 17, 22, 57, 59, 864))); } }
public void TestMerge5() { var source1 = new List<LogLine>(); Mock<ILogFile> logFile1 = CreateLogFile(source1); var source2 = new List<LogLine>(); Mock<ILogFile> logFile2 = CreateLogFile(source2); var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), logFile1.Object, logFile2.Object); var data = Listen(merged); var later = new DateTime(2016, 2, 16); var earlier = new DateTime(2016, 2, 15); source1.Add(new LogLine(0, "a", LevelFlags.Warning, later)); merged.OnLogFileModified(logFile1.Object, new LogFileSection(0, 1)); _scheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); source2.Add(new LogLine(0, "c", LevelFlags.Error, earlier)); merged.OnLogFileModified(logFile2.Object, new LogFileSection(0, 1)); _scheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); merged.Count.Should().Be(2); data.Should().Equal(new object[] { new LogLine(0, 0, source2[0]), new LogLine(1, 1, source1[0]) }); }
public void TestMerge6() { var source1 = new List<LogLine>(); Mock<ILogFile> logFile1 = CreateLogFile(source1); var source2 = new List<LogLine>(); DateTime timestamp = DateTime.Now; source2.Add(new LogLine(0, 0, "Hello World", LevelFlags.Info, timestamp)); Mock<ILogFile> logFile2 = CreateLogFile(source2); var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), logFile1.Object, logFile2.Object); var data = Listen(merged); var changes = ListenToChanges(merged); merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile2.Object, LogFileSection.Reset); merged.OnLogFileModified(logFile2.Object, new LogFileSection(0, 1)); _scheduler.RunOnce(); merged.EndOfSourceReached.Should().BeTrue(); data.Should().Equal(source2); int count = changes.Count; changes.ElementAt(count - 2).Should().Be(LogFileSection.Reset); changes.ElementAt(count - 1).Should().Be(new LogFileSection(0, 1)); }
public void TestStart1() { var source = new Mock<ILogFile>(); var listeners = new List<Tuple<ILogFileListener, TimeSpan, int>>(); source.Setup(x => x.AddListener(It.IsAny<ILogFileListener>(), It.IsAny<TimeSpan>(), It.IsAny<int>())) .Callback( (ILogFileListener listener, TimeSpan maximumWaitTime, int maximumLineCount) => listeners.Add(Tuple.Create(listener, maximumWaitTime, maximumLineCount))); TimeSpan waitTime = TimeSpan.FromSeconds(1); var logFile = new MergedLogFile(_scheduler, TimeSpan.FromSeconds(1), source.Object); listeners.Count.Should() .Be(1, "Because the merged file should have registered exactly 1 listener with the source file"); listeners[0].Item1.Should().NotBeNull(); listeners[0].Item2.Should().Be(waitTime); listeners[0].Item3.Should().BeGreaterThan(0); }