Skip to content

Commit

Permalink
Correctly test for non-auto-read correctness in testsuite
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
normanmaurer committed Apr 20, 2015
1 parent c0b1ab7 commit 7183834
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -150,6 +151,8 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
});
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();
Expand Down Expand Up @@ -227,6 +230,9 @@ private static class EchoHandler extends SimpleChannelInboundHandler<ByteBuf> {
public void channelActive(ChannelHandlerContext ctx)
throws Exception {
channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -84,6 +85,9 @@ public void testFileRegionVoidPromiseNotAutoRead(ServerBootstrap sb, Bootstrap c

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();
Expand All @@ -108,6 +112,15 @@ private static void testFileRegion0(
out.close();

ChannelHandler ch = new SimpleChannelInboundHandler<Object>() {

@Override
public void channelActive(ChannelHandlerContext ctx)
throws Exception {
if (!autoRead) {
ctx.read();
}
}

@Override
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
}
Expand Down Expand Up @@ -193,6 +206,9 @@ private static class TestHandler extends SimpleChannelInboundHandler<ByteBuf> {
public void channelActive(ChannelHandlerContext ctx)
throws Exception {
channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -63,6 +64,7 @@ private static void testFixedLengthEcho(ServerBootstrap sb, Bootstrap cb, boolea
final EchoHandler sh = new EchoHandler(autoRead);
final EchoHandler ch = new EchoHandler(autoRead);

sb.childOption(ChannelOption.AUTO_READ, autoRead);
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(Channel sch) throws Exception {
Expand All @@ -71,6 +73,7 @@ public void initChannel(Channel sch) throws Exception {
}
});

cb.option(ChannelOption.AUTO_READ, autoRead);
cb.handler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(Channel sch) throws Exception {
Expand Down Expand Up @@ -148,6 +151,9 @@ private static class EchoHandler extends SimpleChannelInboundHandler<ByteBuf> {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -104,6 +105,9 @@ public void testGatheringWriteBig(ServerBootstrap sb, Bootstrap cb) throws Throw

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);

Expand Down Expand Up @@ -190,6 +194,9 @@ private static class TestHandler extends SimpleChannelInboundHandler<ByteBuf> {
public void channelActive(ChannelHandlerContext ctx)
throws Exception {
channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -68,6 +69,9 @@ public void testObjectEchoNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws T
}

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);

Expand Down Expand Up @@ -159,6 +163,9 @@ private static class EchoHandler extends ChannelHandlerAdapter {
public void channelActive(ChannelHandlerContext ctx)
throws Exception {
channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -176,6 +177,9 @@ private static void testSpdyEcho(
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);

Expand Down Expand Up @@ -233,6 +237,13 @@ private static class SpdyEchoTestServerHandler extends ChannelHandlerAdapter {
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);
Expand Down Expand Up @@ -267,6 +278,12 @@ private static class SpdyEchoTestClientHandler extends SimpleChannelInboundHandl
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -209,6 +210,9 @@ public static void compressHeapDumps() throws Exception {
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<Channel>() {
@Override
@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -394,6 +398,13 @@ private abstract class EchoHandler extends SimpleChannelInboundHandler<ByteBuf>
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -142,6 +143,9 @@ public void testStartTlsNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Thr
}

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);
Expand Down Expand Up @@ -235,6 +239,9 @@ private static class StartTlsClientHandler extends SimpleChannelInboundHandler<S
@Override
public void channelActive(ChannelHandlerContext ctx)
throws Exception {
if (!autoRead) {
ctx.read();
}
ctx.writeAndFlush("StartTlsRequest\n");
}

Expand Down Expand Up @@ -287,6 +294,9 @@ private static class StartTlsServerHandler extends SimpleChannelInboundHandler<S
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -70,6 +71,9 @@ public void testStringEchoNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws T
}

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);

Expand Down Expand Up @@ -160,6 +164,9 @@ static class StringEchoHandler extends SimpleChannelInboundHandler<String> {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
channel = ctx.channel();
if (!autoRead) {
ctx.read();
}
}

@Override
Expand Down

0 comments on commit 7183834

Please sign in to comment.