Example usage for io.netty.channel.embedded EmbeddedChannel closeFuture

List of usage examples for io.netty.channel.embedded EmbeddedChannel closeFuture

Introduction

In this page you can find the example usage for io.netty.channel.embedded EmbeddedChannel closeFuture.

Prototype

@Override
    public ChannelFuture closeFuture() 

Source Link

Usage

From source file:org.apache.flink.runtime.query.netty.KvStateServerHandlerTest.java

License:Apache License

/**
 * Tests that the channel is closed if an Exception reaches the channel
 * handler.//from  w ww . j  a v a  2  s .  c  om
 */
@Test
public void testCloseChannelOnExceptionCaught() throws Exception {
    KvStateRegistry registry = new KvStateRegistry();
    AtomicKvStateRequestStats stats = new AtomicKvStateRequestStats();

    KvStateServerHandler handler = new KvStateServerHandler(registry, TEST_THREAD_POOL, stats);
    EmbeddedChannel channel = new EmbeddedChannel(handler);

    channel.pipeline().fireExceptionCaught(new RuntimeException("Expected test Exception"));

    ByteBuf buf = (ByteBuf) readInboundBlocking(channel);
    buf.skipBytes(4); // skip frame length

    // Verify the response
    assertEquals(KvStateRequestType.SERVER_FAILURE, KvStateRequestSerializer.deserializeHeader(buf));
    Throwable response = KvStateRequestSerializer.deserializeServerFailure(buf);

    assertTrue(response.getMessage().contains("Expected test Exception"));

    channel.closeFuture().await(READ_TIMEOUT_MILLIS);
    assertFalse(channel.isActive());
}