From 71838342ce3418e685bf1467fa0245b946b8a532 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 14 Apr 2015 14:54:04 +0200 Subject: [PATCH] Correctly test for non-auto-read correctness in testsuite Motiviation: Our tests for non-auto-read did actually not test this correctly as auto-read was never disabled on the Bootstrap and ServerBootstrap. Modifications: - Correctly disable auto-read on Bootstrap and ServerBootstrap - Fix tests to call ChannelHandlerContext.read() once a Channel becomes active. Result: Correctly test that non-auto-read works. --- .../transport/socket/SocketEchoTest.java | 6 ++++++ .../transport/socket/SocketFileRegionTest.java | 16 ++++++++++++++++ .../socket/SocketFixedLengthEchoTest.java | 6 ++++++ .../socket/SocketGatheringWriteTest.java | 7 +++++++ .../transport/socket/SocketObjectEchoTest.java | 7 +++++++ .../transport/socket/SocketSpdyEchoTest.java | 17 +++++++++++++++++ .../transport/socket/SocketSslEchoTest.java | 11 +++++++++++ .../transport/socket/SocketStartTlsTest.java | 10 ++++++++++ .../transport/socket/SocketStringEchoTest.java | 7 +++++++ 9 files changed, 87 insertions(+) diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketEchoTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketEchoTest.java index 0ffea64a98..87840824ee 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketEchoTest.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketEchoTest.java @@ -23,6 +23,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerAdapter; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.util.concurrent.DefaultEventExecutorGroup; import io.netty.util.concurrent.EventExecutorGroup; @@ -150,6 +151,8 @@ public class SocketEchoTest extends AbstractSocketTest { }); cb.handler(ch); } + sb.childOption(ChannelOption.AUTO_READ, autoRead); + cb.option(ChannelOption.AUTO_READ, autoRead); Channel sc = sb.bind().sync().channel(); Channel cc = cb.connect().sync().channel(); @@ -227,6 +230,9 @@ public class SocketEchoTest extends AbstractSocketTest { public void channelActive(ChannelHandlerContext ctx) throws Exception { channel = ctx.channel(); + if (!autoRead) { + ctx.read(); + } } @Override diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketFileRegionTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketFileRegionTest.java index 0bf64d066b..9c039c8551 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketFileRegionTest.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketFileRegionTest.java @@ -22,6 +22,7 @@ import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelOption; import io.netty.channel.DefaultFileRegion; import io.netty.channel.FileRegion; import io.netty.channel.SimpleChannelInboundHandler; @@ -84,6 +85,9 @@ public class SocketFileRegionTest extends AbstractSocketTest { private static void testFileRegion0( ServerBootstrap sb, Bootstrap cb, boolean voidPromise, final boolean autoRead) throws Throwable { + sb.childOption(ChannelOption.AUTO_READ, autoRead); + cb.option(ChannelOption.AUTO_READ, autoRead); + final int bufferSize = 1024; final File file = File.createTempFile("netty-", ".tmp"); file.deleteOnExit(); @@ -108,6 +112,15 @@ public class SocketFileRegionTest extends AbstractSocketTest { out.close(); ChannelHandler ch = new SimpleChannelInboundHandler() { + + @Override + public void channelActive(ChannelHandlerContext ctx) + throws Exception { + if (!autoRead) { + ctx.read(); + } + } + @Override public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { } @@ -193,6 +206,9 @@ public class SocketFileRegionTest extends AbstractSocketTest { public void channelActive(ChannelHandlerContext ctx) throws Exception { channel = ctx.channel(); + if (!autoRead) { + ctx.read(); + } } @Override diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketFixedLengthEchoTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketFixedLengthEchoTest.java index ec1a2a6030..9683d31121 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketFixedLengthEchoTest.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketFixedLengthEchoTest.java @@ -22,6 +22,7 @@ import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.FixedLengthFrameDecoder; import org.junit.Test; @@ -63,6 +64,7 @@ public class SocketFixedLengthEchoTest extends AbstractSocketTest { final EchoHandler sh = new EchoHandler(autoRead); final EchoHandler ch = new EchoHandler(autoRead); + sb.childOption(ChannelOption.AUTO_READ, autoRead); sb.childHandler(new ChannelInitializer() { @Override public void initChannel(Channel sch) throws Exception { @@ -71,6 +73,7 @@ public class SocketFixedLengthEchoTest extends AbstractSocketTest { } }); + cb.option(ChannelOption.AUTO_READ, autoRead); cb.handler(new ChannelInitializer() { @Override public void initChannel(Channel sch) throws Exception { @@ -148,6 +151,9 @@ public class SocketFixedLengthEchoTest extends AbstractSocketTest { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { channel = ctx.channel(); + if (!autoRead) { + ctx.read(); + } } @Override diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketGatheringWriteTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketGatheringWriteTest.java index 65abc6a322..7880991142 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketGatheringWriteTest.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketGatheringWriteTest.java @@ -23,6 +23,7 @@ import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelOption; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.testsuite.util.TestUtils; import io.netty.util.internal.StringUtil; @@ -104,6 +105,9 @@ public class SocketGatheringWriteTest extends AbstractSocketTest { private void testGatheringWrite0( ServerBootstrap sb, Bootstrap cb, byte[] data, boolean composite, boolean autoRead) throws Throwable { + sb.childOption(ChannelOption.AUTO_READ, autoRead); + cb.option(ChannelOption.AUTO_READ, autoRead); + final TestHandler sh = new TestHandler(autoRead); final TestHandler ch = new TestHandler(autoRead); @@ -190,6 +194,9 @@ public class SocketGatheringWriteTest extends AbstractSocketTest { public void channelActive(ChannelHandlerContext ctx) throws Exception { channel = ctx.channel(); + if (!autoRead) { + ctx.read(); + } } @Override diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketObjectEchoTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketObjectEchoTest.java index 64e39bc12a..5debf7376d 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketObjectEchoTest.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketObjectEchoTest.java @@ -21,6 +21,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerAdapter; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; import io.netty.handler.codec.serialization.ClassResolvers; import io.netty.handler.codec.serialization.ObjectDecoder; import io.netty.handler.codec.serialization.ObjectEncoder; @@ -68,6 +69,9 @@ public class SocketObjectEchoTest extends AbstractSocketTest { } private static void testObjectEcho(ServerBootstrap sb, Bootstrap cb, boolean autoRead) throws Throwable { + sb.childOption(ChannelOption.AUTO_READ, autoRead); + cb.option(ChannelOption.AUTO_READ, autoRead); + final EchoHandler sh = new EchoHandler(autoRead); final EchoHandler ch = new EchoHandler(autoRead); @@ -159,6 +163,9 @@ public class SocketObjectEchoTest extends AbstractSocketTest { public void channelActive(ChannelHandlerContext ctx) throws Exception { channel = ctx.channel(); + if (!autoRead) { + ctx.read(); + } } @Override diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java index 2dcffcef2c..698c6be09e 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSpdyEchoTest.java @@ -23,6 +23,7 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerAdapter; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.spdy.SpdyFrameCodec; @@ -176,6 +177,9 @@ public class SocketSpdyEchoTest extends AbstractSocketTest { throw new IllegalArgumentException("unknown version"); } + sb.childOption(ChannelOption.AUTO_READ, autoRead); + cb.option(ChannelOption.AUTO_READ, autoRead); + final SpdyEchoTestServerHandler sh = new SpdyEchoTestServerHandler(autoRead); final SpdyEchoTestClientHandler ch = new SpdyEchoTestClientHandler(frames.copy(), autoRead); @@ -233,6 +237,13 @@ public class SocketSpdyEchoTest extends AbstractSocketTest { this.autoRead = autoRead; } + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + if (!autoRead) { + ctx.read(); + } + } + @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ctx.write(msg); @@ -267,6 +278,12 @@ public class SocketSpdyEchoTest extends AbstractSocketTest { this.frames = frames; this.autoRead = autoRead; } + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + if (!autoRead) { + ctx.read(); + } + } @Override public void messageReceived(ChannelHandlerContext ctx, ByteBuf in) throws Exception { diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java index 1319b6c248..fd25854235 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java @@ -24,6 +24,7 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.ssl.JdkSslClientContext; import io.netty.handler.ssl.JdkSslServerContext; @@ -209,6 +210,9 @@ public class SocketSslEchoTest extends AbstractSocketTest { public void testSslEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable { reset(); + sb.childOption(ChannelOption.AUTO_READ, autoRead); + cb.option(ChannelOption.AUTO_READ, autoRead); + sb.childHandler(new ChannelInitializer() { @Override @SuppressWarnings("deprecation") @@ -394,6 +398,13 @@ public class SocketSslEchoTest extends AbstractSocketTest { this.exception = exception; } + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + if (!autoRead) { + ctx.read(); + } + } + @Override public final void channelReadComplete(ChannelHandlerContext ctx) throws Exception { try { diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketStartTlsTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketStartTlsTest.java index eb3630381e..4c57cfff84 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketStartTlsTest.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketStartTlsTest.java @@ -21,6 +21,7 @@ import io.netty.buffer.PooledByteBufAllocator; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; import io.netty.channel.ChannelPipeline; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.LineBasedFrameDecoder; @@ -142,6 +143,9 @@ public class SocketStartTlsTest extends AbstractSocketTest { } private void testStartTls(ServerBootstrap sb, Bootstrap cb, boolean autoRead) throws Throwable { + sb.childOption(ChannelOption.AUTO_READ, autoRead); + cb.option(ChannelOption.AUTO_READ, autoRead); + final EventExecutorGroup executor = SocketStartTlsTest.executor; SSLEngine sse = serverCtx.newEngine(PooledByteBufAllocator.DEFAULT); SSLEngine cse = clientCtx.newEngine(PooledByteBufAllocator.DEFAULT); @@ -235,6 +239,9 @@ public class SocketStartTlsTest extends AbstractSocketTest { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { + if (!autoRead) { + ctx.read(); + } ctx.writeAndFlush("StartTlsRequest\n"); } @@ -287,6 +294,9 @@ public class SocketStartTlsTest extends AbstractSocketTest { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { channel = ctx.channel(); + if (!autoRead) { + ctx.read(); + } } @Override diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketStringEchoTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketStringEchoTest.java index c21d9e06f9..59e1ba6184 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketStringEchoTest.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketStringEchoTest.java @@ -20,6 +20,7 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.DelimiterBasedFrameDecoder; import io.netty.handler.codec.Delimiters; @@ -70,6 +71,9 @@ public class SocketStringEchoTest extends AbstractSocketTest { } private static void testStringEcho(ServerBootstrap sb, Bootstrap cb, boolean autoRead) throws Throwable { + sb.childOption(ChannelOption.AUTO_READ, autoRead); + cb.option(ChannelOption.AUTO_READ, autoRead); + final StringEchoHandler sh = new StringEchoHandler(autoRead); final StringEchoHandler ch = new StringEchoHandler(autoRead); @@ -160,6 +164,9 @@ public class SocketStringEchoTest extends AbstractSocketTest { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { channel = ctx.channel(); + if (!autoRead) { + ctx.read(); + } } @Override