Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleReadAheadEmptyData() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldHandleReadAheadEmptyData()
        {
            // GIVEN
            TrackingReader actual        = new TrackingReader(0);
            int            bufferSize    = 10;
            CharReadable   aheadReadable = ThreadAheadReadable.ThreadAhead(actual, bufferSize);

            // WHEN
            actual.AwaitCompletedReadAttempts(1);

            // THEN
            SectionedCharBuffer buffer = new SectionedCharBuffer(bufferSize);

            buffer = aheadReadable.Read(buffer, buffer.Front());
            assertEquals(buffer.Pivot(), buffer.Back());
            assertEquals(buffer.Pivot(), buffer.Front());
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReadAhead() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldReadAhead()
        {
            // GIVEN
            TrackingReader      actual      = new TrackingReader(23);
            int                 bufferSize  = 5;
            CharReadable        aheadReader = ThreadAheadReadable.ThreadAhead(actual, bufferSize);
            SectionedCharBuffer buffer      = new SectionedCharBuffer(bufferSize);

            // WHEN starting it up it should read and fill the buffer to the brim
            assertEquals(bufferSize, actual.AwaitCompletedReadAttempts(1));

            // WHEN we read one buffer
            int read = 0;

            buffer = aheadReader.Read(buffer, buffer.Front());
            AssertBuffer(Chars(read, bufferSize), buffer, 0, bufferSize);
            read += buffer.Available();

            // and simulate reading all characters, i.e. back section will be empty in the new buffer
            buffer = aheadReader.Read(buffer, buffer.Front());
            AssertBuffer(Chars(read, bufferSize), buffer, 0, bufferSize);
            read += buffer.Available();

            // then simulate reading some characters, i.e. back section will contain some characters
            int keep = 2;

            buffer = aheadReader.Read(buffer, buffer.Front() - keep);
            AssertBuffer(Chars(read - keep, bufferSize + keep), buffer, keep, bufferSize);
            read += buffer.Available();

            keep   = 3;
            buffer = aheadReader.Read(buffer, buffer.Front() - keep);
            AssertBuffer(Chars(read - keep, bufferSize + keep), buffer, keep, bufferSize);
            read += buffer.Available();

            keep   = 1;
            buffer = aheadReader.Read(buffer, buffer.Front() - keep);
            assertEquals(3, buffer.Available());
            AssertBuffer(Chars(read - keep, buffer.Available() + keep), buffer, keep, 3);
            read += buffer.Available();
            assertEquals(23, read);
        }