Keep Socket/SctpTestPermutation from creating too many event loops

- Also made the event loops created by *TestPermutation use daemon threads for simplicity (i.e. no need to shut down the event loops)
This commit is contained in:
Trustin Lee 2013-04-03 18:06:46 +09:00
parent 117ad8acd7
commit cd0b5ec2db
7 changed files with 46 additions and 34 deletions

View File

@ -65,9 +65,6 @@ public abstract class AbstractSctpTest {
m.invoke(this, sb, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();
} finally {
sb.shutdown();
cb.shutdown();
}
}
}

View File

@ -17,6 +17,7 @@ package io.netty.testsuite.transport.sctp;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.oio.OioEventLoopGroup;
import io.netty.channel.sctp.nio.NioSctpChannel;
@ -24,6 +25,7 @@ import io.netty.channel.sctp.nio.NioSctpServerChannel;
import io.netty.channel.sctp.oio.OioSctpChannel;
import io.netty.channel.sctp.oio.OioSctpServerChannel;
import io.netty.testsuite.util.TestUtils;
import io.netty.util.concurrent.DefaultThreadFactory;
import java.util.ArrayList;
import java.util.Collections;
@ -32,6 +34,17 @@ import java.util.Map;
public final class SctpTestPermutation {
private static final int BOSSES = 2;
private static final int WORKERS = 3;
private static final EventLoopGroup nioBossGroup =
new NioEventLoopGroup(BOSSES, new DefaultThreadFactory("testsuite-sctp-nio-boss", true));
private static final EventLoopGroup nioWorkerGroup =
new NioEventLoopGroup(WORKERS, new DefaultThreadFactory("testsuite-sctp-nio-worker", true));
private static final EventLoopGroup oioBossGroup =
new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-sctp-oio-boss", true));
private static final EventLoopGroup oioWorkerGroup =
new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-sctp-oio-worker", true));
static List<Factory<ServerBootstrap>> sctpServerChannel() {
if (!TestUtils.isSctpSupported()) {
return Collections.emptyList();
@ -43,7 +56,7 @@ public final class SctpTestPermutation {
@Override
public ServerBootstrap newInstance() {
return new ServerBootstrap().
group(new NioEventLoopGroup(), new NioEventLoopGroup()).
group(nioBossGroup, nioWorkerGroup).
channel(NioSctpServerChannel.class);
}
});
@ -51,7 +64,7 @@ public final class SctpTestPermutation {
@Override
public ServerBootstrap newInstance() {
return new ServerBootstrap().
group(new OioEventLoopGroup(), new OioEventLoopGroup()).
group(oioBossGroup, oioWorkerGroup).
channel(OioSctpServerChannel.class);
}
});
@ -68,13 +81,13 @@ public final class SctpTestPermutation {
list.add(new Factory<Bootstrap>() {
@Override
public Bootstrap newInstance() {
return new Bootstrap().group(new NioEventLoopGroup()).channel(NioSctpChannel.class);
return new Bootstrap().group(nioWorkerGroup).channel(NioSctpChannel.class);
}
});
list.add(new Factory<Bootstrap>() {
@Override
public Bootstrap newInstance() {
return new Bootstrap().group(new OioEventLoopGroup()).channel(OioSctpChannel.class);
return new Bootstrap().group(oioWorkerGroup).channel(OioSctpChannel.class);
}
});
return list;

View File

@ -56,8 +56,6 @@ public abstract class AbstractClientSocketTest {
m.invoke(this, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();
} finally {
cb.shutdown();
}
}
}

View File

@ -32,8 +32,7 @@ import java.util.Map.Entry;
public abstract class AbstractDatagramTest {
private static final List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> COMBO =
SocketTestPermutation.datagram();
private static final List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> COMBO = SocketTestPermutation.datagram();
@Rule
public final TestName testName = new TestName();
@ -62,9 +61,6 @@ public abstract class AbstractDatagramTest {
m.invoke(this, sb, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();
} finally {
sb.shutdown();
cb.shutdown();
}
}
}

View File

@ -57,8 +57,6 @@ public abstract class AbstractServerSocketTest {
m.invoke(this, sb);
} catch (InvocationTargetException ex) {
throw ex.getCause();
} finally {
sb.shutdown();
}
}
}

View File

@ -65,9 +65,6 @@ public abstract class AbstractSocketTest {
m.invoke(this, sb, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();
} finally {
sb.shutdown();
cb.shutdown();
}
}
}

View File

@ -19,6 +19,7 @@ import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ChannelFactory;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.aio.AioEventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.oio.OioEventLoopGroup;
@ -31,6 +32,7 @@ import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.channel.socket.oio.OioDatagramChannel;
import io.netty.channel.socket.oio.OioServerSocketChannel;
import io.netty.channel.socket.oio.OioSocketChannel;
import io.netty.util.concurrent.DefaultThreadFactory;
import io.netty.util.internal.PlatformDependent;
import java.util.ArrayList;
@ -43,6 +45,21 @@ final class SocketTestPermutation {
// Disabling test until the root cause is known.
private static final boolean TEST_AIO = !PlatformDependent.isWindows();
private static final int BOSSES = 2;
private static final int WORKERS = 3;
private static final EventLoopGroup nioBossGroup =
new NioEventLoopGroup(BOSSES, new DefaultThreadFactory("testsuite-nio-boss", true));
private static final EventLoopGroup nioWorkerGroup =
new NioEventLoopGroup(WORKERS, new DefaultThreadFactory("testsuite-nio-worker", true));
private static final EventLoopGroup aioBossGroup =
new AioEventLoopGroup(BOSSES, new DefaultThreadFactory("testsuite-aio-boss", true));
private static final EventLoopGroup aioWorkerGroup =
new AioEventLoopGroup(WORKERS, new DefaultThreadFactory("testsuite-aio-worker", true));
private static final EventLoopGroup oioBossGroup =
new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-oio-boss", true));
private static final EventLoopGroup oioWorkerGroup =
new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-oio-worker", true));
static List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> socket() {
List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> list =
new ArrayList<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>>();
@ -93,7 +110,7 @@ final class SocketTestPermutation {
bfs.add(new Factory<Bootstrap>() {
@Override
public Bootstrap newInstance() {
return new Bootstrap().group(new NioEventLoopGroup()).channelFactory(new ChannelFactory<Channel>() {
return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory<Channel>() {
@Override
public Channel newChannel() {
return new NioDatagramChannel(InternetProtocolFamily.IPv4);
@ -109,7 +126,7 @@ final class SocketTestPermutation {
bfs.add(new Factory<Bootstrap>() {
@Override
public Bootstrap newInstance() {
return new Bootstrap().group(new OioEventLoopGroup()).channel(OioDatagramChannel.class);
return new Bootstrap().group(oioWorkerGroup).channel(OioDatagramChannel.class);
}
});
@ -147,27 +164,24 @@ final class SocketTestPermutation {
list.add(new Factory<ServerBootstrap>() {
@Override
public ServerBootstrap newInstance() {
return new ServerBootstrap().
group(new NioEventLoopGroup(), new NioEventLoopGroup()).
channel(NioServerSocketChannel.class);
return new ServerBootstrap().group(nioBossGroup, nioWorkerGroup)
.channel(NioServerSocketChannel.class);
}
});
if (TEST_AIO) {
list.add(new Factory<ServerBootstrap>() {
@Override
public ServerBootstrap newInstance() {
final AioEventLoopGroup parentGroup = new AioEventLoopGroup();
final AioEventLoopGroup childGroup = new AioEventLoopGroup();
return new ServerBootstrap().group(parentGroup, childGroup).channel(AioServerSocketChannel.class);
return new ServerBootstrap().group(aioBossGroup, aioWorkerGroup)
.channel(AioServerSocketChannel.class);
}
});
}
list.add(new Factory<ServerBootstrap>() {
@Override
public ServerBootstrap newInstance() {
return new ServerBootstrap().
group(new OioEventLoopGroup(), new OioEventLoopGroup()).
channel(OioServerSocketChannel.class);
return new ServerBootstrap().group(oioBossGroup, oioWorkerGroup)
.channel(OioServerSocketChannel.class);
}
});
@ -179,22 +193,21 @@ final class SocketTestPermutation {
list.add(new Factory<Bootstrap>() {
@Override
public Bootstrap newInstance() {
return new Bootstrap().group(new NioEventLoopGroup()).channel(NioSocketChannel.class);
return new Bootstrap().group(nioWorkerGroup).channel(NioSocketChannel.class);
}
});
if (TEST_AIO) {
list.add(new Factory<Bootstrap>() {
@Override
public Bootstrap newInstance() {
final AioEventLoopGroup loop = new AioEventLoopGroup();
return new Bootstrap().group(loop).channel(AioSocketChannel.class);
return new Bootstrap().group(aioWorkerGroup).channel(AioSocketChannel.class);
}
});
}
list.add(new Factory<Bootstrap>() {
@Override
public Bootstrap newInstance() {
return new Bootstrap().group(new OioEventLoopGroup()).channel(OioSocketChannel.class);
return new Bootstrap().group(oioWorkerGroup).channel(OioSocketChannel.class);
}
});
return list;