public void TestGetTimestampsOneSource1([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)); 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 LogFileSection(0, count), 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"); } for (int i = 0; i < count; ++i) { buffer[offset + i].Should().Be(source.GetLine(i).Timestamp); } }
public void TestFileDoesNotExist([Values(1, 2, 3)] int numReadOperations) { var logFile = Create(GetUniqueNonExistingFileName(), Encoding.Default); _taskScheduler.Run(numReadOperations); logFile.GetProperty(TextProperties.LineCount).Should().Be(0); logFile.GetProperty(Properties.LogEntryCount).Should().Be(0); logFile.GetProperty(Properties.Size).Should().BeNull("because the source file does not exist"); logFile.GetProperty(Properties.Created).Should().BeNull("because the source file does not exist"); logFile.GetProperty(Properties.LastModified).Should().BeNull("because the source file does not exist"); logFile.GetProperty(Properties.EmptyReason).Should().BeOfType <SourceDoesNotExist>("because the source file does not exist"); logFile.GetProperty(Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent, "because we've checked that the source doesn't exist and thus there's nothing more to process"); }
public void TestSearch1() { var logFile = new InMemoryLogSource(); using (var dataSource = new FileDataSource(_scheduler, CreateDataSource(), logFile, TimeSpan.Zero)) { logFile.AddEntry("Hello foobar world!"); _scheduler.RunOnce(); dataSource.SearchTerm = "foobar"; _scheduler.Run(10); dataSource.Search.Count.Should().Be(1); var matches = dataSource.Search.Matches.ToList(); matches.Should().Equal(new LogMatch(0, new LogLineMatch(6, 6))); } }
public void TestWrite1([Values(true, false)] bool isSingleLine) { _settings.IsSingleLine = isSingleLine; using (var dataSource = new SingleDataSource(_scheduler, _settings, _logFile, TimeSpan.Zero)) { _writer.Write("ssss"); _writer.Flush(); _scheduler.Run(2); dataSource.FilteredLogFile.Count.Should().Be(1); dataSource.FilteredLogFile.GetLine(0).Should().Be(new LogLine(0, 0, "ssss", LevelFlags.Other)); } }
public void TestLevelCount1() { using (var dataSource = new SingleDataSource(_logFileFactory, _scheduler, new DataSource(@"TestData\LevelCounts.txt") { Id = DataSourceId.CreateNew() })) { _scheduler.Run(2); dataSource.UnfilteredLogFile.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(); dataSource.TotalCount.Should().Be(27, "because the data source contains that many lines"); dataSource.DebugCount.Should().Be(1, "because the data source contains one debug line"); dataSource.InfoCount.Should().Be(2, "because the data source contains two info lines"); dataSource.WarningCount.Should().Be(3, "because the data source contains three warnings"); dataSource.ErrorCount.Should().Be(4, "because the data source contains four errors"); dataSource.FatalCount.Should().Be(5, "because the data source contains five fatal lines"); dataSource.TraceCount.Should().Be(6, "because the data source contains six trace lines"); dataSource.NoLevelCount.Should().Be(0, "because all non-matching lines are assumed to belong to the previous line"); } }
public void TestWrite1([Values(true, false)] bool isSingleLine) { _settings.IsSingleLine = isSingleLine; using (var dataSource = new FileDataSource(_scheduler, _settings, _logSource, TimeSpan.Zero)) { _writer.Write("ssss"); _writer.Flush(); _scheduler.Run(3); dataSource.FilteredLogSource.GetProperty(Properties.LogEntryCount).Should().Be(1); var line = dataSource.FilteredLogSource.GetEntry(0); line.Index.Should().Be(0); line.LogEntryIndex.Should().Be(0); line.RawContent.Should().Be("ssss"); line.LogLevel.Should().Be(LevelFlags.Other); } }
public void TestFileCannotBeAccessed() { var fileName = GetUniqueNonExistingFileName(); using (new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) { var source = Create(fileName); _taskScheduler.Run(5); source.GetProperty(Properties.EmptyReason).Should().BeOfType <SourceCannotBeAccessed>(); source.GetProperty(Properties.Created).Should().NotBe(DateTime.MinValue); source.GetProperty(Properties.Created).Should().Be(new FileInfo(fileName).CreationTimeUtc); } }
public void TestMergeMultiline1() { var logFile1 = new InMemoryLogFile(); var source1Id = new LogLineSourceId(0); var source1 = new SingleDataSource(_taskScheduler, new DataSource { Id = DataSourceId.CreateNew() }, logFile1, TimeSpan.Zero); var logFile2 = new InMemoryLogFile(); var source2Id = new LogLineSourceId(1); var source2 = new SingleDataSource(_taskScheduler, new DataSource { Id = DataSourceId.CreateNew() }, logFile2, TimeSpan.Zero); _merged.IsSingleLine = false; _merged.Add(source1); _merged.Add(source2); var t1 = new DateTime(2017, 11, 26, 14, 26, 0); logFile1.AddEntry("Hello, World!", LevelFlags.Info, t1); var t2 = new DateTime(2017, 11, 26, 14, 27, 0); logFile2.AddEntry("foo", LevelFlags.Trace, t2); logFile2.AddEntry("bar", LevelFlags.None); var t3 = new DateTime(2017, 11, 26, 14, 28, 0); logFile1.AddEntry("Houston, we have a problem", LevelFlags.Warning, t3); _taskScheduler.Run(4); //< There's a few proxies involved and thus one round won't do it _merged.FilteredLogFile.Count.Should().Be(4, "because there are four lines in total, each of which has a timestamp"); _merged.FilteredLogFile.GetLine(0).Should().Be(new LogLine(0, 0, source1Id, "Hello, World!", LevelFlags.Info, t1)); _merged.FilteredLogFile.GetLine(1).Should().Be(new LogLine(1, 1, source2Id, "foo", LevelFlags.Trace, t2)); _merged.FilteredLogFile.GetLine(2).Should().Be(new LogLine(2, 1, source2Id, "bar", LevelFlags.Trace, t2)); _merged.FilteredLogFile.GetLine(3).Should().Be(new LogLine(3, 2, source1Id, "Houston, we have a problem", LevelFlags.Warning, t3)); }
public void TestMergeMultiline1() { var logFile1 = new InMemoryLogSource(); var source1Id = new LogEntrySourceId(0); var source1 = new FileDataSource(_taskScheduler, new DataSource { Id = DataSourceId.CreateNew() }, logFile1, TimeSpan.Zero); var logFile2 = new InMemoryLogSource(); var source2Id = new LogEntrySourceId(1); var source2 = new FileDataSource(_taskScheduler, new DataSource { Id = DataSourceId.CreateNew() }, logFile2, TimeSpan.Zero); _merged.IsSingleLine = false; _merged.Add(source1); _merged.Add(source2); var t1 = new DateTime(2017, 11, 26, 14, 26, 0); logFile1.AddEntry("Hello, World!", LevelFlags.Info, t1); var t2 = new DateTime(2017, 11, 26, 14, 27, 0); logFile2.AddEntry("foo", LevelFlags.Trace, t2); logFile2.AddEntry("bar", LevelFlags.Other); var t3 = new DateTime(2017, 11, 26, 14, 28, 0); logFile1.AddEntry("Houston, we have a problem", LevelFlags.Warning, t3); _taskScheduler.Run(4); //< There's a few proxies involved and thus one round won't do it var entries = _merged.FilteredLogSource.GetEntries(new LogSourceSection(0, 4)); entries[0].Index.Should().Be(0); entries[0].LogEntryIndex.Should().Be(0); entries[0].GetValue(Columns.SourceId).Should().Be(source1Id); entries[0].RawContent.Should().Be("Hello, World!"); entries[0].LogLevel.Should().Be(LevelFlags.Info); entries[0].Timestamp.Should().Be(t1); entries[1].Index.Should().Be(1); entries[1].LogEntryIndex.Should().Be(1); entries[1].GetValue(Columns.SourceId).Should().Be(source2Id); entries[1].RawContent.Should().Be("foo"); entries[1].LogLevel.Should().Be(LevelFlags.Trace); entries[1].Timestamp.Should().Be(t2); entries[2].Index.Should().Be(2); entries[2].LogEntryIndex.Should().Be(1); entries[2].GetValue(Columns.SourceId).Should().Be(source2Id); entries[2].RawContent.Should().Be("bar"); entries[2].LogLevel.Should().Be(LevelFlags.Trace); entries[2].Timestamp.Should().Be(t2); entries[3].Index.Should().Be(3); entries[3].LogEntryIndex.Should().Be(2); entries[3].GetValue(Columns.SourceId).Should().Be(source1Id); entries[3].RawContent.Should().Be("Houston, we have a problem"); entries[3].LogLevel.Should().Be(LevelFlags.Warning); entries[3].Timestamp.Should().Be(t3); }