Example usage for io.netty.handler.codec.http2 Http2Error NO_ERROR

List of usage examples for io.netty.handler.codec.http2 Http2Error NO_ERROR

Introduction

In this page you can find the example usage for io.netty.handler.codec.http2 Http2Error NO_ERROR.

Prototype

Http2Error NO_ERROR

To view the source code for io.netty.handler.codec.http2 Http2Error NO_ERROR.

Click Source Link

Usage

From source file:com.linecorp.armeria.common.http.Http2GoAwayListener.java

License:Apache License

private void onGoAway(String sentOrReceived, int lastStreamId, long errorCode, ByteBuf debugData) {
    if (errorCode != Http2Error.NO_ERROR.code()) {
        if (logger.isWarnEnabled()) {
            logger.warn("{} {} a GOAWAY frame: lastStreamId={}, errorCode={}, debugData=\"{}\" (Hex: {})", ch,
                    sentOrReceived, lastStreamId, errorStr(errorCode),
                    debugData.toString(StandardCharsets.UTF_8), ByteBufUtil.hexDump(debugData));
        }//from   ww  w  .  j  a v  a 2 s.  c  o  m
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("{} {} a GOAWAY frame: lastStreamId={}, errorCode=NO_ERROR", ch, sentOrReceived,
                    lastStreamId);
        }
    }
}

From source file:com.linecorp.armeria.internal.http.Http2GoAwayListener.java

License:Apache License

private void onGoAway(String sentOrReceived, int lastStreamId, long errorCode, ByteBuf debugData) {
    if (errorCode != Http2Error.NO_ERROR.code()) {
        if (logger.isWarnEnabled()) {
            logger.warn("{} {} a GOAWAY frame: lastStreamId={}, errorCode={}, debugData=\"{}\"", ch,
                    sentOrReceived, lastStreamId, errorStr(errorCode),
                    debugData.toString(StandardCharsets.UTF_8));
        }//www .j  a v a  2s.c om
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("{} {} a GOAWAY frame: lastStreamId={}, errorCode=NO_ERROR", ch, sentOrReceived,
                    lastStreamId);
        }
    }
}

From source file:io.grpc.netty.NettyServerHandlerTest.java

License:Apache License

@Test
public void closeShouldGracefullyCloseChannel() throws Exception {
    manualSetUp();//  w  ww  .ja v  a  2 s.co m
    handler().close(ctx(), newPromise());

    verifyWrite().writeGoAway(eq(ctx()), eq(Integer.MAX_VALUE), eq(Http2Error.NO_ERROR.code()),
            isA(ByteBuf.class), any(ChannelPromise.class));
    verifyWrite().writePing(eq(ctx()), eq(false), eq(NettyServerHandler.GRACEFUL_SHUTDOWN_PING),
            isA(ChannelPromise.class));
    channelRead(pingFrame(/*ack=*/ true, NettyServerHandler.GRACEFUL_SHUTDOWN_PING));

    verifyWrite().writeGoAway(eq(ctx()), eq(0), eq(Http2Error.NO_ERROR.code()), isA(ByteBuf.class),
            any(ChannelPromise.class));

    // Verify that the channel was closed.
    assertFalse(channel().isOpen());
}

From source file:io.grpc.netty.NettyServerHandlerTest.java

License:Apache License

@Test
public void maxConnectionIdle_goAwaySent_pingAck() throws Exception {
    maxConnectionIdleInNanos = TimeUnit.MILLISECONDS.toNanos(10L);
    manualSetUp();//w  w w . ja  v a 2  s.c o  m
    assertTrue(channel().isOpen());

    fakeClock().forwardNanos(maxConnectionIdleInNanos);

    // first GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(Integer.MAX_VALUE), eq(Http2Error.NO_ERROR.code()),
            any(ByteBuf.class), any(ChannelPromise.class));
    // ping sent
    verifyWrite().writePing(eq(ctx()), eq(false), eq(0x97ACEF001L), any(ChannelPromise.class));
    verifyWrite(never()).writeGoAway(eq(ctx()), eq(0), eq(Http2Error.NO_ERROR.code()), any(ByteBuf.class),
            any(ChannelPromise.class));

    channelRead(pingFrame(true /* isAck */, 0xDEADL)); // irrelevant ping Ack
    verifyWrite(never()).writeGoAway(eq(ctx()), eq(0), eq(Http2Error.NO_ERROR.code()), any(ByteBuf.class),
            any(ChannelPromise.class));
    assertTrue(channel().isOpen());

    channelRead(pingFrame(true /* isAck */, 0x97ACEF001L));

    // second GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(0), eq(Http2Error.NO_ERROR.code()), any(ByteBuf.class),
            any(ChannelPromise.class));
    // channel closed
    assertTrue(!channel().isOpen());
}

From source file:io.grpc.netty.NettyServerHandlerTest.java

License:Apache License

@Test
public void maxConnectionIdle_goAwaySent_pingTimeout() throws Exception {
    maxConnectionIdleInNanos = TimeUnit.MILLISECONDS.toNanos(10L);
    manualSetUp();//from ww w .j  av a 2s.  c o m
    assertTrue(channel().isOpen());

    fakeClock().forwardNanos(maxConnectionIdleInNanos);

    // first GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(Integer.MAX_VALUE), eq(Http2Error.NO_ERROR.code()),
            any(ByteBuf.class), any(ChannelPromise.class));
    // ping sent
    verifyWrite().writePing(eq(ctx()), eq(false), eq(0x97ACEF001L), any(ChannelPromise.class));
    verifyWrite(never()).writeGoAway(eq(ctx()), eq(0), eq(Http2Error.NO_ERROR.code()), any(ByteBuf.class),
            any(ChannelPromise.class));
    assertTrue(channel().isOpen());

    fakeClock().forwardTime(10, TimeUnit.SECONDS);

    // second GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(0), eq(Http2Error.NO_ERROR.code()), any(ByteBuf.class),
            any(ChannelPromise.class));
    // channel closed
    assertTrue(!channel().isOpen());
}

From source file:io.grpc.netty.NettyServerHandlerTest.java

License:Apache License

@Test
public void maxConnectionIdle_activeThenRst_pingAck() throws Exception {
    maxConnectionIdleInNanos = TimeUnit.MILLISECONDS.toNanos(10L);
    manualSetUp();// w ww  .  j  a v  a2  s. c  o  m
    createStream();

    fakeClock().forwardNanos(maxConnectionIdleInNanos);

    // GO_AWAY not sent when active
    verifyWrite(never()).writeGoAway(any(ChannelHandlerContext.class), anyInt(), anyLong(), any(ByteBuf.class),
            any(ChannelPromise.class));
    assertTrue(channel().isOpen());

    channelRead(rstStreamFrame(STREAM_ID, (int) Http2Error.CANCEL.code()));

    fakeClock().forwardNanos(maxConnectionIdleInNanos);

    // first GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(Integer.MAX_VALUE), eq(Http2Error.NO_ERROR.code()),
            any(ByteBuf.class), any(ChannelPromise.class));
    // ping sent
    verifyWrite().writePing(eq(ctx()), eq(false), eq(0x97ACEF001L), any(ChannelPromise.class));
    verifyWrite(never()).writeGoAway(eq(ctx()), eq(STREAM_ID), eq(Http2Error.NO_ERROR.code()),
            any(ByteBuf.class), any(ChannelPromise.class));
    assertTrue(channel().isOpen());

    fakeClock().forwardTime(10, TimeUnit.SECONDS);

    // second GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(STREAM_ID), eq(Http2Error.NO_ERROR.code()), any(ByteBuf.class),
            any(ChannelPromise.class));
    // channel closed
    assertTrue(!channel().isOpen());
}

From source file:io.grpc.netty.NettyServerHandlerTest.java

License:Apache License

@Test
public void maxConnectionIdle_activeThenRst_pingTimeoutk() throws Exception {
    maxConnectionIdleInNanos = TimeUnit.MILLISECONDS.toNanos(10L);
    manualSetUp();/*from   www. j a va 2s.c  om*/
    createStream();

    fakeClock().forwardNanos(maxConnectionIdleInNanos);

    // GO_AWAY not sent when active
    verifyWrite(never()).writeGoAway(any(ChannelHandlerContext.class), anyInt(), anyLong(), any(ByteBuf.class),
            any(ChannelPromise.class));
    assertTrue(channel().isOpen());

    channelRead(rstStreamFrame(STREAM_ID, (int) Http2Error.CANCEL.code()));

    fakeClock().forwardNanos(maxConnectionIdleInNanos);

    // first GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(Integer.MAX_VALUE), eq(Http2Error.NO_ERROR.code()),
            any(ByteBuf.class), any(ChannelPromise.class));
    // ping sent
    verifyWrite().writePing(eq(ctx()), eq(false), eq(0x97ACEF001L), any(ChannelPromise.class));
    verifyWrite(never()).writeGoAway(eq(ctx()), eq(STREAM_ID), eq(Http2Error.NO_ERROR.code()),
            any(ByteBuf.class), any(ChannelPromise.class));
    assertTrue(channel().isOpen());

    channelRead(pingFrame(true /* isAck */, 0x97ACEF001L));

    // second GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(STREAM_ID), eq(Http2Error.NO_ERROR.code()), any(ByteBuf.class),
            any(ChannelPromise.class));
    // channel closed
    assertTrue(!channel().isOpen());
}

From source file:io.grpc.netty.NettyServerHandlerTest.java

License:Apache License

@Test
public void maxConnectionAge_goAwaySent_pingAck() throws Exception {

    maxConnectionAgeInNanos = TimeUnit.MILLISECONDS.toNanos(10L);
    manualSetUp();//from   www .  ja  v  a 2 s .  c o  m
    assertTrue(channel().isOpen());

    fakeClock().forwardNanos(maxConnectionAgeInNanos);

    // first GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(Integer.MAX_VALUE), eq(Http2Error.NO_ERROR.code()),
            any(ByteBuf.class), any(ChannelPromise.class));
    // ping sent
    verifyWrite().writePing(eq(ctx()), eq(false), eq(0x97ACEF001L), any(ChannelPromise.class));
    verifyWrite(never()).writeGoAway(eq(ctx()), eq(0), eq(Http2Error.NO_ERROR.code()), any(ByteBuf.class),
            any(ChannelPromise.class));

    channelRead(pingFrame(true /* isAck */, 0xDEADL)); // irrelevant ping Ack
    verifyWrite(never()).writeGoAway(eq(ctx()), eq(0), eq(Http2Error.NO_ERROR.code()), any(ByteBuf.class),
            any(ChannelPromise.class));
    assertTrue(channel().isOpen());

    channelRead(pingFrame(true /* isAck */, 0x97ACEF001L));

    // second GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(0), eq(Http2Error.NO_ERROR.code()), any(ByteBuf.class),
            any(ChannelPromise.class));
    // channel closed
    assertTrue(!channel().isOpen());
}

From source file:io.grpc.netty.NettyServerHandlerTest.java

License:Apache License

@Test
public void maxConnectionAge_goAwaySent_pingTimeout() throws Exception {

    maxConnectionAgeInNanos = TimeUnit.MILLISECONDS.toNanos(10L);
    manualSetUp();//  w  ww.ja  v a  2  s  . co  m
    assertTrue(channel().isOpen());

    fakeClock().forwardNanos(maxConnectionAgeInNanos);

    // first GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(Integer.MAX_VALUE), eq(Http2Error.NO_ERROR.code()),
            any(ByteBuf.class), any(ChannelPromise.class));
    // ping sent
    verifyWrite().writePing(eq(ctx()), eq(false), eq(0x97ACEF001L), any(ChannelPromise.class));
    verifyWrite(never()).writeGoAway(eq(ctx()), eq(0), eq(Http2Error.NO_ERROR.code()), any(ByteBuf.class),
            any(ChannelPromise.class));
    assertTrue(channel().isOpen());

    fakeClock().forwardTime(10, TimeUnit.SECONDS);

    // second GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(0), eq(Http2Error.NO_ERROR.code()), any(ByteBuf.class),
            any(ChannelPromise.class));
    // channel closed
    assertTrue(!channel().isOpen());
}

From source file:io.grpc.netty.NettyServerHandlerTest.java

License:Apache License

@Test
public void maxConnectionAgeGrace_channelStillOpenDuringGracePeriod() throws Exception {
    maxConnectionAgeInNanos = TimeUnit.MILLISECONDS.toNanos(10L);
    maxConnectionAgeGraceInNanos = TimeUnit.MINUTES.toNanos(30L);
    manualSetUp();/*from  ww w  .ja v  a  2s .  com*/
    createStream();

    fakeClock().forwardNanos(maxConnectionAgeInNanos);

    // first GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(Integer.MAX_VALUE), eq(Http2Error.NO_ERROR.code()),
            any(ByteBuf.class), any(ChannelPromise.class));
    // ping sent
    verifyWrite().writePing(eq(ctx()), eq(false), eq(0x97ACEF001L), any(ChannelPromise.class));
    verifyWrite(never()).writeGoAway(eq(ctx()), eq(STREAM_ID), eq(Http2Error.NO_ERROR.code()),
            any(ByteBuf.class), any(ChannelPromise.class));

    fakeClock().forwardTime(20, TimeUnit.MINUTES);

    // second GO_AWAY sent
    verifyWrite().writeGoAway(eq(ctx()), eq(STREAM_ID), eq(Http2Error.NO_ERROR.code()), any(ByteBuf.class),
            any(ChannelPromise.class));
    // channel not closed yet
    assertTrue(channel().isOpen());
}