Search in sources :

Example 41 with ByteBuf

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());
}
Also used : ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) ByteBuf(io.netty.buffer.ByteBuf) FlowControlled(io.netty.handler.codec.http2.Http2RemoteFlowController.FlowControlled) Test(org.junit.Test)

Example 42 with ByteBuf

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();
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 43 with ByteBuf

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();
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 44 with ByteBuf

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();
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 45 with ByteBuf

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();
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1557 Test (org.junit.Test)668 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)162 IOException (java.io.IOException)99 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)89 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)81 Test (org.testng.annotations.Test)68 InetSocketAddress (java.net.InetSocketAddress)60 Channel (io.netty.channel.Channel)57 ChannelFuture (io.netty.channel.ChannelFuture)56 ArrayList (java.util.ArrayList)55 Map (java.util.Map)45 ChannelPromise (io.netty.channel.ChannelPromise)41 AtomicReference (java.util.concurrent.atomic.AtomicReference)36 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)35 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)34 HashMap (java.util.HashMap)34 CountDownLatch (java.util.concurrent.CountDownLatch)34 RecyclableDuplicateByteBuf (io.netty.buffer.RecyclableDuplicateByteBuf)32 EventLoopGroup (io.netty.channel.EventLoopGroup)32