Esempio n. 1
0
        public void RespectBatchSizeLimit()
        {
            // Arrange
            using var stream = new MemoryStream();

            using var writer = new StreamWriter(stream, Encoding.UTF8WithoutBom);
            writer.Write(FooLogEvent + Environment.NewLine);
            writer.Write(BarLogEvent + Environment.NewLine);
            writer.Flush();

            var batchSizeLimit = stream.Length * 2 / 3;

            // Act
            var got = BufferFileReader.Read(
                stream,
                ref nextLineBeginsAtOffset,
                null,
                null,
                batchSizeLimit);

            // Assert
            got.LogEvents.ShouldBe(new[] { FooLogEvent });
            got.HasReachedLimit.ShouldBeTrue();
            nextLineBeginsAtOffset.ShouldBe(FooLogEvent.Length + Environment.NewLine.Length);
        }
Esempio n. 2
0
        public void NotReadFirstLogEventGivenPartiallyWritten()
        {
            // Arrange
            using var stream = new MemoryStream();

            using var writer = new StreamWriter(stream, Encoding.UTF8);
            writer.Write(FooLogEvent);  // The partially written log event is missing new line
            writer.Flush();

            // Act
            var got = BufferFileReader.Read(stream, ref nextLineBeginsAtOffset, int.MaxValue, long.MaxValue);

            // Assert
            got.LogEvents.ShouldBeEmpty();
            got.HasReachedLimit.ShouldBeFalse();
            nextLineBeginsAtOffset.ShouldBe(0);
        }
Esempio n. 3
0
        public void ReadLogEvent()
        {
            // Arrange
            using var stream = new MemoryStream();

            using var writer = new StreamWriter(stream, Encoding.UTF8);
            writer.Write(FooLogEvent + Environment.NewLine);
            writer.Flush();

            // Act
            var got = BufferFileReader.Read(stream, ref nextLineBeginsAtOffset, int.MaxValue, long.MaxValue);

            // Assert
            got.LogEvents.ShouldBe(new[] { FooLogEvent });
            got.HasReachedLimit.ShouldBeFalse();
            nextLineBeginsAtOffset.ShouldBe(stream.Length);
        }
Esempio n. 4
0
        public void NotReadSecondLogEventGivenPartiallyWritten()
        {
            // Arrange
            using var stream = new MemoryStream();

            using var writer = new StreamWriter(stream, Encoding.UTF8);
            writer.Write(FooLogEvent + Environment.NewLine);
            writer.Write(BarLogEvent);  // The partially written log event is missing new line
            writer.Flush();

            // Act
            var got = BufferFileReader.Read(stream, ref nextLineBeginsAtOffset, int.MaxValue, long.MaxValue);

            // Assert
            got.LogEvents.ShouldBe(new[] { FooLogEvent });
            got.HasReachedLimit.ShouldBeFalse();
            nextLineBeginsAtOffset.ShouldBe(BufferFileReader.BomLength + FooLogEvent.Length + Environment.NewLine.Length);
        }
Esempio n. 5
0
        public void RespectBatchPostingLimit()
        {
            // Arrange
            using var stream = new MemoryStream();

            using var writer = new StreamWriter(stream, Encoding.UTF8);
            writer.Write(FooLogEvent + Environment.NewLine);
            writer.Write(BarLogEvent + Environment.NewLine);
            writer.Flush();

            const int batchPostingLimit = 1;

            // Act
            var got = BufferFileReader.Read(stream, ref nextLineBeginsAtOffset, batchPostingLimit, long.MaxValue);

            // Assert
            got.LogEvents.ShouldBe(new[] { FooLogEvent });
            got.HasReachedLimit.ShouldBeTrue();
            nextLineBeginsAtOffset.ShouldBe(BufferFileReader.BomLength + FooLogEvent.Length + Environment.NewLine.Length);
        }
Esempio n. 6
0
        public void RespectLogEventLimitBytes()
        {
            // Arrange
            using var stream = new MemoryStream();

            using var writer = new StreamWriter(stream, Encoding.UTF8WithoutBom);
            writer.Write(FooLogEvent + Environment.NewLine);
            writer.Flush();

            var logEventLimitBytes = ByteSize.From(FooLogEvent) - 1;

            // Act
            var got = BufferFileReader.Read(
                stream,
                ref nextLineBeginsAtOffset,
                logEventLimitBytes,
                null,
                null);

            // Assert
            got.LogEvents.ShouldBeEmpty();
            got.HasReachedLimit.ShouldBeFalse();
            nextLineBeginsAtOffset.ShouldBe(stream.Length);
        }