ConnectionLimitingHandler extends ChannelInboundHandlerAdapter { public int numConnections() { return numConnections.get(); } ConnectionLimitingHandler(int maxNumConnections); @Override void channelRead(ChannelHandlerContext ctx, Object msg); int maxNumConnections(); int numConnections(); Set<Channel> children(); static int validateMaxNumConnections(int maxNumConnections);  }
@Test void testExceedMaxNumConnections() { final ConnectionLimitingHandler handler = new ConnectionLimitingHandler(1); final EmbeddedChannel ch1 = new EmbeddedChannel(handler); ch1.writeInbound(ch1); assertThat(handler.numConnections()).isEqualTo(1); assertThat(ch1.isActive()).isTrue(); final EmbeddedChannel ch2 = new EmbeddedChannel(handler); ch2.writeInbound(ch2); assertThat(handler.numConnections()).isEqualTo(1); assertThat(ch2.isActive()).isFalse(); ch1.close(); assertThat(handler.numConnections()).isEqualTo(0); }