Implement Bootstrap.toString() and use it in the testsuite

By implementing Bootstrap.toString() and printing it for each test case helps us figure out which transport is causing a trouble.
This commit is contained in:
Trustin Lee 2012-11-26 16:14:24 +09:00
parent 089d022e03
commit 74749ec15d
8 changed files with 121 additions and 29 deletions

View File

@ -22,6 +22,8 @@ import io.netty.logging.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetworkConstants;
import org.junit.Rule;
import org.junit.rules.TestName;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -29,9 +31,6 @@ import java.net.InetSocketAddress;
import java.util.List;
import java.util.Map.Entry;
import org.junit.Rule;
import org.junit.rules.TestName;
public abstract class AbstractDatagramTest {
private static final List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> COMBO =
@ -57,7 +56,7 @@ public abstract class AbstractDatagramTest {
cb.localAddress(0).remoteAddress(addr);
logger.info(String.format(
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
"Running: %s %d of %d (%s + %s)", testName.getMethodName(), ++ i, COMBO.size(), sb, cb));
try {
Method m = getClass().getDeclaredMethod(
testName.getMethodName(), AbstractBootstrap.class, AbstractBootstrap.class);

View File

@ -58,7 +58,7 @@ public abstract class AbstractSctpTest {
cb.remoteAddress(addr);
logger.info(String.format(
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
"Running: %s %d of %d (%s + %s)", testName.getMethodName(), ++ i, COMBO.size(), sb, cb));
try {
Method m = getClass().getDeclaredMethod(
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);

View File

@ -21,15 +21,14 @@ import io.netty.logging.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetworkConstants;
import org.junit.Rule;
import org.junit.rules.TestName;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.util.List;
import org.junit.Rule;
import org.junit.rules.TestName;
public abstract class AbstractServerSocketTest {
private static final List<Factory<ServerBootstrap>> COMBO = SocketTestPermutation.serverSocket();
@ -51,7 +50,7 @@ public abstract class AbstractServerSocketTest {
sb.localAddress(addr);
logger.info(String.format(
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
"Running: %s %d of %d (%s)", testName.getMethodName(), ++ i, COMBO.size(), sb));
try {
Method m = getClass().getDeclaredMethod(
testName.getMethodName(), ServerBootstrap.class);

View File

@ -22,6 +22,8 @@ import io.netty.logging.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
import io.netty.testsuite.util.TestUtils;
import io.netty.util.NetworkConstants;
import org.junit.Rule;
import org.junit.rules.TestName;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -29,9 +31,6 @@ import java.net.InetSocketAddress;
import java.util.List;
import java.util.Map.Entry;
import org.junit.Rule;
import org.junit.rules.TestName;
public abstract class AbstractSocketTest {
private static final List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> COMBO =
@ -59,7 +58,7 @@ public abstract class AbstractSocketTest {
cb.remoteAddress(addr);
logger.info(String.format(
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
"Running: %s %d of %d (%s + %s)", testName.getMethodName(), ++ i, COMBO.size(), sb, cb));
try {
Method m = getClass().getDeclaredMethod(
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);

View File

@ -25,10 +25,10 @@ import io.netty.channel.socket.aio.AioServerSocketChannel;
import io.netty.channel.socket.aio.AioSocketChannel;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSctpServerChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.channel.socket.nio.NioSctpChannel;
import io.netty.channel.socket.nio.NioSctpServerChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.channel.socket.oio.OioDatagramChannel;
import io.netty.channel.socket.oio.OioEventLoopGroup;
import io.netty.channel.socket.oio.OioServerSocketChannel;
@ -97,6 +97,11 @@ final class SocketTestPermutation {
public Channel newChannel() {
return new NioDatagramChannel(InternetProtocolFamily.IPv4);
}
@Override
public String toString() {
return NioDatagramChannel.class.getSimpleName() + ".class";
}
});
}
});
@ -188,13 +193,7 @@ final class SocketTestPermutation {
public ServerBootstrap newInstance() {
final AioEventLoopGroup parentGroup = new AioEventLoopGroup();
final AioEventLoopGroup childGroup = new AioEventLoopGroup();
return new ServerBootstrap().group(parentGroup, childGroup).channelFactory(new ChannelFactory() {
@Override
public Channel newChannel() {
return new AioServerSocketChannel(parentGroup, childGroup);
}
});
return new ServerBootstrap().group(parentGroup, childGroup).channel(AioServerSocketChannel.class);
}
});
list.add(new Factory<ServerBootstrap>() {
@ -221,12 +220,7 @@ final class SocketTestPermutation {
@Override
public Bootstrap newInstance() {
final AioEventLoopGroup loop = new AioEventLoopGroup();
return new Bootstrap().group(loop).channelFactory(new ChannelFactory() {
@Override
public Channel newChannel() {
return new AioSocketChannel(loop);
}
});
return new Bootstrap().group(loop).channel(AioSocketChannel.class);
}
});
list.add(new Factory<Bootstrap>() {

View File

@ -247,6 +247,49 @@ public abstract class AbstractBootstrap<B extends AbstractBootstrap<?>> {
return attrs;
}
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName());
buf.append('(');
if (group != null) {
buf.append("group: ");
buf.append(group.getClass().getSimpleName());
buf.append(", ");
}
if (factory != null) {
buf.append("factory: ");
buf.append(factory);
buf.append(", ");
}
if (localAddress != null) {
buf.append("localAddress: ");
buf.append(localAddress);
buf.append(", ");
}
if (options != null && !options.isEmpty()) {
buf.append("options: ");
buf.append(options);
buf.append(", ");
}
if (attrs != null && !attrs.isEmpty()) {
buf.append("attrs: ");
buf.append(attrs);
buf.append(", ");
}
if (handler != null) {
buf.append("handler: ");
buf.append(handler);
buf.append(", ");
}
if (buf.charAt(buf.length() - 1) == '(') {
buf.append(')');
} else {
buf.setCharAt(buf.length() - 2, ')');
buf.setLength(buf.length() - 1);
}
return buf.toString();
}
private static final class BootstrapChannelFactory implements ChannelFactory {
private final Class<? extends Channel> clazz;
@ -263,6 +306,9 @@ public abstract class AbstractBootstrap<B extends AbstractBootstrap<?>> {
}
}
public String toString() {
return clazz.getSimpleName() + ".class";
}
}
/**

View File

@ -191,10 +191,30 @@ public class Bootstrap extends AbstractBootstrap<Bootstrap> {
return super.channel(channelClass);
}
@Override
public String toString() {
if (remoteAddress == null) {
return super.toString();
}
StringBuilder buf = new StringBuilder(super.toString());
buf.setLength(buf.length() - 1);
buf.append(", remoteAddress: ");
buf.append(remoteAddress);
buf.append(')');
return buf.toString();
}
private final class AioSocketChannelFactory implements ChannelFactory {
@Override
public Channel newChannel() {
return new AioSocketChannel((AioEventLoopGroup) group());
}
@Override
public String toString() {
return AioSocketChannel.class.getSimpleName() + ".class";
}
}
}

View File

@ -271,6 +271,41 @@ public class ServerBootstrap extends AbstractBootstrap<ServerBootstrap> {
}
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(super.toString());
buf.setLength(buf.length() - 1);
buf.append(", ");
if (childGroup != null) {
buf.append("childGroup: ");
buf.append(childGroup.getClass().getSimpleName());
buf.append(", ");
}
if (childOptions != null && !childOptions.isEmpty()) {
buf.append("childOptions: ");
buf.append(childOptions);
buf.append(", ");
}
if (childAttrs != null && !childAttrs.isEmpty()) {
buf.append("childAttrs: ");
buf.append(childAttrs);
buf.append(", ");
}
if (childHandler != null) {
buf.append("childHandler: ");
buf.append(childHandler);
buf.append(", ");
}
if (buf.charAt(buf.length() - 1) == '(') {
buf.append(')');
} else {
buf.setCharAt(buf.length() - 2, ')');
buf.setLength(buf.length() - 1);
}
return buf.toString();
}
private final class AioServerSocketChannelFactory implements ChannelFactory {
@Override
public Channel newChannel() {