From 7d1ec117878b63aa610410432fd713523790b0c4 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 28 Aug 2008 11:36:26 +0000 Subject: [PATCH] * Fixed issue: NETTY-36 DelimiterBasedFrameDecoder can choose a wrong delimiter when more than one delimiter are specified. * A bunch of integration tests (78% test coverage) --- .../frame/DelimiterBasedFrameDecoder.java | 33 +-- .../netty/handler/codec/frame/Delimiters.java | 2 +- .../AbstractSocketClientBootstrapTest.java | 12 +- .../socket/AbstractSocketEchoTest.java | 62 +++-- .../AbstractSocketFixedLengthEchoTest.java | 214 +++++++++++++++++ .../NioNioSocketFixedLengthEchoTest.java | 50 ++++ .../NioOioSocketFixedLengthEchoTest.java | 50 ++++ .../OioNioSocketFixedLengthEchoTest.java | 50 ++++ .../OioOioSocketFixedLengthEchoTest.java | 50 ++++ ...tSocketCompatibleObjectStreamEchoTest.java | 217 +++++++++++++++++ .../AbstractSocketObjectStreamEchoTest.java | 217 +++++++++++++++++ ...oSocketCompatibleObjectStreamEchoTest.java | 50 ++++ .../NioNioSocketObjectStreamEchoTest.java | 50 ++++ ...oSocketCompatibleObjectStreamEchoTest.java | 50 ++++ .../NioOioSocketObjectStreamEchoTest.java | 50 ++++ ...oSocketCompatibleObjectStreamEchoTest.java | 50 ++++ .../OioNioSocketObjectStreamEchoTest.java | 50 ++++ ...oSocketCompatibleObjectStreamEchoTest.java | 50 ++++ .../OioOioSocketObjectStreamEchoTest.java | 50 ++++ .../ssl/AbstractSocketSslEchoTest.java | 62 +++-- .../handler/ssl/OioOioSocketSslEchoTest.java | 2 +- .../string/AbstractSocketStringEchoTest.java | 223 ++++++++++++++++++ .../string/NioNioSocketStringEchoTest.java | 50 ++++ .../string/NioOioSocketStringEchoTest.java | 50 ++++ .../string/OioNioSocketStringEchoTest.java | 50 ++++ .../string/OioOioSocketStringEchoTest.java | 50 ++++ 26 files changed, 1787 insertions(+), 57 deletions(-) create mode 100644 src/test/java/org/jboss/netty/handler/frame/AbstractSocketFixedLengthEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/frame/NioNioSocketFixedLengthEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/frame/NioOioSocketFixedLengthEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/frame/OioNioSocketFixedLengthEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/frame/OioOioSocketFixedLengthEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/serialization/AbstractSocketCompatibleObjectStreamEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/serialization/AbstractSocketObjectStreamEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/serialization/NioNioSocketCompatibleObjectStreamEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/serialization/NioNioSocketObjectStreamEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/serialization/NioOioSocketCompatibleObjectStreamEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/serialization/NioOioSocketObjectStreamEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/serialization/OioNioSocketCompatibleObjectStreamEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/serialization/OioNioSocketObjectStreamEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/serialization/OioOioSocketCompatibleObjectStreamEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/serialization/OioOioSocketObjectStreamEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/string/AbstractSocketStringEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/string/NioNioSocketStringEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/string/NioOioSocketStringEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/string/OioNioSocketStringEchoTest.java create mode 100644 src/test/java/org/jboss/netty/handler/string/OioOioSocketStringEchoTest.java diff --git a/src/main/java/org/jboss/netty/handler/codec/frame/DelimiterBasedFrameDecoder.java b/src/main/java/org/jboss/netty/handler/codec/frame/DelimiterBasedFrameDecoder.java index ff60599c26..f978f279f6 100644 --- a/src/main/java/org/jboss/netty/handler/codec/frame/DelimiterBasedFrameDecoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/frame/DelimiterBasedFrameDecoder.java @@ -23,7 +23,6 @@ package org.jboss.netty.handler.codec.frame; import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; @@ -70,31 +69,35 @@ public class DelimiterBasedFrameDecoder extends FrameDecoder { @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { - // Try all delimiters. + // Try all delimiters and choose the delimiter which yields the shortest frame. + int minDelimIndex = Integer.MAX_VALUE; + ChannelBuffer minDelim = null; for (ChannelBuffer delim: delimiters) { int delimIndex = indexOf(buffer, delim); - if (delimIndex > 0) { - ChannelBuffer frame = buffer.readBytes(delimIndex); - if (frame.capacity() > maxFrameLength) { - fail(); - } - buffer.skipBytes(delim.capacity()); - return frame; - } else if (delimIndex == 0) { - buffer.skipBytes(delim.capacity()); - return ChannelBuffers.EMPTY_BUFFER; + if (delimIndex >= 0 && delimIndex < minDelimIndex) { + minDelimIndex = delimIndex; + minDelim = delim; } } + if (minDelim != null) { + ChannelBuffer frame = buffer.readBytes(minDelimIndex); + if (frame.readableBytes() > maxFrameLength) { + fail(frame.readableBytes()); + } + buffer.skipBytes(minDelim.capacity()); + return frame; + } + if (buffer.readableBytes() > maxFrameLength) { - fail(); + fail(buffer.readableBytes()); } return null; } - private void fail() throws TooLongFrameException { + private void fail(int frameLength) throws TooLongFrameException { throw new TooLongFrameException( - "The frame length exceeds " + maxFrameLength); + "The frame length exceeds " + maxFrameLength + ": " + frameLength); } private static int indexOf(ChannelBuffer haystack, ChannelBuffer needle) { diff --git a/src/main/java/org/jboss/netty/handler/codec/frame/Delimiters.java b/src/main/java/org/jboss/netty/handler/codec/frame/Delimiters.java index 32fb45cd25..05024c90ec 100644 --- a/src/main/java/org/jboss/netty/handler/codec/frame/Delimiters.java +++ b/src/main/java/org/jboss/netty/handler/codec/frame/Delimiters.java @@ -43,7 +43,7 @@ public class Delimiters { return new ChannelBuffer[] { ChannelBuffers.wrappedBuffer(new byte[] { '\r', '\n' }), ChannelBuffers.wrappedBuffer(new byte[] { '\n' }), - ChannelBuffers.wrappedBuffer(new byte[] { '\r' }) }; + }; } private Delimiters() { diff --git a/src/test/java/org/jboss/netty/bootstrap/AbstractSocketClientBootstrapTest.java b/src/test/java/org/jboss/netty/bootstrap/AbstractSocketClientBootstrapTest.java index 587121a26a..4518e13a70 100644 --- a/src/test/java/org/jboss/netty/bootstrap/AbstractSocketClientBootstrapTest.java +++ b/src/test/java/org/jboss/netty/bootstrap/AbstractSocketClientBootstrapTest.java @@ -87,7 +87,7 @@ public abstract class AbstractSocketClientBootstrapTest { } @Test(timeout = 10000) - public void testSuccessfulConnectionAttempt() throws Exception { + public void testSuccessfulConnectionAttempt() throws Throwable { ServerSocketChannel serverSocket = ServerSocketChannel.open(); serverSocket.socket().bind(new InetSocketAddress(0)); @@ -106,7 +106,11 @@ public abstract class AbstractSocketClientBootstrapTest { serverSocket.accept(); future.awaitUninterruptibly(); + if (future.getCause() != null) { + throw future.getCause(); + } assertTrue(future.isSuccess()); + future.getChannel().close().awaitUninterruptibly(); } finally { try { @@ -118,7 +122,7 @@ public abstract class AbstractSocketClientBootstrapTest { } @Test(timeout = 10000) - public void testSuccessfulConnectionAttemptWithLocalAddress() throws Exception { + public void testSuccessfulConnectionAttemptWithLocalAddress() throws Throwable { ServerSocketChannel serverSocket = ServerSocketChannel.open(); serverSocket.socket().bind(new InetSocketAddress(0)); @@ -138,7 +142,11 @@ public abstract class AbstractSocketClientBootstrapTest { serverSocket.accept(); future.awaitUninterruptibly(); + if (future.getCause() != null) { + throw future.getCause(); + } assertTrue(future.isSuccess()); + future.getChannel().close().awaitUninterruptibly(); } finally { try { diff --git a/src/test/java/org/jboss/netty/channel/socket/AbstractSocketEchoTest.java b/src/test/java/org/jboss/netty/channel/socket/AbstractSocketEchoTest.java index e01a76f9ad..c069efb0a2 100644 --- a/src/test/java/org/jboss/netty/channel/socket/AbstractSocketEchoTest.java +++ b/src/test/java/org/jboss/netty/channel/socket/AbstractSocketEchoTest.java @@ -24,6 +24,7 @@ package org.jboss.netty.channel.socket; import static org.junit.Assert.*; +import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.Random; @@ -31,6 +32,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; import org.jboss.netty.bootstrap.ClientBootstrap; import org.jboss.netty.bootstrap.ServerBootstrap; @@ -60,7 +62,7 @@ import org.junit.Test; public abstract class AbstractSocketEchoTest { private static final Random random = new Random(); - static final byte[] data = new byte[1048576 * 32]; + static final byte[] data = new byte[1048576]; private static ExecutorService executor; @@ -91,7 +93,7 @@ public abstract class AbstractSocketEchoTest { protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); @Test - public void testEcho() throws Throwable { + public void testSimpleEcho() throws Throwable { ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); @@ -109,13 +111,34 @@ public abstract class AbstractSocketEchoTest { Channel cc = ccf.getChannel(); for (int i = 0; i < data.length;) { - int length = Math.min(random.nextInt(1024 * 512), data.length - i); + int length = Math.min(random.nextInt(1024 * 64), data.length - i); cc.write(ChannelBuffers.wrappedBuffer(data, i, length)); i += length; } while (ch.counter < data.length) { - assertNull(ch.exception); + if (sh.exception.get() != null) { + break; + } + if (ch.exception.get() != null) { + break; + } + + try { + Thread.sleep(1); + } catch (InterruptedException e) { + // Ignore. + } + } + + while (sh.counter < data.length) { + if (sh.exception.get() != null) { + break; + } + if (ch.exception.get() != null) { + break; + } + try { Thread.sleep(1); } catch (InterruptedException e) { @@ -124,27 +147,27 @@ public abstract class AbstractSocketEchoTest { } ch.channel.close().awaitUninterruptibly(); - - while (sh.counter < data.length) { - assertNull(sh.exception); - try { - Thread.sleep(1); - } catch (InterruptedException e) { - // Ignore. - } - } - sh.channel.close().awaitUninterruptibly(); sc.close().awaitUninterruptibly(); - assertNull(sh.exception); - assertNull(ch.exception); + if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { + throw sh.exception.get(); + } + if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { + throw ch.exception.get(); + } + if (sh.exception.get() != null) { + throw sh.exception.get(); + } + if (ch.exception.get() != null) { + throw ch.exception.get(); + } } @ChannelPipelineCoverage("one") private class EchoHandler extends SimpleChannelHandler { volatile Channel channel; - volatile Throwable exception; + final AtomicReference exception = new AtomicReference(); volatile int counter; EchoHandler() { @@ -178,8 +201,9 @@ public abstract class AbstractSocketEchoTest { @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { - exception = e.getCause(); - e.getChannel().close(); + if (exception.compareAndSet(null, e.getCause())) { + e.getChannel().close(); + } } } } diff --git a/src/test/java/org/jboss/netty/handler/frame/AbstractSocketFixedLengthEchoTest.java b/src/test/java/org/jboss/netty/handler/frame/AbstractSocketFixedLengthEchoTest.java new file mode 100644 index 0000000000..d77bd48553 --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/frame/AbstractSocketFixedLengthEchoTest.java @@ -0,0 +1,214 @@ +/* + * 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.handler.frame; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.util.Random; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.jboss.netty.bootstrap.ClientBootstrap; +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.ChannelFuture; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.channel.ChannelPipelineCoverage; +import org.jboss.netty.channel.ChannelStateEvent; +import org.jboss.netty.channel.ExceptionEvent; +import org.jboss.netty.channel.MessageEvent; +import org.jboss.netty.channel.SimpleChannelHandler; +import org.jboss.netty.handler.codec.frame.FixedLengthFrameDecoder; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + + +/** + * @author The Netty Project (netty-dev@lists.jboss.org) + * @author Trustin Lee (tlee@redhat.com) + * + * @version $Rev$, $Date$ + * + */ +public abstract class AbstractSocketFixedLengthEchoTest { + + private static final Random random = new Random(); + static final byte[] data = new byte[1048576]; + + private static ExecutorService executor; + + static { + random.nextBytes(data); + } + + @BeforeClass + public static void init() { + executor = Executors.newCachedThreadPool(); + } + + @AfterClass + public static void destroy() { + executor.shutdown(); + for (;;) { + try { + if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) { + break; + } + } catch (InterruptedException e) { + // Ignore. + } + } + } + + protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); + protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); + + @Test + public void testFixedLengthEcho() throws Throwable { + ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); + ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); + + EchoHandler sh = new EchoHandler(); + EchoHandler ch = new EchoHandler(); + + sb.getPipeline().addLast("decoder", new FixedLengthFrameDecoder(1024)); + sb.getPipeline().addAfter("decoder", "handler", sh); + cb.getPipeline().addLast("decoder", new FixedLengthFrameDecoder(1024)); + cb.getPipeline().addAfter("decoder", "handler", ch); + + Channel sc = sb.bind(new InetSocketAddress(0)); + int port = ((InetSocketAddress) sc.getLocalAddress()).getPort(); + + ChannelFuture ccf = cb.connect(new InetSocketAddress(InetAddress.getLocalHost(), port)); + assertTrue(ccf.awaitUninterruptibly().isSuccess()); + + Channel cc = ccf.getChannel(); + for (int i = 0; i < data.length;) { + int length = Math.min(random.nextInt(1024 * 64), data.length - i); + cc.write(ChannelBuffers.wrappedBuffer(data, i, length)); + i += length; + } + + while (ch.counter < data.length) { + if (sh.exception.get() != null) { + break; + } + if (ch.exception.get() != null) { + break; + } + + try { + Thread.sleep(1); + } catch (InterruptedException e) { + // Ignore. + } + } + + while (sh.counter < data.length) { + if (sh.exception.get() != null) { + break; + } + if (ch.exception.get() != null) { + break; + } + + try { + Thread.sleep(1); + } catch (InterruptedException e) { + // Ignore. + } + } + + ch.channel.close().awaitUninterruptibly(); + sh.channel.close().awaitUninterruptibly(); + sc.close().awaitUninterruptibly(); + + if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { + throw sh.exception.get(); + } + if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { + throw ch.exception.get(); + } + if (sh.exception.get() != null) { + throw sh.exception.get(); + } + if (ch.exception.get() != null) { + throw ch.exception.get(); + } + } + + @ChannelPipelineCoverage("one") + private class EchoHandler extends SimpleChannelHandler { + volatile Channel channel; + final AtomicReference exception = new AtomicReference(); + volatile int counter; + + EchoHandler() { + super(); + } + + @Override + public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) + throws Exception { + channel = e.getChannel(); + } + + @Override + public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) + throws Exception { + ChannelBuffer m = (ChannelBuffer) e.getMessage(); + assertEquals(1024, m.readableBytes()); + + byte[] actual = new byte[m.readableBytes()]; + m.getBytes(0, actual); + + int lastIdx = counter; + for (int i = 0; i < actual.length; i ++) { + assertEquals(data[i + lastIdx], actual[i]); + } + counter += actual.length; + + if (channel.getParent() != null) { + channel.write(m); + } + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) + throws Exception { + if (exception.compareAndSet(null, e.getCause())) { + e.getChannel().close(); + } + } + } +} diff --git a/src/test/java/org/jboss/netty/handler/frame/NioNioSocketFixedLengthEchoTest.java b/src/test/java/org/jboss/netty/handler/frame/NioNioSocketFixedLengthEchoTest.java new file mode 100644 index 0000000000..79adf3ec77 --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/frame/NioNioSocketFixedLengthEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.frame; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; +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 NioNioSocketFixedLengthEchoTest extends AbstractSocketFixedLengthEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new NioClientSocketChannelFactory(executor, executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new NioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/frame/NioOioSocketFixedLengthEchoTest.java b/src/test/java/org/jboss/netty/handler/frame/NioOioSocketFixedLengthEchoTest.java new file mode 100644 index 0000000000..e2faee4d80 --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/frame/NioOioSocketFixedLengthEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.frame; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; +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 NioOioSocketFixedLengthEchoTest extends AbstractSocketFixedLengthEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new NioClientSocketChannelFactory(executor, executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new OioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/frame/OioNioSocketFixedLengthEchoTest.java b/src/test/java/org/jboss/netty/handler/frame/OioNioSocketFixedLengthEchoTest.java new file mode 100644 index 0000000000..9333557c05 --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/frame/OioNioSocketFixedLengthEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.frame; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; +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 OioNioSocketFixedLengthEchoTest extends AbstractSocketFixedLengthEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new OioClientSocketChannelFactory(executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new NioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/frame/OioOioSocketFixedLengthEchoTest.java b/src/test/java/org/jboss/netty/handler/frame/OioOioSocketFixedLengthEchoTest.java new file mode 100644 index 0000000000..e7b22a0770 --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/frame/OioOioSocketFixedLengthEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.frame; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; +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 OioOioSocketFixedLengthEchoTest extends AbstractSocketFixedLengthEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new OioClientSocketChannelFactory(executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new OioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/serialization/AbstractSocketCompatibleObjectStreamEchoTest.java b/src/test/java/org/jboss/netty/handler/serialization/AbstractSocketCompatibleObjectStreamEchoTest.java new file mode 100644 index 0000000000..2c6ebcc4de --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/serialization/AbstractSocketCompatibleObjectStreamEchoTest.java @@ -0,0 +1,217 @@ +/* + * 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.handler.serialization; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.util.Random; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.jboss.netty.bootstrap.ClientBootstrap; +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.ChannelFuture; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.channel.ChannelPipelineCoverage; +import org.jboss.netty.channel.ChannelStateEvent; +import org.jboss.netty.channel.ExceptionEvent; +import org.jboss.netty.channel.MessageEvent; +import org.jboss.netty.channel.SimpleChannelHandler; +import org.jboss.netty.handler.codec.serialization.CompatibleObjectDecoder; +import org.jboss.netty.handler.codec.serialization.CompatibleObjectEncoder; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + + +/** + * @author The Netty Project (netty-dev@lists.jboss.org) + * @author Trustin Lee (tlee@redhat.com) + * + * @version $Rev$, $Date$ + * + */ +public abstract class AbstractSocketCompatibleObjectStreamEchoTest { + + static final Random random = new Random(); + static final String[] data = new String[1024]; + + private static ExecutorService executor; + + static { + for (int i = 0; i < data.length; i ++) { + int eLen = random.nextInt(512); + StringBuilder e = new StringBuilder(eLen); + + for (int j = 0; j < eLen; j ++) { + e.append((char) ('a' + random.nextInt(26))); + } + + data[i] = e.toString(); + } + } + + @BeforeClass + public static void init() { + executor = Executors.newCachedThreadPool(); + } + + @AfterClass + public static void destroy() { + executor.shutdown(); + for (;;) { + try { + if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) { + break; + } + } catch (InterruptedException e) { + // Ignore. + } + } + } + + protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); + protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); + + @Test + public void testCompatibleObjectEcho() throws Throwable { + ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); + ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); + + EchoHandler sh = new EchoHandler(); + EchoHandler ch = new EchoHandler(); + + sb.getPipeline().addLast("decoder", new CompatibleObjectDecoder()); + sb.getPipeline().addLast("encoder", new CompatibleObjectEncoder()); + sb.getPipeline().addLast("handler", sh); + + cb.getPipeline().addLast("decoder", new CompatibleObjectDecoder()); + cb.getPipeline().addLast("encoder", new CompatibleObjectEncoder()); + cb.getPipeline().addLast("handler", ch); + + Channel sc = sb.bind(new InetSocketAddress(0)); + int port = ((InetSocketAddress) sc.getLocalAddress()).getPort(); + + ChannelFuture ccf = cb.connect(new InetSocketAddress(InetAddress.getLocalHost(), port)); + assertTrue(ccf.awaitUninterruptibly().isSuccess()); + + Channel cc = ccf.getChannel(); + for (String element : data) { + cc.write(element); + } + + while (ch.counter < data.length) { + if (sh.exception.get() != null) { + break; + } + if (ch.exception.get() != null) { + break; + } + + try { + Thread.sleep(1); + } catch (InterruptedException e) { + // Ignore. + } + } + + while (sh.counter < data.length) { + if (sh.exception.get() != null) { + break; + } + if (ch.exception.get() != null) { + break; + } + + try { + Thread.sleep(1); + } catch (InterruptedException e) { + // Ignore. + } + } + + ch.channel.close().awaitUninterruptibly(); + sh.channel.close().awaitUninterruptibly(); + sc.close().awaitUninterruptibly(); + + if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { + throw sh.exception.get(); + } + if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { + throw ch.exception.get(); + } + if (sh.exception.get() != null) { + throw sh.exception.get(); + } + if (ch.exception.get() != null) { + throw ch.exception.get(); + } + } + + @ChannelPipelineCoverage("one") + private class EchoHandler extends SimpleChannelHandler { + volatile Channel channel; + final AtomicReference exception = new AtomicReference(); + volatile int counter; + + EchoHandler() { + super(); + } + + @Override + public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) + throws Exception { + channel = e.getChannel(); + } + + @Override + public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) + throws Exception { + + String m = (String) e.getMessage(); + assertEquals(data[counter], m); + + counter ++; + + if (channel.getParent() != null) { + channel.write(m); + } + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) + throws Exception { + if (exception.compareAndSet(null, e.getCause())) { + e.getChannel().close(); + } + } + } +} diff --git a/src/test/java/org/jboss/netty/handler/serialization/AbstractSocketObjectStreamEchoTest.java b/src/test/java/org/jboss/netty/handler/serialization/AbstractSocketObjectStreamEchoTest.java new file mode 100644 index 0000000000..bb164b609c --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/serialization/AbstractSocketObjectStreamEchoTest.java @@ -0,0 +1,217 @@ +/* + * 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.handler.serialization; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.util.Random; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.jboss.netty.bootstrap.ClientBootstrap; +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.ChannelFuture; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.channel.ChannelPipelineCoverage; +import org.jboss.netty.channel.ChannelStateEvent; +import org.jboss.netty.channel.ExceptionEvent; +import org.jboss.netty.channel.MessageEvent; +import org.jboss.netty.channel.SimpleChannelHandler; +import org.jboss.netty.handler.codec.serialization.ObjectDecoder; +import org.jboss.netty.handler.codec.serialization.ObjectEncoder; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + + +/** + * @author The Netty Project (netty-dev@lists.jboss.org) + * @author Trustin Lee (tlee@redhat.com) + * + * @version $Rev$, $Date$ + * + */ +public abstract class AbstractSocketObjectStreamEchoTest { + + static final Random random = new Random(); + static final String[] data = new String[32768]; + + private static ExecutorService executor; + + static { + for (int i = 0; i < data.length; i ++) { + int eLen = random.nextInt(512); + StringBuilder e = new StringBuilder(eLen); + + for (int j = 0; j < eLen; j ++) { + e.append((char) ('a' + random.nextInt(26))); + } + + data[i] = e.toString(); + } + } + + @BeforeClass + public static void init() { + executor = Executors.newCachedThreadPool(); + } + + @AfterClass + public static void destroy() { + executor.shutdown(); + for (;;) { + try { + if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) { + break; + } + } catch (InterruptedException e) { + // Ignore. + } + } + } + + protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); + protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); + + @Test + public void testObjectEcho() throws Throwable { + ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); + ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); + + EchoHandler sh = new EchoHandler(); + EchoHandler ch = new EchoHandler(); + + sb.getPipeline().addLast("decoder", new ObjectDecoder()); + sb.getPipeline().addLast("encoder", new ObjectEncoder()); + sb.getPipeline().addLast("handler", sh); + + cb.getPipeline().addLast("decoder", new ObjectDecoder()); + cb.getPipeline().addLast("encoder", new ObjectEncoder()); + cb.getPipeline().addLast("handler", ch); + + Channel sc = sb.bind(new InetSocketAddress(0)); + int port = ((InetSocketAddress) sc.getLocalAddress()).getPort(); + + ChannelFuture ccf = cb.connect(new InetSocketAddress(InetAddress.getLocalHost(), port)); + assertTrue(ccf.awaitUninterruptibly().isSuccess()); + + Channel cc = ccf.getChannel(); + for (String element : data) { + cc.write(element); + } + + while (ch.counter < data.length) { + if (sh.exception.get() != null) { + break; + } + if (ch.exception.get() != null) { + break; + } + + try { + Thread.sleep(1); + } catch (InterruptedException e) { + // Ignore. + } + } + + while (sh.counter < data.length) { + if (sh.exception.get() != null) { + break; + } + if (ch.exception.get() != null) { + break; + } + + try { + Thread.sleep(1); + } catch (InterruptedException e) { + // Ignore. + } + } + + ch.channel.close().awaitUninterruptibly(); + sh.channel.close().awaitUninterruptibly(); + sc.close().awaitUninterruptibly(); + + if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { + throw sh.exception.get(); + } + if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { + throw ch.exception.get(); + } + if (sh.exception.get() != null) { + throw sh.exception.get(); + } + if (ch.exception.get() != null) { + throw ch.exception.get(); + } + } + + @ChannelPipelineCoverage("one") + private class EchoHandler extends SimpleChannelHandler { + volatile Channel channel; + final AtomicReference exception = new AtomicReference(); + volatile int counter; + + EchoHandler() { + super(); + } + + @Override + public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) + throws Exception { + channel = e.getChannel(); + } + + @Override + public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) + throws Exception { + + String m = (String) e.getMessage(); + assertEquals(data[counter], m); + + counter ++; + + if (channel.getParent() != null) { + channel.write(m); + } + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) + throws Exception { + if (exception.compareAndSet(null, e.getCause())) { + e.getChannel().close(); + } + } + } +} diff --git a/src/test/java/org/jboss/netty/handler/serialization/NioNioSocketCompatibleObjectStreamEchoTest.java b/src/test/java/org/jboss/netty/handler/serialization/NioNioSocketCompatibleObjectStreamEchoTest.java new file mode 100644 index 0000000000..7f036e2d4f --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/serialization/NioNioSocketCompatibleObjectStreamEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.serialization; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; +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 NioNioSocketCompatibleObjectStreamEchoTest extends AbstractSocketCompatibleObjectStreamEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new NioClientSocketChannelFactory(executor, executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new NioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/serialization/NioNioSocketObjectStreamEchoTest.java b/src/test/java/org/jboss/netty/handler/serialization/NioNioSocketObjectStreamEchoTest.java new file mode 100644 index 0000000000..2e570038a7 --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/serialization/NioNioSocketObjectStreamEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.serialization; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; +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 NioNioSocketObjectStreamEchoTest extends AbstractSocketObjectStreamEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new NioClientSocketChannelFactory(executor, executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new NioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/serialization/NioOioSocketCompatibleObjectStreamEchoTest.java b/src/test/java/org/jboss/netty/handler/serialization/NioOioSocketCompatibleObjectStreamEchoTest.java new file mode 100644 index 0000000000..621665575b --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/serialization/NioOioSocketCompatibleObjectStreamEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.serialization; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; +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 NioOioSocketCompatibleObjectStreamEchoTest extends AbstractSocketCompatibleObjectStreamEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new NioClientSocketChannelFactory(executor, executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new OioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/serialization/NioOioSocketObjectStreamEchoTest.java b/src/test/java/org/jboss/netty/handler/serialization/NioOioSocketObjectStreamEchoTest.java new file mode 100644 index 0000000000..a50cfd58b6 --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/serialization/NioOioSocketObjectStreamEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.serialization; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; +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 NioOioSocketObjectStreamEchoTest extends AbstractSocketObjectStreamEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new NioClientSocketChannelFactory(executor, executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new OioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/serialization/OioNioSocketCompatibleObjectStreamEchoTest.java b/src/test/java/org/jboss/netty/handler/serialization/OioNioSocketCompatibleObjectStreamEchoTest.java new file mode 100644 index 0000000000..50ae25aa42 --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/serialization/OioNioSocketCompatibleObjectStreamEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.serialization; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; +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 OioNioSocketCompatibleObjectStreamEchoTest extends AbstractSocketCompatibleObjectStreamEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new OioClientSocketChannelFactory(executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new NioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/serialization/OioNioSocketObjectStreamEchoTest.java b/src/test/java/org/jboss/netty/handler/serialization/OioNioSocketObjectStreamEchoTest.java new file mode 100644 index 0000000000..3e571e4f7c --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/serialization/OioNioSocketObjectStreamEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.serialization; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; +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 OioNioSocketObjectStreamEchoTest extends AbstractSocketObjectStreamEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new OioClientSocketChannelFactory(executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new NioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/serialization/OioOioSocketCompatibleObjectStreamEchoTest.java b/src/test/java/org/jboss/netty/handler/serialization/OioOioSocketCompatibleObjectStreamEchoTest.java new file mode 100644 index 0000000000..bdf0762282 --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/serialization/OioOioSocketCompatibleObjectStreamEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.serialization; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; +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 OioOioSocketCompatibleObjectStreamEchoTest extends AbstractSocketCompatibleObjectStreamEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new OioClientSocketChannelFactory(executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new OioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/serialization/OioOioSocketObjectStreamEchoTest.java b/src/test/java/org/jboss/netty/handler/serialization/OioOioSocketObjectStreamEchoTest.java new file mode 100644 index 0000000000..ac0e6db6df --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/serialization/OioOioSocketObjectStreamEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.serialization; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; +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 OioOioSocketObjectStreamEchoTest extends AbstractSocketObjectStreamEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new OioClientSocketChannelFactory(executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new OioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/ssl/AbstractSocketSslEchoTest.java b/src/test/java/org/jboss/netty/handler/ssl/AbstractSocketSslEchoTest.java index b479a4991c..088bef1cf5 100644 --- a/src/test/java/org/jboss/netty/handler/ssl/AbstractSocketSslEchoTest.java +++ b/src/test/java/org/jboss/netty/handler/ssl/AbstractSocketSslEchoTest.java @@ -24,6 +24,7 @@ package org.jboss.netty.handler.ssl; import static org.junit.Assert.*; +import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.Random; @@ -31,6 +32,7 @@ import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; import javax.net.ssl.SSLEngine; @@ -63,7 +65,7 @@ import org.junit.Test; public abstract class AbstractSocketSslEchoTest { private static final Random random = new Random(); - static final byte[] data = new byte[1048576 * 32]; + static final byte[] data = new byte[1048576]; private static ExecutorService executor; @@ -94,7 +96,7 @@ public abstract class AbstractSocketSslEchoTest { protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); @Test - public void testEcho() throws Throwable { + public void testSslEcho() throws Throwable { ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); @@ -121,13 +123,34 @@ public abstract class AbstractSocketSslEchoTest { assertTrue(cc.getPipeline().get(SslHandler.class).handshake(cc).awaitUninterruptibly().isSuccess()); for (int i = 0; i < data.length;) { - int length = Math.min(random.nextInt(1024 * 512), data.length - i); + int length = Math.min(random.nextInt(1024 * 64), data.length - i); cc.write(ChannelBuffers.wrappedBuffer(data, i, length)); i += length; } while (ch.counter < data.length) { - assertNull(ch.exception); + if (sh.exception.get() != null) { + break; + } + if (ch.exception.get() != null) { + break; + } + + try { + Thread.sleep(1); + } catch (InterruptedException e) { + // Ignore. + } + } + + while (sh.counter < data.length) { + if (sh.exception.get() != null) { + break; + } + if (ch.exception.get() != null) { + break; + } + try { Thread.sleep(1); } catch (InterruptedException e) { @@ -136,27 +159,27 @@ public abstract class AbstractSocketSslEchoTest { } ch.channel.close().awaitUninterruptibly(); - - while (sh.counter < data.length) { - assertNull(sh.exception); - try { - Thread.sleep(1); - } catch (InterruptedException e) { - // Ignore. - } - } - sh.channel.close().awaitUninterruptibly(); sc.close().awaitUninterruptibly(); - assertNull(sh.exception); - assertNull(ch.exception); + if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { + throw sh.exception.get(); + } + if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { + throw ch.exception.get(); + } + if (sh.exception.get() != null) { + throw sh.exception.get(); + } + if (ch.exception.get() != null) { + throw ch.exception.get(); + } } @ChannelPipelineCoverage("one") private class EchoHandler extends SimpleChannelHandler { volatile Channel channel; - volatile Throwable exception; + final AtomicReference exception = new AtomicReference(); volatile int counter; EchoHandler() { @@ -190,8 +213,9 @@ public abstract class AbstractSocketSslEchoTest { @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { - exception = e.getCause(); - e.getChannel().close(); + if (exception.compareAndSet(null, e.getCause())) { + e.getChannel().close(); + } } } } diff --git a/src/test/java/org/jboss/netty/handler/ssl/OioOioSocketSslEchoTest.java b/src/test/java/org/jboss/netty/handler/ssl/OioOioSocketSslEchoTest.java index 9a6ff6f595..a048036d21 100644 --- a/src/test/java/org/jboss/netty/handler/ssl/OioOioSocketSslEchoTest.java +++ b/src/test/java/org/jboss/netty/handler/ssl/OioOioSocketSslEchoTest.java @@ -50,7 +50,7 @@ public class OioOioSocketSslEchoTest extends AbstractSocketSslEchoTest { @Test @Override - public void testEcho() throws Throwable { + public void testSslEcho() throws Throwable { // FIXME Disabled temporarily } } diff --git a/src/test/java/org/jboss/netty/handler/string/AbstractSocketStringEchoTest.java b/src/test/java/org/jboss/netty/handler/string/AbstractSocketStringEchoTest.java new file mode 100644 index 0000000000..9592942b2d --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/string/AbstractSocketStringEchoTest.java @@ -0,0 +1,223 @@ +/* + * 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.handler.string; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.util.Random; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import org.jboss.netty.bootstrap.ClientBootstrap; +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.ChannelFuture; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.channel.ChannelPipelineCoverage; +import org.jboss.netty.channel.ChannelStateEvent; +import org.jboss.netty.channel.ExceptionEvent; +import org.jboss.netty.channel.MessageEvent; +import org.jboss.netty.channel.SimpleChannelHandler; +import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; +import org.jboss.netty.handler.codec.frame.Delimiters; +import org.jboss.netty.handler.codec.string.StringDecoder; +import org.jboss.netty.handler.codec.string.StringEncoder; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + + +/** + * @author The Netty Project (netty-dev@lists.jboss.org) + * @author Trustin Lee (tlee@redhat.com) + * + * @version $Rev$, $Date$ + * + */ +public abstract class AbstractSocketStringEchoTest { + + static final Random random = new Random(); + static final String[] data = new String[1024]; + + private static ExecutorService executor; + + static { + for (int i = 0; i < data.length; i ++) { + int eLen = random.nextInt(512); + StringBuilder e = new StringBuilder(eLen); + + for (int j = 0; j < eLen; j ++) { + e.append((char) ('a' + random.nextInt(26))); + } + + data[i] = e.toString(); + } + } + + @BeforeClass + public static void init() { + executor = Executors.newCachedThreadPool(); + } + + @AfterClass + public static void destroy() { + executor.shutdown(); + for (;;) { + try { + if (executor.awaitTermination(1, TimeUnit.MILLISECONDS)) { + break; + } + } catch (InterruptedException e) { + // Ignore. + } + } + } + + protected abstract ChannelFactory newServerSocketChannelFactory(Executor executor); + protected abstract ChannelFactory newClientSocketChannelFactory(Executor executor); + + @Test + public void testStringEcho() throws Throwable { + ServerBootstrap sb = new ServerBootstrap(newServerSocketChannelFactory(executor)); + ClientBootstrap cb = new ClientBootstrap(newClientSocketChannelFactory(executor)); + + EchoHandler sh = new EchoHandler(); + EchoHandler ch = new EchoHandler(); + + sb.getPipeline().addLast("framer", new DelimiterBasedFrameDecoder(512, Delimiters.lineDelimiter())); + sb.getPipeline().addLast("decoder", new StringDecoder("ISO-8859-1")); + sb.getPipeline().addBefore("decoder", "encoder", new StringEncoder("ISO-8859-1")); + sb.getPipeline().addAfter("decoder", "handler", sh); + + cb.getPipeline().addLast("framer", new DelimiterBasedFrameDecoder(512, Delimiters.lineDelimiter())); + cb.getPipeline().addLast("decoder", new StringDecoder("ISO-8859-1")); + cb.getPipeline().addBefore("decoder", "encoder", new StringEncoder("ISO-8859-1")); + cb.getPipeline().addAfter("decoder", "handler", ch); + + Channel sc = sb.bind(new InetSocketAddress(0)); + int port = ((InetSocketAddress) sc.getLocalAddress()).getPort(); + + ChannelFuture ccf = cb.connect(new InetSocketAddress(InetAddress.getLocalHost(), port)); + assertTrue(ccf.awaitUninterruptibly().isSuccess()); + + Channel cc = ccf.getChannel(); + for (String element : data) { + String delimiter = random.nextBoolean() ? "\r\n" : "\n"; + cc.write(element + delimiter); + } + + while (ch.counter < data.length) { + if (sh.exception.get() != null) { + break; + } + if (ch.exception.get() != null) { + break; + } + + try { + Thread.sleep(1); + } catch (InterruptedException e) { + // Ignore. + } + } + + while (sh.counter < data.length) { + if (sh.exception.get() != null) { + break; + } + if (ch.exception.get() != null) { + break; + } + + try { + Thread.sleep(1); + } catch (InterruptedException e) { + // Ignore. + } + } + + ch.channel.close().awaitUninterruptibly(); + sh.channel.close().awaitUninterruptibly(); + sc.close().awaitUninterruptibly(); + + if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) { + throw sh.exception.get(); + } + if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) { + throw ch.exception.get(); + } + if (sh.exception.get() != null) { + throw sh.exception.get(); + } + if (ch.exception.get() != null) { + throw ch.exception.get(); + } + } + + @ChannelPipelineCoverage("one") + private class EchoHandler extends SimpleChannelHandler { + volatile Channel channel; + final AtomicReference exception = new AtomicReference(); + volatile int counter; + + EchoHandler() { + super(); + } + + @Override + public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) + throws Exception { + channel = e.getChannel(); + } + + @Override + public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) + throws Exception { + + String m = (String) e.getMessage(); + assertEquals(data[counter], m); + + counter ++; + + if (channel.getParent() != null) { + String delimiter = random.nextBoolean() ? "\r\n" : "\n"; + channel.write(m + delimiter); + } + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) + throws Exception { + if (exception.compareAndSet(null, e.getCause())) { + e.getChannel().close(); + } + } + } +} diff --git a/src/test/java/org/jboss/netty/handler/string/NioNioSocketStringEchoTest.java b/src/test/java/org/jboss/netty/handler/string/NioNioSocketStringEchoTest.java new file mode 100644 index 0000000000..b34d34338e --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/string/NioNioSocketStringEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.string; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; +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 NioNioSocketStringEchoTest extends AbstractSocketStringEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new NioClientSocketChannelFactory(executor, executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new NioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/string/NioOioSocketStringEchoTest.java b/src/test/java/org/jboss/netty/handler/string/NioOioSocketStringEchoTest.java new file mode 100644 index 0000000000..850006536c --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/string/NioOioSocketStringEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.string; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; +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 NioOioSocketStringEchoTest extends AbstractSocketStringEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new NioClientSocketChannelFactory(executor, executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new OioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/string/OioNioSocketStringEchoTest.java b/src/test/java/org/jboss/netty/handler/string/OioNioSocketStringEchoTest.java new file mode 100644 index 0000000000..6dc13a6498 --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/string/OioNioSocketStringEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.string; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; +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 OioNioSocketStringEchoTest extends AbstractSocketStringEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new OioClientSocketChannelFactory(executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new NioServerSocketChannelFactory(executor, executor); + } + +} diff --git a/src/test/java/org/jboss/netty/handler/string/OioOioSocketStringEchoTest.java b/src/test/java/org/jboss/netty/handler/string/OioOioSocketStringEchoTest.java new file mode 100644 index 0000000000..10f416e618 --- /dev/null +++ b/src/test/java/org/jboss/netty/handler/string/OioOioSocketStringEchoTest.java @@ -0,0 +1,50 @@ +/* + * 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.handler.string; + +import java.util.concurrent.Executor; + +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; +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 OioOioSocketStringEchoTest extends AbstractSocketStringEchoTest { + + @Override + protected ChannelFactory newClientSocketChannelFactory(Executor executor) { + return new OioClientSocketChannelFactory(executor); + } + + @Override + protected ChannelFactory newServerSocketChannelFactory(Executor executor) { + return new OioServerSocketChannelFactory(executor, executor); + } + +}