public void TestGetSection1()
        {
            using (var file = new TextLogFile(_scheduler, File20Mb))
            {
                file.Property(x => x.EndOfSourceReached).ShouldAfter(TimeSpan.FromSeconds(5)).BeTrue("because we should be able to read the entire file in a few seconds");
                file.Count.Should().Be(165342);
                file.GetValue(LogFileProperties.StartTimestamp).Should().Be(new DateTime(2015, 10, 7, 19, 50, 58, 982));

                LogLine[] section = file.GetSection(new LogFileSection(0, 10));
                section.Should().Equal(new[]
                {
                    new LogLine(0,
                                "2015-10-07 19:50:58,982 [8092, 1] INFO  SharpRemote.Hosting.OutOfProcessSiloServer (null) - Silo Server starting, args (1): \"14056\", without custom type resolver",
                                LevelFlags.Info,
                                new DateTime(2015, 10, 7, 19, 50, 58, 982)),
                    new LogLine(1,
                                "2015-10-07 19:50:58,998 [8092, 1] DEBUG SharpRemote.Hosting.OutOfProcessSiloServer (null) - Args.Length: 1",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 58, 998)),
                    new LogLine(2,
                                "2015-10-07 19:50:59,013 [8092, 1] DEBUG SharpRemote.AbstractSocketRemotingEndPoint (null) - Creating new servant (#18446744073709551613) 'SharpRemote.Heartbeat' implementing 'SharpRemote.IHeartbeat'",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 59, 013)),
                    new LogLine(3,
                                "2015-10-07 19:50:59,062 [8092, 1] DEBUG SharpRemote.AbstractSocketRemotingEndPoint (null) - Creating new servant (#18446744073709551614) 'SharpRemote.Latency' implementing 'SharpRemote.ILatency'",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 59, 062)),
                    new LogLine(4,
                                "2015-10-07 19:50:59,067 [8092, 1] DEBUG SharpRemote.AbstractSocketRemotingEndPoint (null) - Creating new servant (#18446744073709551615) 'SharpRemote.Hosting.SubjectHost' implementing 'SharpRemote.Hosting.ISubjectHost'",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 59, 067)),
                    new LogLine(5,
                                "2015-10-07 19:50:59,081 [8092, 1] INFO  SharpRemote.SocketRemotingEndPointServer (null) - EndPoint '<Unnamed>' listening on 0.0.0.0:49152",
                                LevelFlags.Info,
                                new DateTime(2015, 10, 7, 19, 50, 59, 081)),
                    new LogLine(6,
                                "2015-10-07 19:50:59,141 [8092, 6] DEBUG SharpRemote.SocketRemotingEndPointServer (null) - Incoming connection from '127.0.0.1:10348', starting handshake...",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 59, 141)),
                    new LogLine(7,
                                "2015-10-07 19:50:59,171 [8092, 6] INFO  SharpRemote.AbstractIPSocketRemotingEndPoint (null) - <Unnamed>: Connected to 127.0.0.1:10348",
                                LevelFlags.Info,
                                new DateTime(2015, 10, 7, 19, 50, 59, 171)),
                    new LogLine(8,
                                "2015-10-07 19:50:59,181 [8092, 10] DEBUG SharpRemote.AbstractSocketRemotingEndPoint (null) - 0.0.0.0:49152 to 127.0.0.1:10348: sending RPC #1 to 18446744073709551611.Beat",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 59, 181)),
                    new LogLine(9,
                                "2015-10-07 19:50:59,182 [8092, 11] DEBUG SharpRemote.AbstractSocketRemotingEndPoint (null) - 0.0.0.0:49152 to 127.0.0.1:10348: sending RPC #2 to 18446744073709551612.Roundtrip",
                                LevelFlags.Debug,
                                new DateTime(2015, 10, 7, 19, 50, 59, 182))
                });
            }
        }
        public void TestRead2LogEntries()
        {
            using (var file = new TextLogFile(_scheduler, File2Entries))
            {
                var listener = new Mock <ILogFileListener>();
                var changes  = new List <LogFileSection>();
                listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogFile>(), It.IsAny <LogFileSection>()))
                .Callback((ILogFile logFile, LogFileSection section) => changes.Add(section));

                file.AddListener(listener.Object, TimeSpan.Zero, 1);

                changes.Property(x => x.Count).ShouldAfter(TimeSpan.FromSeconds(5)).Be(7);

                changes.Should().Equal(new[]
                {
                    LogFileSection.Reset,
                    new LogFileSection(0, 1),
                    new LogFileSection(1, 1),
                    new LogFileSection(2, 1),
                    new LogFileSection(3, 1),
                    new LogFileSection(4, 1),
                    new LogFileSection(5, 1)
                });

                file.GetValue(LogFileProperties.StartTimestamp).Should().Be(new DateTime(2015, 10, 7, 19, 50, 58, 982));

                LogLine[] lines = file.GetSection(new LogFileSection(0, 6));
                lines.Should().Equal(new[]
                {
                    new LogLine(0, 0,
                                "2015-10-07 19:50:58,982 [8092, 1] INFO  SharpRemote.Hosting.OutOfProcessSiloServer (null) - Silo Server starting, args (1): \"14056\", without custom type resolver",
                                LevelFlags.Info, new DateTime(2015, 10, 7, 19, 50, 58, 982)),
                    new LogLine(1, 1, "Foobar", LevelFlags.Other, null),
                    new LogLine(2, 2, "Some more info", LevelFlags.Other, null),
                    new LogLine(3, 3,
                                "2015-10-07 19:50:58,998 [8092, 1] DEBUG SharpRemote.Hosting.OutOfProcessSiloServer (null) - Args.Length: 1",
                                LevelFlags.Debug, new DateTime(2015, 10, 7, 19, 50, 58, 998)),
                    new LogLine(4, 4, "Hey look at me", LevelFlags.Other, null),
                    new LogLine(5, 5, "dwadawdadw", LevelFlags.Other, null)
                });
            }
        }
Exemplo n.º 3
0
        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);
                    }
                }
        }