LoggingHandler does not override channelReadComplete or channelWritabilityChanged
Motivation: `io.netty.handler.logging.LoggingHandler` does not log when these events happen. Modifiations: Add overrides with logging to these methods. Result: Logging now happens for these two events.
This commit is contained in:
parent
225d10e1ad
commit
34e0007f07
@ -225,10 +225,18 @@ public class LoggingHandler extends ChannelDuplexHandler {
|
|||||||
ctx.deregister(promise);
|
ctx.deregister(promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
if (logger.isEnabled(internalLevel)) {
|
||||||
|
logger.log(internalLevel, format(ctx, "READ COMPLETE"));
|
||||||
|
}
|
||||||
|
ctx.fireChannelReadComplete();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||||
if (logger.isEnabled(internalLevel)) {
|
if (logger.isEnabled(internalLevel)) {
|
||||||
logger.log(internalLevel, format(ctx, "RECEIVED", msg));
|
logger.log(internalLevel, format(ctx, "READ", msg));
|
||||||
}
|
}
|
||||||
ctx.fireChannelRead(msg);
|
ctx.fireChannelRead(msg);
|
||||||
}
|
}
|
||||||
@ -241,6 +249,14 @@ public class LoggingHandler extends ChannelDuplexHandler {
|
|||||||
ctx.write(msg, promise);
|
ctx.write(msg, promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
if (logger.isEnabled(internalLevel)) {
|
||||||
|
logger.log(internalLevel, format(ctx, "WRITABILITY CHANGED"));
|
||||||
|
}
|
||||||
|
ctx.fireChannelWritabilityChanged();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void flush(ChannelHandlerContext ctx) throws Exception {
|
public void flush(ChannelHandlerContext ctx) throws Exception {
|
||||||
if (logger.isEnabled(internalLevel)) {
|
if (logger.isEnabled(internalLevel)) {
|
||||||
|
@ -111,6 +111,17 @@ public class LoggingHandlerTest {
|
|||||||
verify(appender).doAppend(argThat(new RegexLogMatcher(".+ACTIVE$")));
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+ACTIVE$")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldLogChannelWritabilityChanged() throws Exception {
|
||||||
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
|
// this is used to switch the channel to become unwritable
|
||||||
|
channel.config().setWriteBufferLowWaterMark(5);
|
||||||
|
channel.config().setWriteBufferHighWaterMark(10);
|
||||||
|
channel.write("hello", channel.newPromise());
|
||||||
|
|
||||||
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+WRITABILITY CHANGED$")));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldLogChannelRegistered() {
|
public void shouldLogChannelRegistered() {
|
||||||
new EmbeddedChannel(new LoggingHandler());
|
new EmbeddedChannel(new LoggingHandler());
|
||||||
@ -194,7 +205,7 @@ public class LoggingHandlerTest {
|
|||||||
String msg = "hello";
|
String msg = "hello";
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.writeInbound(msg);
|
channel.writeInbound(msg);
|
||||||
verify(appender).doAppend(argThat(new RegexLogMatcher(".+RECEIVED: " + msg + '$')));
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+READ: " + msg + '$')));
|
||||||
|
|
||||||
String handledMsg = channel.readInbound();
|
String handledMsg = channel.readInbound();
|
||||||
assertThat(msg, is(sameInstance(handledMsg)));
|
assertThat(msg, is(sameInstance(handledMsg)));
|
||||||
@ -206,7 +217,7 @@ public class LoggingHandlerTest {
|
|||||||
ByteBuf msg = Unpooled.copiedBuffer("hello", CharsetUtil.UTF_8);
|
ByteBuf msg = Unpooled.copiedBuffer("hello", CharsetUtil.UTF_8);
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.writeInbound(msg);
|
channel.writeInbound(msg);
|
||||||
verify(appender).doAppend(argThat(new RegexLogMatcher(".+RECEIVED: " + msg.readableBytes() + "B$")));
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+READ: " + msg.readableBytes() + "B$")));
|
||||||
|
|
||||||
ByteBuf handledMsg = channel.readInbound();
|
ByteBuf handledMsg = channel.readInbound();
|
||||||
assertThat(msg, is(sameInstance(handledMsg)));
|
assertThat(msg, is(sameInstance(handledMsg)));
|
||||||
@ -219,7 +230,7 @@ public class LoggingHandlerTest {
|
|||||||
ByteBuf msg = Unpooled.EMPTY_BUFFER;
|
ByteBuf msg = Unpooled.EMPTY_BUFFER;
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.writeInbound(msg);
|
channel.writeInbound(msg);
|
||||||
verify(appender).doAppend(argThat(new RegexLogMatcher(".+RECEIVED: 0B$")));
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+READ: 0B$")));
|
||||||
|
|
||||||
ByteBuf handledMsg = channel.readInbound();
|
ByteBuf handledMsg = channel.readInbound();
|
||||||
assertThat(msg, is(sameInstance(handledMsg)));
|
assertThat(msg, is(sameInstance(handledMsg)));
|
||||||
@ -237,7 +248,7 @@ public class LoggingHandlerTest {
|
|||||||
|
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.writeInbound(msg);
|
channel.writeInbound(msg);
|
||||||
verify(appender).doAppend(argThat(new RegexLogMatcher(".+RECEIVED: foobar, 5B$")));
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+READ: foobar, 5B$")));
|
||||||
|
|
||||||
ByteBufHolder handledMsg = channel.readInbound();
|
ByteBufHolder handledMsg = channel.readInbound();
|
||||||
assertThat(msg, is(sameInstance(handledMsg)));
|
assertThat(msg, is(sameInstance(handledMsg)));
|
||||||
@ -245,6 +256,14 @@ public class LoggingHandlerTest {
|
|||||||
assertThat(channel.readInbound(), is(nullValue()));
|
assertThat(channel.readInbound(), is(nullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldLogChannelReadComplete() throws Exception {
|
||||||
|
ByteBuf msg = Unpooled.EMPTY_BUFFER;
|
||||||
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
|
channel.writeInbound(msg);
|
||||||
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+READ COMPLETE$")));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A custom EasyMock matcher that matches on Logback messages.
|
* A custom EasyMock matcher that matches on Logback messages.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user