use of io.netty.buffer.ByteBuf in project netty by netty.
the class DefaultHttp2ConnectionEncoderTest method dataFramesShouldMergeUseVoidPromise.
@Test
public void dataFramesShouldMergeUseVoidPromise() throws Exception {
createStream(STREAM_ID, false);
final ByteBuf data = dummyData().retain();
ChannelPromise promise1 = newVoidPromise(channel);
encoder.writeData(ctx, STREAM_ID, data, 0, true, promise1);
ChannelPromise promise2 = newVoidPromise(channel);
encoder.writeData(ctx, STREAM_ID, data, 0, true, promise2);
// Now merge the two payloads.
List<FlowControlled> capturedWrites = payloadCaptor.getAllValues();
FlowControlled mergedPayload = capturedWrites.get(0);
mergedPayload.merge(ctx, capturedWrites.get(1));
assertEquals(16, mergedPayload.size());
assertFalse(promise1.isSuccess());
assertFalse(promise2.isSuccess());
// Write the merged payloads and verify it was written correctly.
mergedPayload.write(ctx, 16);
assertEquals(0, mergedPayload.size());
assertEquals("abcdefghabcdefgh", writtenData.get(0));
assertEquals(0, data.refCnt());
// The promises won't be set since there are no listeners.
assertFalse(promise1.isSuccess());
assertFalse(promise2.isSuccess());
}
use of io.netty.buffer.ByteBuf in project netty by netty.
the class SpdyHeaderBlockRawDecoderTest method testZeroNameValuePairs.
@Test
public void testZeroNameValuePairs() throws Exception {
ByteBuf headerBlock = Unpooled.buffer(4);
headerBlock.writeInt(0);
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
decoder.endHeaderBlock(frame);
assertFalse(headerBlock.isReadable());
assertFalse(frame.isInvalid());
assertEquals(0, frame.headers().names().size());
headerBlock.release();
}
use of io.netty.buffer.ByteBuf in project netty by netty.
the class SpdyHeaderBlockRawDecoderTest method testMultipleNames.
@Test
public void testMultipleNames() throws Exception {
ByteBuf headerBlock = Unpooled.buffer(38);
headerBlock.writeInt(2);
headerBlock.writeInt(4);
headerBlock.writeBytes(nameBytes);
headerBlock.writeInt(5);
headerBlock.writeBytes(valueBytes);
headerBlock.writeInt(4);
headerBlock.writeBytes(nameBytes);
headerBlock.writeInt(5);
headerBlock.writeBytes(valueBytes);
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
assertFalse(headerBlock.isReadable());
assertTrue(frame.isInvalid());
assertEquals(1, frame.headers().names().size());
assertTrue(frame.headers().contains(name));
assertEquals(1, frame.headers().getAll(name).size());
assertEquals(value, frame.headers().get(name));
headerBlock.release();
}
use of io.netty.buffer.ByteBuf in project netty by netty.
the class SpdyHeaderBlockRawDecoderTest method testTruncatedHeaderValue.
@Test
public void testTruncatedHeaderValue() throws Exception {
ByteBuf headerBlock = Unpooled.buffer(maxHeaderSize + 13);
headerBlock.writeInt(1);
headerBlock.writeInt(4);
headerBlock.writeBytes(nameBytes);
headerBlock.writeInt(13);
for (int i = 0; i < maxHeaderSize - 3; i++) {
headerBlock.writeByte('a');
}
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
decoder.endHeaderBlock(frame);
assertFalse(headerBlock.isReadable());
assertTrue(frame.isTruncated());
assertFalse(frame.isInvalid());
assertEquals(0, frame.headers().names().size());
headerBlock.release();
}
use of io.netty.buffer.ByteBuf in project netty by netty.
the class SpdyHeaderBlockRawDecoderTest method testMissingValueLength.
@Test
public void testMissingValueLength() throws Exception {
ByteBuf headerBlock = Unpooled.buffer(12);
headerBlock.writeInt(1);
headerBlock.writeInt(4);
headerBlock.writeBytes(nameBytes);
decoder.decode(ByteBufAllocator.DEFAULT, headerBlock, frame);
decoder.endHeaderBlock(frame);
assertFalse(headerBlock.isReadable());
assertTrue(frame.isInvalid());
assertEquals(0, frame.headers().names().size());
headerBlock.release();
}
Aggregations