@Test
  public void test() throws Exception {
    assertEquals("test",
      stub.echo(null, EchoRequestProto.newBuilder().setMessage("test").build()).getMessage());
    Channel channel = Iterators.getOnlyElement(server.allChannels.iterator());
    assertNotNull(channel);
    NettyRpcFrameDecoder decoder = channel.pipeline().get(NettyRpcFrameDecoder.class);
    // set a mock saslServer to verify that it will call the dispose method of this instance
    HBaseSaslRpcServer saslServer = mock(HBaseSaslRpcServer.class);
    decoder.connection.saslServer = saslServer;
    client.close();
    // the channel should have been closed
    channel.closeFuture().await(5, TimeUnit.SECONDS);
    // verify that we have called the dispose method and set saslServer to null
    Waiter.waitFor(CONF, 5000, () -> decoder.connection.saslServer == null);
    verify(saslServer, times(1)).dispose();
  }
Confirm that we truly close the NettyRpcConnection when the netty channel is closed.
hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestNettyIPCCloseConnection.java