Search in sources :

Example 41 with ChannelPromise

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

the class DefaultHttp2ConnectionEncoderTest method dataWriteShouldCreateHalfClosedStream.

@Test
public void dataWriteShouldCreateHalfClosedStream() throws Exception {
    writeAllFlowControlledFrames();
    Http2Stream stream = createStream(STREAM_ID, false);
    ByteBuf data = dummyData();
    ChannelPromise promise = newPromise();
    encoder.writeData(ctx, STREAM_ID, data.retain(), 0, true, promise);
    assertTrue(promise.isSuccess());
    verify(remoteFlow).addFlowControlled(eq(stream), any(FlowControlled.class));
    verify(lifecycleManager).closeStreamLocal(stream, promise);
    assertEquals(data.toString(UTF_8), writtenData.get(0));
    data.release();
}
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.jupiter.api.Test)

Example 42 with ChannelPromise

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

the class DefaultHttp2ConnectionEncoderTest method canWriteHeaderFrameAfterGoAwayReceived.

@Test
public void canWriteHeaderFrameAfterGoAwayReceived() throws Http2Exception {
    writeAllFlowControlledFrames();
    goAwayReceived(STREAM_ID);
    ChannelPromise promise = newPromise();
    encoder.writeHeaders(ctx, STREAM_ID, EmptyHttp2Headers.INSTANCE, 0, false, promise);
    verify(writer).writeHeaders(eq(ctx), eq(STREAM_ID), eq(EmptyHttp2Headers.INSTANCE), eq(0), eq(false), eq(promise));
}
Also used : ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) Test(org.junit.jupiter.api.Test)

Example 43 with ChannelPromise

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

the class DefaultHttp2ConnectionEncoderTest method priorityWriteAfterGoAwayShouldSucceed.

@Test
public void priorityWriteAfterGoAwayShouldSucceed() throws Exception {
    createStream(STREAM_ID, false);
    goAwayReceived(Integer.MAX_VALUE);
    ChannelPromise promise = newPromise();
    encoder.writePriority(ctx, STREAM_ID, 0, (short) 255, true, promise);
    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 44 with ChannelPromise

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

the class DefaultHttp2ConnectionEncoderTest method settingsWriteShouldNotUpdateSettings.

@Test
public void settingsWriteShouldNotUpdateSettings() throws Exception {
    Http2Settings settings = new Http2Settings();
    settings.initialWindowSize(100);
    settings.maxConcurrentStreams(1000);
    settings.headerTableSize(2000);
    ChannelPromise promise = newPromise();
    encoder.writeSettings(ctx, settings, promise);
    verify(writer).writeSettings(eq(ctx), eq(settings), eq(promise));
}
Also used : ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) Test(org.junit.jupiter.api.Test)

Example 45 with ChannelPromise

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise 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.jupiter.api.Test)

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