Search in sources :

Example 46 with ChannelPromise

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project netty by netty.

the class DefaultHttp2ConnectionEncoderTest method priorityWriteShouldSetPriorityForStream.

@Test
public void priorityWriteShouldSetPriorityForStream() throws Exception {
    ChannelPromise promise = newPromise();
    short weight = 255;
    encoder.writePriority(ctx, STREAM_ID, 0, weight, true, promise);
    // Verify that this did NOT create a stream object.
    Http2Stream stream = stream(STREAM_ID);
    assertNull(stream);
    verify(writer).writePriority(eq(ctx), eq(STREAM_ID), eq(0), eq((short) 255), eq(true), eq(promise));
}
Also used : ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) Test(org.junit.jupiter.api.Test)

Example 47 with ChannelPromise

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project netty by netty.

the class DefaultHttp2ConnectionEncoderTest method pushPromiseWriteShouldReserveStream.

@Test
public void pushPromiseWriteShouldReserveStream() throws Exception {
    createStream(STREAM_ID, false);
    ChannelPromise promise = newPromise();
    encoder.writePushPromise(ctx, STREAM_ID, PUSH_STREAM_ID, EmptyHttp2Headers.INSTANCE, 0, promise);
    assertEquals(RESERVED_LOCAL, stream(PUSH_STREAM_ID).state());
    verify(writer).writePushPromise(eq(ctx), eq(STREAM_ID), eq(PUSH_STREAM_ID), eq(EmptyHttp2Headers.INSTANCE), eq(0), eq(promise));
}
Also used : ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) Test(org.junit.jupiter.api.Test)

Example 48 with ChannelPromise

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project netty by netty.

the class DefaultHttp2ConnectionEncoderTest method trailersDoNotEndStreamThrows.

@Test
public void trailersDoNotEndStreamThrows() {
    writeAllFlowControlledFrames();
    final int streamId = 6;
    ChannelPromise promise = newPromise();
    encoder.writeHeaders(ctx, streamId, EmptyHttp2Headers.INSTANCE, 0, false, promise);
    ChannelPromise promise2 = newPromise();
    ChannelFuture future = encoder.writeHeaders(ctx, streamId, EmptyHttp2Headers.INSTANCE, 0, false, promise2);
    assertTrue(future.isDone());
    assertFalse(future.isSuccess());
    verify(writer, times(1)).writeHeaders(eq(ctx), eq(streamId), eq(EmptyHttp2Headers.INSTANCE), eq(0), eq(false), eq(promise));
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) Test(org.junit.jupiter.api.Test)

Example 49 with ChannelPromise

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project netty by netty.

the class DefaultHttp2ConnectionEncoderTest method assertSplitPaddingOnEmptyBuffer.

private void assertSplitPaddingOnEmptyBuffer(ByteBuf data) throws Exception {
    createStream(STREAM_ID, false);
    when(frameSizePolicy.maxFrameSize()).thenReturn(5);
    ChannelPromise p = newPromise();
    encoder.writeData(ctx, STREAM_ID, data, 10, true, p);
    assertEquals(10, payloadCaptor.getValue().size());
    payloadCaptor.getValue().write(ctx, 10);
    // writer was called 2 times
    assertEquals(1, writtenData.size());
    assertEquals("", writtenData.get(0));
    assertEquals(10, (int) writtenPadding.get(0));
    assertEquals(0, data.refCnt());
    assertTrue(p.isSuccess());
}
Also used : ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise)

Example 50 with ChannelPromise

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project netty by netty.

the class DefaultHttp2ConnectionEncoderTest method tooManyHeadersThrows.

private void tooManyHeadersThrows(boolean eos) {
    writeAllFlowControlledFrames();
    final int streamId = 6;
    ChannelPromise promise = newPromise();
    encoder.writeHeaders(ctx, streamId, EmptyHttp2Headers.INSTANCE, 0, false, promise);
    ChannelPromise promise2 = newPromise();
    encoder.writeHeaders(ctx, streamId, EmptyHttp2Headers.INSTANCE, 0, true, promise2);
    ChannelPromise promise3 = newPromise();
    ChannelFuture future = encoder.writeHeaders(ctx, streamId, EmptyHttp2Headers.INSTANCE, 0, eos, promise3);
    assertTrue(future.isDone());
    assertFalse(future.isSuccess());
    verify(writer, times(1)).writeHeaders(eq(ctx), eq(streamId), eq(EmptyHttp2Headers.INSTANCE), eq(0), eq(false), eq(promise));
    verify(writer, times(1)).writeHeaders(eq(ctx), eq(streamId), eq(EmptyHttp2Headers.INSTANCE), eq(0), eq(true), eq(promise2));
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise)

Aggregations

ChannelPromise (io.netty.channel.ChannelPromise)223 Test (org.junit.jupiter.api.Test)88 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)63 ChannelFuture (io.netty.channel.ChannelFuture)62 DefaultChannelPromise (io.netty.channel.DefaultChannelPromise)58 ByteBuf (io.netty.buffer.ByteBuf)56 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)30 Test (org.junit.Test)25 Channel (io.netty.channel.Channel)23 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)22 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)22 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)21 ClosedChannelException (java.nio.channels.ClosedChannelException)20 ChannelFutureListener (io.netty.channel.ChannelFutureListener)19 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)18 InvocationOnMock (org.mockito.invocation.InvocationOnMock)18 AsciiString (io.netty.util.AsciiString)15 IOException (java.io.IOException)14 CountDownLatch (java.util.concurrent.CountDownLatch)13 Bootstrap (io.netty.bootstrap.Bootstrap)12