From 98f533db965d3752732971db57f9ca5d14348322 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Tue, 26 Aug 2008 16:09:00 +0000 Subject: [PATCH] Improved Client/ServerBootstrapTest to run with both oio and nio socket transport --- ...=> AbstractSocketClientBootstrapTest.java} | 11 ++--- ...=> AbstractSocketServerBootstrapTest.java} | 10 +++-- .../NioSocketClientBootstrapTest.java | 44 +++++++++++++++++++ .../NioSocketServerBootstrapTest.java | 44 +++++++++++++++++++ .../OioSocketClientBootstrapTest.java | 44 +++++++++++++++++++ .../OioSocketServerBootstrapTest.java | 44 +++++++++++++++++++ 6 files changed, 188 insertions(+), 9 deletions(-) rename src/test/java/org/jboss/netty/bootstrap/{ClientBootstrapTest.java => AbstractSocketClientBootstrapTest.java} (93%) rename src/test/java/org/jboss/netty/bootstrap/{ServerBootstrapTest.java => AbstractSocketServerBootstrapTest.java} (95%) create mode 100644 src/test/java/org/jboss/netty/bootstrap/NioSocketClientBootstrapTest.java create mode 100644 src/test/java/org/jboss/netty/bootstrap/NioSocketServerBootstrapTest.java create mode 100644 src/test/java/org/jboss/netty/bootstrap/OioSocketClientBootstrapTest.java create mode 100644 src/test/java/org/jboss/netty/bootstrap/OioSocketServerBootstrapTest.java diff --git a/src/test/java/org/jboss/netty/bootstrap/ClientBootstrapTest.java b/src/test/java/org/jboss/netty/bootstrap/AbstractSocketClientBootstrapTest.java similarity index 93% rename from src/test/java/org/jboss/netty/bootstrap/ClientBootstrapTest.java rename to src/test/java/org/jboss/netty/bootstrap/AbstractSocketClientBootstrapTest.java index 368c8d4e9f..954aa33664 100644 --- a/src/test/java/org/jboss/netty/bootstrap/ClientBootstrapTest.java +++ b/src/test/java/org/jboss/netty/bootstrap/AbstractSocketClientBootstrapTest.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.nio.channels.ServerSocketChannel; +import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -37,7 +38,6 @@ import org.jboss.netty.channel.ChannelFactory; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelPipelineException; import org.jboss.netty.channel.ChannelPipelineFactory; -import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -50,7 +50,7 @@ import org.junit.Test; * @version $Rev$, $Date$ * */ -public class ClientBootstrapTest { +public abstract class AbstractSocketClientBootstrapTest { private static ExecutorService executor; @@ -73,11 +73,12 @@ public class ClientBootstrapTest { } } + protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); @Test(timeout = 10000) public void testFailedConnectionAttempt() throws Exception { ClientBootstrap bootstrap = new ClientBootstrap(); - bootstrap.setFactory(new OioClientSocketChannelFactory(executor)); + bootstrap.setFactory(newClientSocketChannelFactory(executor)); bootstrap.setOption("remoteAddress", new InetSocketAddress("255.255.255.255", 1)); ChannelFuture future = bootstrap.connect(); future.awaitUninterruptibly(); @@ -94,7 +95,7 @@ public class ClientBootstrapTest { serverSocket.configureBlocking(false); ClientBootstrap bootstrap = - new ClientBootstrap(new OioClientSocketChannelFactory(executor)); + new ClientBootstrap(newClientSocketChannelFactory(executor)); bootstrap.setOption( "remoteAddress", new InetSocketAddress( @@ -125,7 +126,7 @@ public class ClientBootstrapTest { serverSocket.configureBlocking(false); ClientBootstrap bootstrap = - new ClientBootstrap(new OioClientSocketChannelFactory(executor)); + new ClientBootstrap(newClientSocketChannelFactory(executor)); bootstrap.setOption( "remoteAddress", new InetSocketAddress( diff --git a/src/test/java/org/jboss/netty/bootstrap/ServerBootstrapTest.java b/src/test/java/org/jboss/netty/bootstrap/AbstractSocketServerBootstrapTest.java similarity index 95% rename from src/test/java/org/jboss/netty/bootstrap/ServerBootstrapTest.java rename to src/test/java/org/jboss/netty/bootstrap/AbstractSocketServerBootstrapTest.java index 4921a8db6e..e82dd552b1 100644 --- a/src/test/java/org/jboss/netty/bootstrap/ServerBootstrapTest.java +++ b/src/test/java/org/jboss/netty/bootstrap/AbstractSocketServerBootstrapTest.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; +import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -43,7 +44,6 @@ import org.jboss.netty.channel.ChannelPipelineFactory; import org.jboss.netty.channel.ChildChannelStateEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.channel.socket.SocketChannelConfig; -import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -56,7 +56,7 @@ import org.junit.Test; * @version $Rev$, $Date$ * */ -public class ServerBootstrapTest { +public abstract class AbstractSocketServerBootstrapTest { private static ExecutorService executor; @@ -79,10 +79,12 @@ public class ServerBootstrapTest { } } + protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); + @Test(timeout = 10000, expected = ChannelException.class) public void testFailedBindAttempt() throws Exception { ServerBootstrap bootstrap = new ServerBootstrap(); - bootstrap.setFactory(new OioServerSocketChannelFactory(executor, executor)); + bootstrap.setFactory(newServerSocketChannelFactory(executor)); bootstrap.setOption("localAddress", new InetSocketAddress("255.255.255.255", 0)); bootstrap.bind(); } @@ -90,7 +92,7 @@ public class ServerBootstrapTest { @Test(timeout = 10000) public void testSuccessfulBindAttempt() throws Exception { ServerBootstrap bootstrap = new ServerBootstrap( - new OioServerSocketChannelFactory(executor, executor)); + newServerSocketChannelFactory(executor)); bootstrap.setParentHandler(new ParentChannelHandler()); bootstrap.setOption("localAddress", new InetSocketAddress(0)); diff --git a/src/test/java/org/jboss/netty/bootstrap/NioSocketClientBootstrapTest.java b/src/test/java/org/jboss/netty/bootstrap/NioSocketClientBootstrapTest.java new file mode 100644 index 0000000000..9541f184ca --- /dev/null +++ b/src/test/java/org/jboss/netty/bootstrap/NioSocketClientBootstrapTest.java @@ -0,0 +1,44 @@ +/* + * JBoss, Home of Professional Open Source + * + * Copyright 2008, Red Hat Middleware LLC, and individual contributors + * by the @author tags. See the COPYRIGHT.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.netty.bootstrap; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; + +/** + * @author The Netty Project (netty-dev@lists.jboss.org) + * @author Trustin Lee (tlee@redhat.com) + * + * @version $Rev$, $Date$ + * + */ +public class NioSocketClientBootstrapTest extends + AbstractSocketClientBootstrapTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new NioClientSocketChannelFactory(executor, executor); + } +} diff --git a/src/test/java/org/jboss/netty/bootstrap/NioSocketServerBootstrapTest.java b/src/test/java/org/jboss/netty/bootstrap/NioSocketServerBootstrapTest.java new file mode 100644 index 0000000000..c83027939b --- /dev/null +++ b/src/test/java/org/jboss/netty/bootstrap/NioSocketServerBootstrapTest.java @@ -0,0 +1,44 @@ +/* + * JBoss, Home of Professional Open Source + * + * Copyright 2008, Red Hat Middleware LLC, and individual contributors + * by the @author tags. See the COPYRIGHT.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.netty.bootstrap; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; + +/** + * @author The Netty Project (netty-dev@lists.jboss.org) + * @author Trustin Lee (tlee@redhat.com) + * + * @version $Rev$, $Date$ + * + */ +public class NioSocketServerBootstrapTest extends + AbstractSocketServerBootstrapTest { + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new NioServerSocketChannelFactory(executor, executor); + } +} diff --git a/src/test/java/org/jboss/netty/bootstrap/OioSocketClientBootstrapTest.java b/src/test/java/org/jboss/netty/bootstrap/OioSocketClientBootstrapTest.java new file mode 100644 index 0000000000..8247177e5e --- /dev/null +++ b/src/test/java/org/jboss/netty/bootstrap/OioSocketClientBootstrapTest.java @@ -0,0 +1,44 @@ +/* + * JBoss, Home of Professional Open Source + * + * Copyright 2008, Red Hat Middleware LLC, and individual contributors + * by the @author tags. See the COPYRIGHT.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.netty.bootstrap; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; + +/** + * @author The Netty Project (netty-dev@lists.jboss.org) + * @author Trustin Lee (tlee@redhat.com) + * + * @version $Rev$, $Date$ + * + */ +public class OioSocketClientBootstrapTest extends + AbstractSocketClientBootstrapTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new OioClientSocketChannelFactory(executor); + } +} diff --git a/src/test/java/org/jboss/netty/bootstrap/OioSocketServerBootstrapTest.java b/src/test/java/org/jboss/netty/bootstrap/OioSocketServerBootstrapTest.java new file mode 100644 index 0000000000..02942883a4 --- /dev/null +++ b/src/test/java/org/jboss/netty/bootstrap/OioSocketServerBootstrapTest.java @@ -0,0 +1,44 @@ +/* + * JBoss, Home of Professional Open Source + * + * Copyright 2008, Red Hat Middleware LLC, and individual contributors + * by the @author tags. See the COPYRIGHT.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.jboss.netty.bootstrap; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory; + +/** + * @author The Netty Project (netty-dev@lists.jboss.org) + * @author Trustin Lee (tlee@redhat.com) + * + * @version $Rev$, $Date$ + * + */ +public class OioSocketServerBootstrapTest extends + AbstractSocketServerBootstrapTest { + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new OioServerSocketChannelFactory(executor, executor); + } +}