use of org.apache.hc.core5.http2.ReadableByteChannelMock in project httpcomponents-core by apache.
the class TestFrameInOutBuffers method testReadFramePartialReads.
@Test
public void testReadFramePartialReads() throws Exception {
final FrameInputBuffer inBuffer = new FrameInputBuffer(16 * 1024);
final ReadableByteChannelMock readableChannel = new ReadableByteChannelMock(new byte[] { 0, 0 }, new byte[] { 10, 0, 9, 0 }, new byte[] { 0, 0, 8 }, new byte[] { 4 }, new byte[] { 1, 2, 3, 4 }, new byte[] { 5, 0 }, new byte[] { 0, 0, 0 });
final RawFrame frame = inBuffer.read(readableChannel);
Assertions.assertEquals(FrameType.DATA, FrameType.valueOf(frame.getType()));
Assertions.assertEquals(FrameFlag.of(FrameFlag.END_STREAM, FrameFlag.PADDED), frame.getFlags());
Assertions.assertEquals(8, frame.getStreamId());
final ByteBuffer payload = frame.getPayloadContent();
Assertions.assertNotNull(payload);
Assertions.assertEquals(5, payload.remaining());
Assertions.assertEquals(1, payload.get());
Assertions.assertEquals(2, payload.get());
Assertions.assertEquals(3, payload.get());
Assertions.assertEquals(4, payload.get());
Assertions.assertEquals(5, payload.get());
Assertions.assertEquals(-1, readableChannel.read(ByteBuffer.allocate(1024)));
}
use of org.apache.hc.core5.http2.ReadableByteChannelMock in project httpcomponents-core by apache.
the class TestFrameInOutBuffers method testReadFrameExceedingLimit.
@Test
public void testReadFrameExceedingLimit() throws Exception {
final FrameInputBuffer inBuffer = new FrameInputBuffer(16 * 1024);
final ReadableByteChannelMock readableChannel = new ReadableByteChannelMock(new byte[] { 0, -128, -128, 0, 0, 0, 0, 0, 1 });
Assertions.assertThrows(H2ConnectionException.class, () -> inBuffer.read(readableChannel));
}
use of org.apache.hc.core5.http2.ReadableByteChannelMock in project httpcomponents-core by apache.
the class TestIdentityDecoder method testInvalidConstructor.
@Test
public void testInvalidConstructor() {
final ReadableByteChannel channel = new ReadableByteChannelMock(new String[] { "stuff;", "more stuff" }, StandardCharsets.US_ASCII);
final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, 0, StandardCharsets.US_ASCII);
Assertions.assertThrows(NullPointerException.class, () -> new IdentityDecoder(null, null, null));
Assertions.assertThrows(NullPointerException.class, () -> new IdentityDecoder(channel, null, null));
Assertions.assertThrows(NullPointerException.class, () -> new IdentityDecoder(channel, inbuf, null));
}
use of org.apache.hc.core5.http2.ReadableByteChannelMock in project httpcomponents-core by apache.
the class TestIdentityDecoder method testInvalidInput.
@Test
public void testInvalidInput() throws Exception {
final String s = "stuff";
final ReadableByteChannel channel = new ReadableByteChannelMock(new String[] { s }, StandardCharsets.US_ASCII);
final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, 0, StandardCharsets.US_ASCII);
final BasicHttpTransportMetrics metrics = new BasicHttpTransportMetrics();
final IdentityDecoder decoder = new IdentityDecoder(channel, inbuf, metrics);
Assertions.assertThrows(NullPointerException.class, () -> decoder.read(null));
}
use of org.apache.hc.core5.http2.ReadableByteChannelMock in project httpcomponents-core by apache.
the class TestLengthDelimitedDecoder method testCodingBeyondContentLimit.
@Test
public void testCodingBeyondContentLimit() throws Exception {
final ReadableByteChannel channel = new ReadableByteChannelMock(new String[] { "stuff;", "more stuff; and a lot more stuff" }, StandardCharsets.US_ASCII);
final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, 0, StandardCharsets.US_ASCII);
final BasicHttpTransportMetrics metrics = new BasicHttpTransportMetrics();
final LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(channel, inbuf, metrics, 16);
final ByteBuffer dst = ByteBuffer.allocate(1024);
int bytesRead = decoder.read(dst);
Assertions.assertEquals(6, bytesRead);
Assertions.assertEquals("stuff;", CodecTestUtils.convert(dst));
Assertions.assertFalse(decoder.isCompleted());
Assertions.assertEquals(6, metrics.getBytesTransferred());
dst.clear();
bytesRead = decoder.read(dst);
Assertions.assertEquals(10, bytesRead);
Assertions.assertEquals("more stuff", CodecTestUtils.convert(dst));
Assertions.assertTrue(decoder.isCompleted());
Assertions.assertEquals(16, metrics.getBytesTransferred());
dst.clear();
bytesRead = decoder.read(dst);
Assertions.assertEquals(-1, bytesRead);
Assertions.assertTrue(decoder.isCompleted());
Assertions.assertEquals(16, metrics.getBytesTransferred());
}
Aggregations