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.
This commit is contained in:
Norman Maurer 2015-04-14 14:54:04 +02:00
parent b35f2b4cb4
commit 3b1bf6348a
9 changed files with 78 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.concurrent.DefaultEventExecutorGroup; import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup; import io.netty.util.concurrent.EventExecutorGroup;
@ -150,6 +151,8 @@ public class SocketEchoTest extends AbstractSocketTest {
}); });
cb.handler(ch); cb.handler(ch);
} }
sb.childOption(ChannelOption.AUTO_READ, autoRead);
cb.option(ChannelOption.AUTO_READ, autoRead);
Channel sc = sb.bind().sync().channel(); Channel sc = sb.bind().sync().channel();
Channel cc = cb.connect().sync().channel(); Channel cc = cb.connect().sync().channel();
@ -227,6 +230,9 @@ public class SocketEchoTest extends AbstractSocketTest {
public void channelActive(ChannelHandlerContext ctx) public void channelActive(ChannelHandlerContext ctx)
throws Exception { throws Exception {
channel = ctx.channel(); channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
} }
@Override @Override

View File

@ -22,6 +22,7 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler; import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultFileRegion; import io.netty.channel.DefaultFileRegion;
import io.netty.channel.FileRegion; import io.netty.channel.FileRegion;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
@ -84,6 +85,9 @@ public class SocketFileRegionTest extends AbstractSocketTest {
private static void testFileRegion0( private static void testFileRegion0(
ServerBootstrap sb, Bootstrap cb, boolean voidPromise, final boolean autoRead) throws Throwable { 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 int bufferSize = 1024;
final File file = File.createTempFile("netty-", ".tmp"); final File file = File.createTempFile("netty-", ".tmp");
file.deleteOnExit(); file.deleteOnExit();
@ -193,6 +197,9 @@ public class SocketFileRegionTest extends AbstractSocketTest {
public void channelActive(ChannelHandlerContext ctx) public void channelActive(ChannelHandlerContext ctx)
throws Exception { throws Exception {
channel = ctx.channel(); channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
} }
@Override @Override

View File

@ -22,6 +22,7 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.FixedLengthFrameDecoder; import io.netty.handler.codec.FixedLengthFrameDecoder;
import org.junit.Test; import org.junit.Test;
@ -63,6 +64,7 @@ public class SocketFixedLengthEchoTest extends AbstractSocketTest {
final EchoHandler sh = new EchoHandler(autoRead); final EchoHandler sh = new EchoHandler(autoRead);
final EchoHandler ch = new EchoHandler(autoRead); final EchoHandler ch = new EchoHandler(autoRead);
sb.childOption(ChannelOption.AUTO_READ, autoRead);
sb.childHandler(new ChannelInitializer<Channel>() { sb.childHandler(new ChannelInitializer<Channel>() {
@Override @Override
public void initChannel(Channel sch) throws Exception { 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<Channel>() { cb.handler(new ChannelInitializer<Channel>() {
@Override @Override
public void initChannel(Channel sch) throws Exception { public void initChannel(Channel sch) throws Exception {
@ -148,6 +151,9 @@ public class SocketFixedLengthEchoTest extends AbstractSocketTest {
@Override @Override
public void channelActive(ChannelHandlerContext ctx) throws Exception { public void channelActive(ChannelHandlerContext ctx) throws Exception {
channel = ctx.channel(); channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
} }
@Override @Override

View File

@ -23,6 +23,7 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.testsuite.util.TestUtils; import io.netty.testsuite.util.TestUtils;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
@ -104,6 +105,9 @@ public class SocketGatheringWriteTest extends AbstractSocketTest {
private void testGatheringWrite0( private void testGatheringWrite0(
ServerBootstrap sb, Bootstrap cb, byte[] data, boolean composite, boolean autoRead) throws Throwable { 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 sh = new TestHandler(autoRead);
final TestHandler ch = new TestHandler(autoRead); final TestHandler ch = new TestHandler(autoRead);
@ -190,6 +194,9 @@ public class SocketGatheringWriteTest extends AbstractSocketTest {
public void channelActive(ChannelHandlerContext ctx) public void channelActive(ChannelHandlerContext ctx)
throws Exception { throws Exception {
channel = ctx.channel(); channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
} }
@Override @Override

View File

@ -21,6 +21,7 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.handler.codec.serialization.ClassResolvers; import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder; import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder; 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 { 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 sh = new EchoHandler(autoRead);
final EchoHandler ch = new EchoHandler(autoRead); final EchoHandler ch = new EchoHandler(autoRead);
@ -159,6 +163,9 @@ public class SocketObjectEchoTest extends AbstractSocketTest {
public void channelActive(ChannelHandlerContext ctx) public void channelActive(ChannelHandlerContext ctx)
throws Exception { throws Exception {
channel = ctx.channel(); channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
} }
@Override @Override

View File

@ -23,6 +23,7 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.spdy.SpdyFrameCodec; import io.netty.handler.codec.spdy.SpdyFrameCodec;
@ -176,6 +177,9 @@ public class SocketSpdyEchoTest extends AbstractSocketTest {
throw new IllegalArgumentException("unknown version"); throw new IllegalArgumentException("unknown version");
} }
sb.childOption(ChannelOption.AUTO_READ, autoRead);
cb.option(ChannelOption.AUTO_READ, autoRead);
final SpdyEchoTestServerHandler sh = new SpdyEchoTestServerHandler(autoRead); final SpdyEchoTestServerHandler sh = new SpdyEchoTestServerHandler(autoRead);
final SpdyEchoTestClientHandler ch = new SpdyEchoTestClientHandler(frames.copy(), autoRead); final SpdyEchoTestClientHandler ch = new SpdyEchoTestClientHandler(frames.copy(), autoRead);
@ -233,6 +237,13 @@ public class SocketSpdyEchoTest extends AbstractSocketTest {
this.autoRead = autoRead; this.autoRead = autoRead;
} }
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
if (!autoRead) {
ctx.read();
}
}
@Override @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ctx.write(msg); ctx.write(msg);
@ -267,6 +278,12 @@ public class SocketSpdyEchoTest extends AbstractSocketTest {
this.frames = frames; this.frames = frames;
this.autoRead = autoRead; this.autoRead = autoRead;
} }
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
if (!autoRead) {
ctx.read();
}
}
@Override @Override
public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception { public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) throws Exception {

View File

@ -24,6 +24,7 @@ import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.ssl.JdkSslClientContext; import io.netty.handler.ssl.JdkSslClientContext;
import io.netty.handler.ssl.JdkSslServerContext; import io.netty.handler.ssl.JdkSslServerContext;
@ -221,6 +222,9 @@ public class SocketSslEchoTest extends AbstractSocketTest {
final ExecutorService delegatedTaskExecutor = Executors.newCachedThreadPool(); final ExecutorService delegatedTaskExecutor = Executors.newCachedThreadPool();
reset(); reset();
sb.childOption(ChannelOption.AUTO_READ, autoRead);
cb.option(ChannelOption.AUTO_READ, autoRead);
sb.childHandler(new ChannelInitializer<Channel>() { sb.childHandler(new ChannelInitializer<Channel>() {
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -419,6 +423,13 @@ public class SocketSslEchoTest extends AbstractSocketTest {
this.exception = exception; this.exception = exception;
} }
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
if (!autoRead) {
ctx.read();
}
}
@Override @Override
public final void channelReadComplete(ChannelHandlerContext ctx) throws Exception { public final void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
try { try {

View File

@ -21,6 +21,7 @@ import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.LineBasedFrameDecoder; 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 { 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; final EventExecutorGroup executor = SocketStartTlsTest.executor;
SSLEngine sse = serverCtx.newEngine(PooledByteBufAllocator.DEFAULT); SSLEngine sse = serverCtx.newEngine(PooledByteBufAllocator.DEFAULT);
SSLEngine cse = clientCtx.newEngine(PooledByteBufAllocator.DEFAULT); SSLEngine cse = clientCtx.newEngine(PooledByteBufAllocator.DEFAULT);
@ -235,6 +239,9 @@ public class SocketStartTlsTest extends AbstractSocketTest {
@Override @Override
public void channelActive(ChannelHandlerContext ctx) public void channelActive(ChannelHandlerContext ctx)
throws Exception { throws Exception {
if (!autoRead) {
ctx.read();
}
ctx.writeAndFlush("StartTlsRequest\n"); ctx.writeAndFlush("StartTlsRequest\n");
} }
@ -287,6 +294,9 @@ public class SocketStartTlsTest extends AbstractSocketTest {
@Override @Override
public void channelActive(ChannelHandlerContext ctx) throws Exception { public void channelActive(ChannelHandlerContext ctx) throws Exception {
channel = ctx.channel(); channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
} }
@Override @Override

View File

@ -20,6 +20,7 @@ import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.DelimiterBasedFrameDecoder; import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters; 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 { 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 sh = new StringEchoHandler(autoRead);
final StringEchoHandler ch = new StringEchoHandler(autoRead); final StringEchoHandler ch = new StringEchoHandler(autoRead);
@ -160,6 +164,9 @@ public class SocketStringEchoTest extends AbstractSocketTest {
@Override @Override
public void channelActive(ChannelHandlerContext ctx) throws Exception { public void channelActive(ChannelHandlerContext ctx) throws Exception {
channel = ctx.channel(); channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
} }
@Override @Override