Exemple #1
0
        public void Should_be_able_to_accomodate_fitting_strings_without_length_that_do_not_fit_by_maximum_encoding_consumption()
        {
            buffer.WriteWithoutLength(new string('-', MaximumSize));

            buffer.IsOverflowed.Should().BeFalse();
            buffer.Position.Should().Be(MaximumSize);
        }
        public void TryCollectGarbage_should_move_useful_and_uncommitted_data_to_the_start_of_the_buffer()
        {
            var usefulData      = Guid.NewGuid().ToByteArray();
            var uncommittedData = Guid.NewGuid().ToByteArray();

            WriteAndCommit(4);
            WriteAndCommit(6);
            WriteAndCommit(usefulData);

            buffer.WriteWithoutLength(uncommittedData);

            buffer.ReportGarbage(new BufferState(10, 2));

            buffer.TryCollectGarbage().Should().BeTrue();

            buffer.Position.Should().Be(usefulData.Length + uncommittedData.Length);
            buffer.CommittedSegment.Should().Equal(usefulData);

            buffer.CommitRecord(uncommittedData.Length);
            buffer.CommittedSegment.Should().Equal(usefulData.Concat(uncommittedData));
        }