@Test public void countsReceivedBytes() throws Exception { ByteBuf buf = httpRequestAsBuf(POST, "/foo/bar", "Hello, world"); this.handler.channelRead(mock(ChannelHandlerContext.class), buf); assertThat(countOf("connections.bytes-received"), is((long) buf.readableBytes())); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof ByteBuf) { receivedBytesCount.inc(((ByteBuf) msg).readableBytes()); } else if (msg instanceof ByteBufHolder) { receivedBytesCount.inc(((ByteBufHolder) msg).content().readableBytes()); } else { LOGGER.warn(format("channelRead(): Expected byte buffers, but got [%s]", msg)); } super.channelRead(ctx, msg); }
ChannelStatisticsHandler extends ChannelDuplexHandler { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof ByteBuf) { receivedBytesCount.inc(((ByteBuf) msg).readableBytes()); } else if (msg instanceof ByteBufHolder) { receivedBytesCount.inc(((ByteBufHolder) msg).content().readableBytes()); } else { LOGGER.warn(format("channelRead(): Expected byte buffers, but got [%s]", msg)); } super.channelRead(ctx, msg); } }
ChannelStatisticsHandler extends ChannelDuplexHandler { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof ByteBuf) { receivedBytesCount.inc(((ByteBuf) msg).readableBytes()); } else if (msg instanceof ByteBufHolder) { receivedBytesCount.inc(((ByteBufHolder) msg).content().readableBytes()); } else { LOGGER.warn(format("channelRead(): Expected byte buffers, but got [%s]", msg)); } super.channelRead(ctx, msg); } ChannelStatisticsHandler(MetricRegistry metricRegistry); }
ChannelStatisticsHandler extends ChannelDuplexHandler { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof ByteBuf) { receivedBytesCount.inc(((ByteBuf) msg).readableBytes()); } else if (msg instanceof ByteBufHolder) { receivedBytesCount.inc(((ByteBufHolder) msg).content().readableBytes()); } else { LOGGER.warn(format("channelRead(): Expected byte buffers, but got [%s]", msg)); } super.channelRead(ctx, msg); } ChannelStatisticsHandler(MetricRegistry metricRegistry); @Override void channelRegistered(ChannelHandlerContext ctx); @Override void channelUnregistered(ChannelHandlerContext ctx); @Override void channelActive(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void channelRead(ChannelHandlerContext ctx, Object msg); @Override void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise); }
ChannelStatisticsHandler extends ChannelDuplexHandler { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof ByteBuf) { receivedBytesCount.inc(((ByteBuf) msg).readableBytes()); } else if (msg instanceof ByteBufHolder) { receivedBytesCount.inc(((ByteBufHolder) msg).content().readableBytes()); } else { LOGGER.warn(format("channelRead(): Expected byte buffers, but got [%s]", msg)); } super.channelRead(ctx, msg); } ChannelStatisticsHandler(MetricRegistry metricRegistry); @Override void channelRegistered(ChannelHandlerContext ctx); @Override void channelUnregistered(ChannelHandlerContext ctx); @Override void channelActive(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void channelRead(ChannelHandlerContext ctx, Object msg); @Override void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise);  }