Пример #1
0
        public void TestPercentageProcessed()
        {
            var source           = new Mock <ILogSource>();
            var sourceProperties = new PropertiesBufferList();

            sourceProperties.SetValue(Core.Properties.PercentageProcessed, Percentage.Zero);
            source.Setup(x => x.Columns).Returns(Core.Columns.Minimum);
            source.Setup(x => x.GetAllProperties(It.IsAny <IPropertiesBuffer>()))
            .Callback((IPropertiesBuffer destination) => sourceProperties.CopyAllValuesTo(destination));
            source.Setup(x => x.GetProperty(Core.Properties.PercentageProcessed))
            .Returns(() => sourceProperties.GetValue(Core.Properties.PercentageProcessed));
            source.Setup(x => x.Properties).Returns(() => sourceProperties.Properties);

            using (var file = Create(source.Object))
            {
                var fileListener = (ILogSourceListener)file;

                file.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.Zero, "because the filtered log file hasn't consumed anything of its source (yet)");

                _taskScheduler.RunOnce();
                file.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.Zero, "because even though the filter doesn't have anything to do just yet - it's because its own source hasn't even started");

                sourceProperties.SetValue(Core.Properties.PercentageProcessed, Percentage.FromPercent(42));
                fileListener.OnLogFileModified(source.Object, LogSourceModification.Appended(0, 84));
                _taskScheduler.RunOnce();
                file.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.FromPercent(42), "because now the filtered log file has processed 100% of the data the source sent it, but the original data source is still only at 42%");

                sourceProperties.SetValue(Core.Properties.PercentageProcessed, Percentage.HundredPercent);
                fileListener.OnLogFileModified(source.Object, LogSourceModification.Appended(84, 200));
                _taskScheduler.RunOnce();
                file.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent);
            }
        }
Пример #2
0
        public void TestEmptyFile()
        {
            var index = new PresentationLogFile(_scheduler, new InMemoryLogFile());

            _scheduler.RunOnce();
            index.MaximumWidth.Should().Be(0);
            index.LineCount.Should().Be(0);
        }
Пример #3
0
        public void TestEmptyFile()
        {
            var index = new PresentationLogSource(_scheduler, new InMemoryLogSource(), TextSettings.Default);

            _scheduler.RunOnce();
            index.MaximumWidth.Should().Be(0);
            index.LineCount.Should().Be(0);
        }
        public void TestAnalyseEmpty()
        {
            var analyser = new LogEntryCountAnalyser(_scheduler,
                                                     _logFile,
                                                     TimeSpan.Zero,
                                                     new LogEntryCountAnalyserConfiguration());

            _scheduler.RunOnce();
            analyser.Result.Should().NotBeNull();
            analyser.Result.Should().BeOfType <LogEntryCountResult>();
            ((LogEntryCountResult)analyser.Result).Count.Should().Be(0);
        }
Пример #5
0
        public void TestNoSuchFolder()
        {
            var dataSource = new FolderDataSource(_taskScheduler,
                                                  _logFileFactory,
                                                  _filesystem,
                                                  _settings,
                                                  TimeSpan.Zero);
            var path = Path.Combine(_filesystem.Roots.First().FullName, "logs");

            dataSource.Change(path, "*", false);

            _taskScheduler.RunOnce();
            dataSource.OriginalSources.Should().BeEmpty();
        }
Пример #6
0
        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)));
            }
        }
Пример #7
0
        public void TestLevelPrecedence()
        {
            var settings = new DataSource(@"TestData\DifferentLevels.txt")
            {
                Id = DataSourceId.CreateNew()
            };

            using (var dataSource = new SingleDataSource(_logFileFactory, _scheduler, settings))
            {
                dataSource.FilteredLogFile.Property(x =>
                {
                    _scheduler.RunOnce();
                    return(x.Count >= 6);
                }).ShouldEventually().BeTrue();
                dataSource.FilteredLogFile.Count.Should().Be(6, "because the file consists of 6 lines");

                LogLine[] lines = dataSource.FilteredLogFile.GetSection(new LogFileSection(0, 6));
                lines[0].Message.Should().Be("DEBUG ERROR WARN FATAL INFO");
                lines[0].Level.Should().Be(LevelFlags.Debug, "Because DEBUG is the first level to appear in the line");

                lines[1].Message.Should().Be("INFO DEBUG ERROR WARN FATAL");
                lines[1].Level.Should().Be(LevelFlags.Info, "Because INFO is the first level to appear in the line");

                lines[2].Message.Should().Be("WARN ERROR FATAL INFO DEBUG");
                lines[2].Level.Should().Be(LevelFlags.Warning, "Because WARN is the first level to appear in the line");

                lines[3].Message.Should().Be("ERROR INFO DEBUG FATAL WARN");
                lines[3].Level.Should().Be(LevelFlags.Error, "Because ERROR is the first level to appear in the line");

                lines[4].Message.Should().Be("FATAL ERROR INFO WARN DEBUG");
                lines[4].Level.Should().Be(LevelFlags.Fatal, "Because FATAL is the first level to appear in the line");

                lines[5].Message.Should().Be("fatal error info warn debug");
                lines[5].Level.Should()
                .Be(LevelFlags.Fatal,
                    "Because this line belongs to the previous log entry and thus is marked as fatal as well");
                lines[5].LogEntryIndex.Should().Be(lines[4].LogEntryIndex);

                _scheduler.RunOnce();

                dataSource.DebugCount.Should().Be(1);
                dataSource.InfoCount.Should().Be(1);
                dataSource.WarningCount.Should().Be(1);
                dataSource.ErrorCount.Should().Be(1);
                dataSource.FatalCount.Should().Be(1);
                dataSource.NoLevelCount.Should().Be(0);
            }
        }
Пример #8
0
        private ILogSource Create(string fileName)
        {
            var fileLogSource = new FileLogSource(_services, fileName, TimeSpan.Zero);

            _taskScheduler.RunOnce();
            return(fileLogSource);
        }
Пример #9
0
        public void TestCtor2()
        {
            Add("Hello World!");
            using (var search = new LogFileSearch(_scheduler, _logFile.Object, "l"))
            {
                _scheduler.RunOnce();

                search.Count.Should().Be(3);
                var matches = search.Matches.ToList();
                matches.Should().Equal(new[]
                {
                    new LogMatch(0, new LogLineMatch(2, 1)),
                    new LogMatch(0, new LogLineMatch(3, 1)),
                    new LogMatch(0, new LogLineMatch(9, 1))
                });
            }
        }
Пример #10
0
        public void TestPrefetchAsync([Values(10, 100, 1000)] int pageSize)
        {
            var buffer       = new PageBufferedLogSource(_taskScheduler, _source.Object, TimeSpan.Zero, pageSize: pageSize);
            var destination  = new LogBufferArray(4, new IColumnDescriptor[] { Core.Columns.Index, Core.Columns.RawContent });
            var queryOptions = new LogSourceQueryOptions(LogSourceQueryMode.FromCache | LogSourceQueryMode.FetchForLater);

            buffer.OnLogFileModified(_source.Object, LogSourceModification.Appended(0, 10));

            var sectionToQuery = new LogSourceSection(2, 4);

            buffer.GetEntries(sectionToQuery, destination, 0, queryOptions);
            _source.Verify(x => x.GetEntries(It.IsAny <IReadOnlyList <LogLineIndex> >(), It.IsAny <ILogBuffer>(), It.IsAny <int>(), It.IsAny <LogSourceQueryOptions>()),
                           Times.Never, "Because we didn't allow data to be retrieved on the calling thread");

            _taskScheduler.RunOnce();
            _source.Verify(x => x.GetEntries(new LogSourceSection(0, pageSize), It.IsAny <ILogBuffer>(), It.IsAny <int>(), It.IsAny <LogSourceQueryOptions>()),
                           Times.Once, "Because the buffer should have tried to retrieve the page for the entire page which was accessed");
        }
Пример #11
0
        public void TestListen1()
        {
            using (var proxy = new LogFileProxy(_scheduler, TimeSpan.Zero, _logFile.Object))
            {
                proxy.AddListener(_listener.Object, TimeSpan.Zero, 1000);

                _listeners.OnRead(500);
                _listeners.OnRead(600);

                _scheduler.RunOnce();

                _modifications.Should().Equal(new[]
                {
                    LogFileSection.Reset,
                    new LogFileSection(0, 500),
                    new LogFileSection(500, 100)
                });
            }
        }
Пример #12
0
        public void TestPercentageProcessedEmpty()
        {
            using (var logFile = CreateEmpty())
            {
                logFile.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.Zero, "because the log file didn't have enough time to check the source");

                _taskScheduler.RunOnce();

                logFile.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent, "because we've checked that the source doesn't exist and thus there's nothing more to process");
            }
        }
Пример #13
0
 public void TestSearch1()
 {
     using (var dataSource = new SingleDataSource(_scheduler, CreateDataSource(), _logFile.Object, TimeSpan.Zero))
     {
         _entries.Add(new LogLine(0, 0, "Hello foobar world!", LevelFlags.None));
         _listeners.OnRead(1);
         _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)));
     }
 }
Пример #14
0
        public void TestDispose()
        {
            var logFile = new InMemoryLogSource();

            logFile.AddEntry("What's a foobar?");
            LogSourceSearch search;

            using (search = new LogSourceSearch(_scheduler, logFile, "foobar", TimeSpan.Zero))
            {
                search.IsDisposed.Should().BeFalse();
                _scheduler.PeriodicTaskCount.Should().Be(1);

                _scheduler.RunOnce();
                search.Count.Should().Be(1);
            }

            search.IsDisposed.Should().BeTrue();
            search.Count.Should().Be(0);
            _scheduler.PeriodicTaskCount.Should().Be(0);
        }
        public void TestOneEntry1()
        {
            var settings = new EventsLogAnalyserConfiguration
            {
                Events =
                {
                    new EventConfiguration {
                        FilterExpression = @"Found (\d+) thing(s)"
                    }
                }
            };

            _source.AddEntry("Found 42 things", LevelFlags.None);

            using (var analyser = new EventsLogAnalyser(_scheduler,
                                                        _source,
                                                        TimeSpan.Zero,
                                                        settings
                                                        ))
            {
                _scheduler.RunOnce();
                analyser.Events.Count.Should().Be(1);
            }
        }
Пример #16
0
        public void TestCustomColumn()
        {
            var myCustomColumn = CreateCustomColumn <string>(null);
            var source1        = new InMemoryLogSource();

            source1.Add(new LogEntry
            {
                RawContent = "What is up Munich?",
                Timestamp  = new DateTime(2021, 02, 11, 22, 16, 49)
            });
            var source2 = new InMemoryLogSource(myCustomColumn);
            var entry2  = new LogEntry
            {
                RawContent = "Everything",
                Timestamp  = new DateTime(2021, 02, 11, 22, 15, 11)
            };

            entry2.SetValue(myCustomColumn, "A very important piece of information");
            source2.Add(entry2);

            var merged = new MergedLogSource(_taskScheduler, TimeSpan.Zero, new[] { source1, source2 });

            _taskScheduler.RunOnce();

            merged.GetProperty(Core.Properties.LogEntryCount).Should().Be(2);
            var entries = merged.GetEntries(new LogSourceSection(0, 2), new IColumnDescriptor[] { Core.Columns.RawContent, Core.Columns.Timestamp, Core.Columns.SourceId, myCustomColumn });

            entries.Count.Should().Be(2);
            entries[0].RawContent.Should().Be("Everything");
            entries[0].Timestamp.Should().Be(new DateTime(2021, 02, 11, 22, 15, 11));
            entries[0].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(1), "because this log entry is from the second source of the log file");
            entries[0].GetValue(myCustomColumn).Should().Be("A very important piece of information");
            entries[1].RawContent.Should().Be("What is up Munich?");
            entries[1].Timestamp.Should().Be(new DateTime(2021, 02, 11, 22, 16, 49));
            entries[1].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(0), "because this log entry is from the first source of the log file");
            entries[1].GetValue(myCustomColumn).Should().Be(myCustomColumn.DefaultValue, "because the first source doesn't have this column");
        }
Пример #17
0
        public void TestCtor3()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _source.Setup(x => x.EndOfSourceReached).Returns(true);
            logFile.EndOfSourceReached.Should().BeFalse("because the log file shouldn't even have inspected the source yet");

            _taskScheduler.RunOnce();

            logFile.EndOfSourceReached.Should().BeTrue();
        }
Пример #18
0
        public void TestExists()
        {
            using (var proxy = new LogSourceProxy(_taskScheduler, TimeSpan.Zero, _logFile.Object))
            {
                _logFile.Setup(x => x.GetAllProperties(It.IsAny <IPropertiesBuffer>()))
                .Callback((IPropertiesBuffer destination) =>
                {
                    destination.SetValue(Core.Properties.EmptyReason, null);
                });
                _taskScheduler.RunOnce();
                proxy.GetProperty(Core.Properties.EmptyReason).Should().Be(null);

                var emptyReason = new Mock <IEmptyReason>();
                _logFile.Setup(x => x.GetAllProperties(It.IsAny <IPropertiesBuffer>()))
                .Callback((IPropertiesBuffer destination) =>
                {
                    destination.SetValue(Core.Properties.EmptyReason, emptyReason.Object);
                });
                _taskScheduler.RunOnce();
                proxy.GetProperty(Core.Properties.EmptyReason).Should().Be(emptyReason.Object);
            }
        }
Пример #19
0
        public void TestEndOfSourceReached1()
        {
            _logFile.Setup(x => x.EndOfSourceReached).Returns(false);

            using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create(null, true, LevelFlags.Debug)))
            {
                file.EndOfSourceReached.Should().BeFalse("because the filtered log file hasn't even inspected the source yet");

                _taskScheduler.RunOnce();
                file.EndOfSourceReached.Should().BeFalse("because the source isn't at its own end yet");

                _logFile.Setup(x => x.EndOfSourceReached).Returns(true);
                file.EndOfSourceReached.Should().BeFalse("because the filtered log file hasn't processed the latest changes to the source yet");

                _taskScheduler.RunOnce();
                file.EndOfSourceReached.Should().BeTrue("because the source is finished and the filtered log file has processed all changes from the source");
            }
        }
Пример #20
0
        public void TestConstruction()
        {
            _source.Columns.Should().Equal(new IColumnDescriptor[]
            {
                Columns.Index,
                Columns.OriginalIndex,
                Columns.LogEntryIndex,
                Columns.LineNumber,
                Columns.OriginalLineNumber,
                Columns.OriginalDataSourceName,
                Columns.RawContent,
                PageBufferedLogSource.RetrievalState
            });

            _streamWriter.Write("Foo");
            _streamWriter.Flush();

            var info = new FileInfo(_fname);

            _taskScheduler.RunOnce();

            _source.GetProperty(Properties.LastModified).Should().Be(info.LastWriteTimeUtc);
            _source.GetProperty(Properties.Created).Should().Be(info.CreationTimeUtc);
        }
Пример #21
0
        public void TestEmptySourceFinishedProcessing()
        {
            var adorner = new LogSourcePropertyAdorner(_scheduler, _source.Object, TimeSpan.Zero);

            _sourceProperties.SetValue(Core.Properties.PercentageProcessed, Percentage.HundredPercent);
            _scheduler.RunOnce();

            adorner.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent, "because both the source and adorner are finished processing");

            var buffer = new PropertiesBufferList();

            adorner.GetAllProperties(buffer);
            buffer.GetValue(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent, "because both the source and adorner are finished processing");
        }
Пример #22
0
        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);
        }
Пример #23
0
        public void TestCtor()
        {
            _streamWriter.Write("Foo");
            _streamWriter.Flush();

            var info = new FileInfo(_fname);

            _scheduler.RunOnce();

            _file.GetValue(LogFileProperties.LastModified).Should().Be(info.LastWriteTime);
            _file.GetValue(LogFileProperties.Created).Should().Be(info.CreationTime);
        }
        private IReadOnlyLogEntry GetEntry(StreamingTextLogSource logSource, LogLineIndex index)
        {
            var readTask = Task.Factory.StartNew(() => logSource.GetEntry(index));

            logSource.Property(x => x.HasPendingReadRequests).ShouldEventually().BeTrue();
            _taskScheduler.RunOnce();
            readTask.Wait();
            //readTask.Wait(TimeSpan.FromSeconds(10)).Should().BeTrue("because the task should have been finished now that we've let the scheduler run");
            return(readTask.Result);
        }
Пример #25
0
        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))
            });
        }