Fix resource leak in tests introduced by 69070c37ba.

This commit is contained in:
Norman Maurer 2016-04-14 10:13:55 +02:00
parent 0035630bd0
commit 7c734fcf73
2 changed files with 10 additions and 1 deletions

View File

@ -24,6 +24,7 @@ import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.channel.DefaultChannelPromise;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.Promise;
@ -178,6 +179,14 @@ public class Http2ConnectionHandlerTest {
when(ctx.newPromise()).thenReturn(promise);
when(ctx.write(any())).thenReturn(future);
when(ctx.executor()).thenReturn(executor);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock in) throws Throwable {
Object msg = in.getArgumentAt(0, Object.class);
ReferenceCountUtil.release(msg);
return null;
}
}).when(ctx).fireChannelRead(any());
}
private Http2ConnectionHandler newHandler() throws Exception {

View File

@ -43,7 +43,7 @@ public class ReplayingDecoderTest {
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'C' }));
assertNull(ch.readInbound());
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { '\n' }));
assertEquals(Unpooled.wrappedBuffer(new byte[] { 'A', 'B', 'C' }), ch.readInbound());
assertEquals(Unpooled.wrappedBuffer(new byte[] { 'A', 'B', 'C' }), releaseLater(ch.readInbound()));
// Truncated input
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A' }));