diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractClientSocketTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractClientSocketTest.java index f6fde17047..dabcf5492c 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractClientSocketTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractClientSocketTest.java @@ -36,7 +36,7 @@ public abstract class AbstractClientSocketTest extends AbstractTestsuiteTest> newFactories() { - return SocketTestPermutation.clientSocket(); + return SocketTestPermutation.INSTANCE.clientSocket(); } @Override diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramTest.java index e8b1b9a638..353f614f2b 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractDatagramTest.java @@ -36,7 +36,7 @@ public abstract class AbstractDatagramTest extends AbstractComboTestsuiteTest> newFactories() { - return SocketTestPermutation.datagram(); + return SocketTestPermutation.INSTANCE.datagram(); } @Override diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractServerSocketTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractServerSocketTest.java index fb634556de..8a4d17748e 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractServerSocketTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractServerSocketTest.java @@ -36,7 +36,7 @@ public abstract class AbstractServerSocketTest extends AbstractTestsuiteTest> newFactories() { - return SocketTestPermutation.serverSocket(); + return SocketTestPermutation.INSTANCE.serverSocket(); } @Override diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketTest.java index 10e7321a54..a73d2d545e 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketTest.java @@ -37,7 +37,7 @@ public abstract class AbstractSocketTest extends AbstractComboTestsuiteTest> newFactories() { - return SocketTestPermutation.socket(); + return SocketTestPermutation.INSTANCE.socket(); } @Override diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java index 05dd6d4008..dec016c7a4 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketTestPermutation.java @@ -15,6 +15,7 @@ */ package io.netty.testsuite.transport.socket; +import io.netty.bootstrap.AbstractBootstrap; import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ChannelFactory; import io.netty.bootstrap.ServerBootstrap; @@ -34,28 +35,53 @@ import io.netty.testsuite.transport.TestsuitePermutation.BootstrapFactory; import io.netty.util.concurrent.DefaultThreadFactory; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -public final class SocketTestPermutation { - private SocketTestPermutation() { - // utility - } +public class SocketTestPermutation { - private static final int BOSSES = 2; - private static final int WORKERS = 3; - private static final EventLoopGroup nioBossGroup = + static final SocketTestPermutation INSTANCE = new SocketTestPermutation(); + + protected static final int BOSSES = 2; + protected static final int WORKERS = 3; + + protected final EventLoopGroup nioBossGroup = new NioEventLoopGroup(BOSSES, new DefaultThreadFactory("testsuite-nio-boss", true)); - private static final EventLoopGroup nioWorkerGroup = + protected final EventLoopGroup nioWorkerGroup = new NioEventLoopGroup(WORKERS, new DefaultThreadFactory("testsuite-nio-worker", true)); - private static final EventLoopGroup oioBossGroup = + protected final EventLoopGroup oioBossGroup = new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-oio-boss", true)); - private static final EventLoopGroup oioWorkerGroup = + protected final EventLoopGroup oioWorkerGroup = new OioEventLoopGroup(Integer.MAX_VALUE, new DefaultThreadFactory("testsuite-oio-worker", true)); - static List> socket() { - List> list = - new ArrayList>(); + protected , B extends AbstractBootstrap> + List> combo(List> sbfs, List> cbfs) { + List> list = new ArrayList>(); + + // Populate the combinations + for (BootstrapFactory sbf: sbfs) { + for (BootstrapFactory cbf: cbfs) { + final BootstrapFactory sbf0 = sbf; + final BootstrapFactory cbf0 = cbf; + list.add(new BootstrapComboFactory() { + @Override + public A newServerInstance() { + return sbf0.newInstance(); + } + + @Override + public B newClientInstance() { + return cbf0.newInstance(); + } + }); + } + } + + return list; + } + + public List> socket() { // Make the list of ServerBootstrap factories. List> sbfs = serverSocket(); @@ -63,23 +89,7 @@ public final class SocketTestPermutation { List> cbfs = clientSocket(); // Populate the combinations - for (BootstrapFactory sbf: sbfs) { - for (BootstrapFactory cbf: cbfs) { - final BootstrapFactory sbf0 = sbf; - final BootstrapFactory cbf0 = cbf; - list.add(new BootstrapComboFactory() { - @Override - public ServerBootstrap newServerInstance() { - return sbf0.newInstance(); - } - - @Override - public Bootstrap newClientInstance() { - return cbf0.newInstance(); - } - }); - } - } + List> list = combo(sbfs, cbfs); // Remove the OIO-OIO case which often leads to a dead lock by its nature. list.remove(list.size() - 1); @@ -87,95 +97,70 @@ public final class SocketTestPermutation { return list; } - static List> datagram() { - List> list = - new ArrayList>(); - + public List> datagram() { // Make the list of Bootstrap factories. - List> bfs = - new ArrayList>(); - bfs.add(new BootstrapFactory() { - @Override - public Bootstrap newInstance() { - return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory() { + List> bfs = Arrays.asList( + new BootstrapFactory() { @Override - public Channel newChannel() { - return new NioDatagramChannel(InternetProtocolFamily.IPv4); - } + public Bootstrap newInstance() { + return new Bootstrap().group(nioWorkerGroup).channelFactory(new ChannelFactory() { + @Override + public Channel newChannel() { + return new NioDatagramChannel(InternetProtocolFamily.IPv4); + } + @Override + public String toString() { + return NioDatagramChannel.class.getSimpleName() + ".class"; + } + }); + } + }, + new BootstrapFactory() { @Override - public String toString() { - return NioDatagramChannel.class.getSimpleName() + ".class"; + public Bootstrap newInstance() { + return new Bootstrap().group(oioWorkerGroup).channel(OioDatagramChannel.class); } - }); - } - }); - bfs.add(new BootstrapFactory() { - @Override - public Bootstrap newInstance() { - return new Bootstrap().group(oioWorkerGroup).channel(OioDatagramChannel.class); - } - }); + } + ); - // Populate the combinations - for (BootstrapFactory sbf: bfs) { - for (BootstrapFactory cbf: bfs) { - final BootstrapFactory sbf0 = sbf; - final BootstrapFactory cbf0 = cbf; - list.add(new BootstrapComboFactory() { - @Override - public Bootstrap newServerInstance() { - return sbf0.newInstance(); - } - - @Override - public Bootstrap newClientInstance() { - return cbf0.newInstance(); - } - }); - } - } - - return list; + // Populare the combinations. + return combo(bfs, bfs); } - static List> serverSocket() { - List> list = new ArrayList>(); - - // Make the list of ServerBootstrap factories. - list.add(new BootstrapFactory() { - @Override - public ServerBootstrap newInstance() { - return new ServerBootstrap().group(nioBossGroup, nioWorkerGroup) - .channel(NioServerSocketChannel.class); - } - }); - list.add(new BootstrapFactory() { - @Override - public ServerBootstrap newInstance() { - return new ServerBootstrap().group(oioBossGroup, oioWorkerGroup) - .channel(OioServerSocketChannel.class); - } - }); - - return list; + public List> serverSocket() { + return Arrays.asList( + new BootstrapFactory() { + @Override + public ServerBootstrap newInstance() { + return new ServerBootstrap().group(nioBossGroup, nioWorkerGroup) + .channel(NioServerSocketChannel.class); + } + }, + new BootstrapFactory() { + @Override + public ServerBootstrap newInstance() { + return new ServerBootstrap().group(oioBossGroup, oioWorkerGroup) + .channel(OioServerSocketChannel.class); + } + } + ); } - static List> clientSocket() { - List> list = new ArrayList>(); - list.add(new BootstrapFactory() { - @Override - public Bootstrap newInstance() { - return new Bootstrap().group(nioWorkerGroup).channel(NioSocketChannel.class); - } - }); - list.add(new BootstrapFactory() { - @Override - public Bootstrap newInstance() { - return new Bootstrap().group(oioWorkerGroup).channel(OioSocketChannel.class); - } - }); - return list; + public List> clientSocket() { + return Arrays.asList( + new BootstrapFactory() { + @Override + public Bootstrap newInstance() { + return new Bootstrap().group(nioWorkerGroup).channel(NioSocketChannel.class); + } + }, + new BootstrapFactory() { + @Override + public Bootstrap newInstance() { + return new Bootstrap().group(oioWorkerGroup).channel(OioSocketChannel.class); + } + } + ); } - } diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketEchoTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketEchoTest.java index d3c70a1178..e193aad087 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketEchoTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketEchoTest.java @@ -26,6 +26,6 @@ public class EpollSocketEchoTest extends SocketEchoTest { @Override protected List> newFactories() { - return EpollTestUtils.newFactories(); + return EpollSocketTestPermutation.INSTANCE.socket(); } } diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketFileRegionTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketFileRegionTest.java index cecd2960e9..c46fce3f47 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketFileRegionTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketFileRegionTest.java @@ -26,6 +26,6 @@ public class EpollSocketFileRegionTest extends SocketFileRegionTest { @Override protected List> newFactories() { - return EpollTestUtils.newFactories(); + return EpollSocketTestPermutation.INSTANCE.socket(); } } diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketFixedLengthEchoTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketFixedLengthEchoTest.java index 16392bf284..fc93dcb908 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketFixedLengthEchoTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketFixedLengthEchoTest.java @@ -26,6 +26,6 @@ public class EpollSocketFixedLengthEchoTest extends SocketFixedLengthEchoTest { @Override protected List> newFactories() { - return EpollTestUtils.newFactories(); + return EpollSocketTestPermutation.INSTANCE.socket(); } } diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketGatheringWriteTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketGatheringWriteTest.java index ed5d09413d..311efcaf75 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketGatheringWriteTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketGatheringWriteTest.java @@ -26,6 +26,6 @@ public class EpollSocketGatheringWriteTest extends SocketGatheringWriteTest { @Override protected List> newFactories() { - return EpollTestUtils.newFactories(); + return EpollSocketTestPermutation.INSTANCE.socket(); } } diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketObjectEchoTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketObjectEchoTest.java index b6305590ca..bf1fd0a5d3 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketObjectEchoTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketObjectEchoTest.java @@ -26,6 +26,6 @@ public class EpollSocketObjectEchoTest extends SocketObjectEchoTest { @Override protected List> newFactories() { - return EpollTestUtils.newFactories(); + return EpollSocketTestPermutation.INSTANCE.socket(); } } diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketSslEchoTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketSslEchoTest.java index 24eccf4f19..7271b5ad1b 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketSslEchoTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketSslEchoTest.java @@ -34,6 +34,6 @@ public class EpollSocketSslEchoTest extends SocketSslEchoTest { @Override protected List> newFactories() { - return EpollTestUtils.newFactories(); + return EpollSocketTestPermutation.INSTANCE.socket(); } } diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketStartTlsTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketStartTlsTest.java index c290c6a812..f80a24bcf9 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketStartTlsTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketStartTlsTest.java @@ -26,6 +26,6 @@ public class EpollSocketStartTlsTest extends SocketStartTlsTest { @Override protected List> newFactories() { - return EpollTestUtils.newFactories(); + return EpollSocketTestPermutation.INSTANCE.socket(); } } diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketStringEchoTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketStringEchoTest.java index a8a7bb8889..d01346c162 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketStringEchoTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketStringEchoTest.java @@ -26,6 +26,6 @@ public class EpollSocketStringEchoTest extends SocketStringEchoTest { @Override protected List> newFactories() { - return EpollTestUtils.newFactories(); + return EpollSocketTestPermutation.INSTANCE.socket(); } } diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketTestPermutation.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketTestPermutation.java new file mode 100644 index 0000000000..a452a956e4 --- /dev/null +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketTestPermutation.java @@ -0,0 +1,88 @@ +/* + * Copyright 2014 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package io.netty.channel.epoll; + +import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.testsuite.transport.TestsuitePermutation; +import io.netty.testsuite.transport.TestsuitePermutation.BootstrapFactory; +import io.netty.testsuite.transport.socket.SocketTestPermutation; +import io.netty.util.concurrent.DefaultThreadFactory; + +import java.util.Arrays; +import java.util.List; + +class EpollSocketTestPermutation extends SocketTestPermutation { + + static final SocketTestPermutation INSTANCE = new EpollSocketTestPermutation(); + + private final EventLoopGroup epollBossGroup = + new EpollEventLoopGroup(BOSSES, new DefaultThreadFactory("testsuite-epoll-boss", true)); + private final EventLoopGroup epollWorkerGroup = + new EpollEventLoopGroup(WORKERS, new DefaultThreadFactory("testsuite-epoll-worker", true)); + + @Override + public List> socket() { + + List> list = + combo(serverSocket(), clientSocket()); + + list.remove(list.size() - 1); // Exclude NIO x NIO test + + return list; + } + + @Override + public List> serverSocket() { + return Arrays.asList( + new BootstrapFactory() { + @Override + public ServerBootstrap newInstance() { + return new ServerBootstrap().group(epollBossGroup, epollWorkerGroup) + .channel(EpollServerSocketChannel.class); + } + }, + new BootstrapFactory() { + @Override + public ServerBootstrap newInstance() { + return new ServerBootstrap().group(nioBossGroup, nioWorkerGroup) + .channel(NioServerSocketChannel.class); + } + } + ); + } + + @Override + public List> clientSocket() { + return Arrays.asList( + new BootstrapFactory() { + @Override + public Bootstrap newInstance() { + return new Bootstrap().group(epollWorkerGroup).channel(EpollSocketChannel.class); + } + }, + new BootstrapFactory() { + @Override + public Bootstrap newInstance() { + return new Bootstrap().group(nioWorkerGroup).channel(NioSocketChannel.class); + } + } + ); + } +} diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollTestUtils.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollTestUtils.java deleted file mode 100644 index 72382c142f..0000000000 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollTestUtils.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2014 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.channel.epoll; - -import io.netty.bootstrap.Bootstrap; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.EventLoopGroup; -import io.netty.testsuite.transport.TestsuitePermutation; -import io.netty.util.concurrent.DefaultThreadFactory; - -import java.util.Collections; -import java.util.List; - -final class EpollTestUtils { - - private static final int BOSSES = 2; - private static final int WORKERS = 3; - - private static final EventLoopGroup epollBossGroup = - new EpollEventLoopGroup(BOSSES, new DefaultThreadFactory("testsuite-epoll-boss", true)); - private static final EventLoopGroup epollWorkerGroup = - new EpollEventLoopGroup(WORKERS, new DefaultThreadFactory("testsuite-epoll-worker", true)); - - static List> newFactories() { - return Collections.>singletonList( - new TestsuitePermutation.BootstrapComboFactory() { - @Override - public ServerBootstrap newServerInstance() { - return new ServerBootstrap().group( - epollBossGroup, epollWorkerGroup).channel(EpollServerSocketChannel.class); - } - - @Override - public Bootstrap newClientInstance() { - return new Bootstrap().group(epollWorkerGroup).channel(EpollSocketChannel.class); - } - }); - } - - private EpollTestUtils() { - // utility class - } -}