Пример #1
0
        public void ReadsSegmentsFromLargeSource()
        {
            var log = Enumerable
                      .Repeat(
                "<log4j:event logger=\"ConsoleApplication1.Program\" level=\"INFO\" timestamp=\"1361281966733\" thread=\"1\">" +
                "  <log4j:message>Istcua orojurf bysgurnl t.</log4j:message>" +
                "  <log4j:properties>" +
                "    <log4j:data name=\"log4japp\" value=\"ConsoleApplication1.exe(6512)\" />" +
                "    <log4j:data name=\"log4jmachinename\" value=\"user1\" />" +
                "  </log4j:properties>" +
                "</log4j:event>", 1200)
                      .Aggregate(string.Concat);

            var stream = new MemoryStream(Encoding.UTF8.GetBytes(log));
            var format = new Log4JXmlLogFormat {
                BufferSize = 10000
            };
            var testScheduler = new TestScheduler();
            var observer      = testScheduler.CreateObserver <RecordSegment>();

            format.ReadSegments(observer, stream, CancellationToken.None).Wait();

            Assert.Equal(1200, observer.Messages.Count);

            var segments = observer.Messages.Select(x => x.Value.Value).ToArray();

            Assert.True(segments.All(x => x.Length > 0));
        }
Пример #2
0
        public void ReadsSegmentsCorrectly()
        {
            var bytes = Encoding.UTF8.GetBytes(
                "<log4j:event logger=\"ConsoleApplication1.Program\" level=\"INFO\" timestamp=\"1361281966733\" thread=\"1\">" +
                "  <log4j:message>Istcua orojurf bysgurnl t.</log4j:message>" +
                "  <log4j:properties>" +
                "    <log4j:data name=\"log4japp\" value=\"ConsoleApplication1.exe(6512)\" />" +
                "    <log4j:data name=\"log4jmachinename\" value=\"user1\" />" +
                "  </log4j:properties>" +
                "</log4j:event>" +
                "<log4j:event logger=\"ConsoleApplication1.Program\" level=\"WARN\" timestamp=\"1361281966808\" thread=\"1\">" +
                "  <log4j:message>Ebo ohow aco inldrfb pameenegy.</log4j:message>" +
                "  <log4j:properties>" +
                "    <log4j:data name=\"log4japp\" value=\"ConsoleApplication1.exe(6512)\" />" +
                "    <log4j:data name=\"log4jmachinename\" value=\"user2\" />" +
                "  </log4j:properties>" +
                "</log4j:event>");

            var stream        = new MemoryStream(bytes);
            var format        = new Log4JXmlLogFormat();
            var testScheduler = new TestScheduler();
            var observer      = testScheduler.CreateObserver <RecordSegment>();

            var offset = format.ReadSegments(observer, stream, CancellationToken.None).Result;

            Assert.Equal(2, observer.Messages.Count);

            var segments = observer.Messages.Select(x => x.Value.Value).ToArray();

            Assert.True(segments.Any(x => x.Offset == 0 && x.Length == 342));
            Assert.True(segments.Any(x => x.Offset == 342 && x.Length == 347));
            Assert.Equal(stream.Length, offset);
        }