You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tr...@apache.org on 2005/12/01 06:19:07 UTC

svn commit: r350169 [15/16] - in /directory/network: branches/chain_refactor/src/java/org/apache/mina/common/ trunk/src/examples/org/apache/mina/examples/echoserver/ trunk/src/examples/org/apache/mina/examples/httpserver/ trunk/src/examples/org/apache/...

Modified: directory/network/trunk/src/test/org/apache/mina/common/FutureTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/common/FutureTest.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/common/FutureTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/common/FutureTest.java Wed Nov 30 21:17:41 2005
@@ -73,26 +73,11 @@
                 return null;
             }
 
-            public WriteFuture write( Object message )
-            {
-                return null;
-            }
-
-            public CloseFuture close()
-            {
-                return null;
-            }
-
             public TransportType getTransportType()
             {
                 return null;
             }
 
-            public boolean isConnected()
-            {
-                return false;
-            }
-
             public SocketAddress getRemoteAddress()
             {
                 return null;
@@ -115,6 +100,11 @@
             public boolean isClosing()
             {
                 return false;
+            }
+
+            public IoSessionManager getManager()
+            {
+                return null;
             }
         };
         

Modified: directory/network/trunk/src/test/org/apache/mina/common/IoFilterChainTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/common/IoFilterChainTest.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/common/IoFilterChainTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/common/IoFilterChainTest.java Wed Nov 30 21:17:41 2005
@@ -1,305 +1,439 @@
-/*
- *   @(#) $Id$
- *
- *   Copyright 2004 The Apache Software Foundation
- *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- *
- */
-package org.apache.mina.common;
-
-import java.net.SocketAddress;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.mina.common.IoFilter.WriteRequest;
-import org.apache.mina.common.support.AbstractIoFilterChain;
-import org.apache.mina.common.support.BaseIoSession;
-
-/**
- * Tests {@link AbstractIoFilterChain}.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$ 
- */
-public class IoFilterChainTest extends TestCase
-{
-    private IoFilterChainImpl chain;
-    private IoSession session;
-    private String result;
-
-    public void setUp()
-    {
-        chain = new IoFilterChainImpl();
-        session = new TestSession();
-        result = "";
-    }
-    
-    public void tearDown()
-    {
-    }
-    
-    public void testDefault()
-    {
-        run( "HS0 HSO HMR HMS HSI HEC HSC" );
-    }
-    
-    public void testChained() throws Exception
-    {
-        chain.addLast( "A", new EventOrderTestFilter( 'A' ) );
-        chain.addLast( "B", new EventOrderTestFilter( 'B' ) );
-        run( "AS0 BS0 HS0" +
-             "ASO BSO HSO" +
-             "AMR BMR HMR" +
-             "BFW AFW AMS BMS HMS" +
-             "ASI BSI HSI" +
-             "AEC BEC HEC" +
-             "ASC BSC HSC" );
-    }
-    
-    public void testAddRemove() throws Exception
-    {
-        IoFilter filter = new AddRemoveTestFilter();
-
-        chain.addFirst( "A", filter );
-        assertEquals( "ADDED", result );
-        
-        chain.remove( "A" );
-        assertEquals( "ADDEDREMOVED", result );
-    }
-    
-    private void run( String expectedResult )
-    {
-        chain.sessionCreated( session );
-        chain.sessionOpened( session );
-        chain.messageReceived( session, new Object() );
-        chain.filterWrite( session, new WriteRequest( new Object() ) );
-        chain.sessionIdle( session, IdleStatus.READER_IDLE );
-        chain.exceptionCaught( session, new Exception() );
-        chain.sessionClosed( session );
-        
-        result = formatResult( result );
-        expectedResult = formatResult( expectedResult );
-        
-        System.out.println( "Expected: " + expectedResult );
-        System.out.println( "Actual:   " + result );
-        Assert.assertEquals( expectedResult, result );
-    }
-    
-    private String formatResult( String result )
-    {
-        result = result.replaceAll( "\\s", "" );
-        StringBuffer buf = new StringBuffer( result.length() * 4 / 3 );
-        for( int i = 0; i < result.length(); i++ )
-        {
-            buf.append( result.charAt( i ) );
-            if( i % 3 == 2 )
-            {
-                buf.append(' ');
-            }
-        }
-        
-        return buf.toString();
-    }
-
-    private class TestSession extends BaseIoSession implements IoSession
-    {
-        private IoHandler handler = new IoHandlerAdapter()
-        {
-            public void sessionCreated(IoSession session) {
-                result += "HS0";
-            }
-
-            public void sessionOpened(IoSession session) {
-                result += "HSO";
-            }
-
-            public void sessionClosed(IoSession session) {
-                result += "HSC";
-            }
-
-            public void sessionIdle(IoSession session, IdleStatus status) {
-                result += "HSI";
-            }
-
-            public void exceptionCaught(IoSession session, Throwable cause) {
-                result += "HEC";
-                if( cause.getClass() != Exception.class )
-                {
-                    cause.printStackTrace( System.out );
-                }
-            }
-
-            public void messageReceived(IoSession session, Object message) {
-                result += "HMR";
-            }
-
-            public void messageSent(IoSession session, Object message) {
-                result += "HMS";
-            }
-        };
-
-        public IoHandler getHandler() {
-            return handler;
-        }
-
-        public CloseFuture close() {
-            return null;
-        }
-
-        public WriteFuture write(Object message) {
-            return null;
-        }
-
-        public TransportType getTransportType() {
-            return TransportType.VM_PIPE;
-        }
-
-        public boolean isConnected() {
-            return false;
-        }
-
-        public SocketAddress getRemoteAddress() {
-            return null;
-        }
-
-        public SocketAddress getLocalAddress() {
-            return null;
-        }
-
-        public IoFilterChain getFilterChain()
-        {
-            return new AbstractIoFilterChain( this )
-            {
-                protected void doWrite( IoSession session, WriteRequest writeRequest )
-                {
-                }
-
-                protected void doClose( IoSession session, CloseFuture closeFuture )
-                {
-                }
-            };
-        }
-
-        public int getScheduledWriteRequests()
-        {
-            return 0;
-        }
-
-        protected void updateTrafficMask()
-        {
-        }
-
-        public boolean isClosing()
-        {
-            return false;
-        }
-    }
-
-    private class EventOrderTestFilter implements IoFilter
-    {
-        private final char id;
-
-        private EventOrderTestFilter( char id )
-        {
-            this.id = id;
-        }
-        
-        public void sessionCreated( NextFilter nextFilter, IoSession session )
-        {
-            result += id + "S0";
-            nextFilter.sessionCreated( session );
-        }
-
-        public void sessionOpened( NextFilter nextFilter, IoSession session )
-        {
-            result += id + "SO";
-            nextFilter.sessionOpened( session );
-        }
-
-        public void sessionClosed(NextFilter nextFilter, IoSession session) {
-            result += id + "SC";
-            nextFilter.sessionClosed( session );
-        }
-
-        public void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status) {
-            result += id + "SI";
-            nextFilter.sessionIdle( session, status );
-        }
-
-        public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) {
-            result += id + "EC";
-            nextFilter.exceptionCaught( session, cause );
-        }
-
-        public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest ) {
-            result += id + "FW";
-            nextFilter.filterWrite( session, writeRequest );
-        }
-
-        public void messageReceived(NextFilter nextFilter, IoSession session, Object message) {
-            result += id + "MR";
-            nextFilter.messageReceived( session, message );
-        }
-
-        public void messageSent(NextFilter nextFilter, IoSession session, Object message) {
-            result += id + "MS";
-            nextFilter.messageSent( session, message );
-        }
-
-        public void filterClose( NextFilter nextFilter, IoSession session, CloseFuture closeFuture ) throws Exception
-        {
-            nextFilter.filterClose( session, closeFuture );
-        }
-
-        public void init( IoFilterChain parent, NextFilter nextFilter ) throws Exception
-        {
-        }
-
-        public void destroy( IoFilterChain parent, NextFilter nextFilter ) throws Exception
-        {
-        }
-    }
-
-    private class AddRemoveTestFilter extends IoFilterAdapter
-    {
-        public void init( IoFilterChain parent, NextFilter nextFilter )
-        {
-            result += "ADDED";
-        }
-        
-        public void destroy( IoFilterChain parent, NextFilter nextFilter )
-        {
-            result += "REMOVED";
-        }
-    }
-
-    private static class IoFilterChainImpl extends AbstractIoFilterChain
-    {
-        protected IoFilterChainImpl()
-        {
-            super( new Object() );
-        }
-
-        protected void doWrite( IoSession session, WriteRequest writeRequest )
-        {
-            messageSent( session, writeRequest.getMessage() );
-        }
-
-        protected void doClose( IoSession session, CloseFuture closeFuture )
-        {
-        }
-    }
-    
-}
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.common;
+
+import java.net.SocketAddress;
+import java.util.Iterator;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.mina.common.IoFilter.WriteRequest;
+import org.apache.mina.common.IoFilterChain.Entry;
+import org.apache.mina.common.support.AbstractIoFilterChain;
+import org.apache.mina.common.support.BaseIoSession;
+
+/**
+ * Tests {@link AbstractIoFilterChain}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$ 
+ */
+public class IoFilterChainTest extends TestCase
+{
+    private IoFilterChainImpl chain;
+    private IoSession session;
+    private String result;
+
+    public void setUp()
+    {
+        chain = new IoFilterChainImpl();
+        session = new TestSession();
+        result = "";
+    }
+    
+    public void tearDown()
+    {
+    }
+    
+    public void testAdd() throws Exception
+    {
+        chain.addFirst( "A", new EventOrderTestFilter( 'A' ) );
+        chain.addLast( "B", new EventOrderTestFilter( 'A' ) );
+        chain.addFirst( "C", new EventOrderTestFilter( 'A' ) );
+        chain.addLast( "D", new EventOrderTestFilter( 'A' ) );
+        chain.addBefore( "B", "E", new EventOrderTestFilter( 'A' ) );
+        chain.addBefore( "C", "F", new EventOrderTestFilter( 'A' ) );
+        chain.addAfter( "B", "G", new EventOrderTestFilter( 'A' ) );
+        chain.addAfter( "D", "H", new EventOrderTestFilter( 'A' ) );
+        
+        String actual = "";
+        for( Iterator i = chain.getAll().iterator(); i.hasNext(); ) 
+        {
+            Entry e = ( Entry ) i.next();
+            actual += e.getName();
+        }
+        
+        Assert.assertEquals( "FCAEBGDH", actual );
+    }
+    
+    public void testGet() throws Exception
+    {
+        IoFilter filterA = new IoFilterAdapter();
+        IoFilter filterB = new IoFilterAdapter();
+        IoFilter filterC = new IoFilterAdapter();
+        IoFilter filterD = new IoFilterAdapter();
+        
+        chain.addFirst( "A", filterA );
+        chain.addLast( "B", filterB );
+        chain.addBefore( "B", "C", filterC );
+        chain.addAfter( "A", "D", filterD );
+        
+        Assert.assertSame( filterA, chain.get( "A" ) );
+        Assert.assertSame( filterB, chain.get( "B" ) );
+        Assert.assertSame( filterC, chain.get( "C" ) );
+        Assert.assertSame( filterD, chain.get( "D" ) );
+    }
+    
+    public void testRemove() throws Exception
+    {
+        chain.addLast( "A", new EventOrderTestFilter( 'A' ) );
+        chain.addLast( "B", new EventOrderTestFilter( 'A' ) );
+        chain.addLast( "C", new EventOrderTestFilter( 'A' ) );
+        chain.addLast( "D", new EventOrderTestFilter( 'A' ) );
+        chain.addLast( "E", new EventOrderTestFilter( 'A' ) );
+        
+        chain.remove( "A" );
+        chain.remove( "E" );
+        chain.remove( "C" );
+        chain.remove( "B" );
+        chain.remove( "D" );
+        
+        Assert.assertEquals( 0, chain.getAll().size() );
+    }
+    
+    public void testClear() throws Exception
+    {
+        chain.addLast( "A", new EventOrderTestFilter( 'A' ) );
+        chain.addLast( "B", new EventOrderTestFilter( 'A' ) );
+        chain.addLast( "C", new EventOrderTestFilter( 'A' ) );
+        chain.addLast( "D", new EventOrderTestFilter( 'A' ) );
+        chain.addLast( "E", new EventOrderTestFilter( 'A' ) );
+        
+        chain.clear();
+        
+        Assert.assertEquals( 0, chain.getAll().size() );
+    }
+    
+    public void testToString() throws Exception
+    {
+        // When the chain is empty
+        Assert.assertEquals( "{ empty }", chain.toString() );
+        
+        // When there's one filter
+        chain.addLast( "A", new IoFilterAdapter()
+        {
+            public String toString()
+            {
+                return "B";
+            }
+        } );
+        Assert.assertEquals( "{ (A:B) }", chain.toString() );
+        
+        // When there are two
+        chain.addLast( "C", new IoFilterAdapter()
+        {
+            public String toString()
+            {
+                return "D";
+            }
+        } );
+        Assert.assertEquals( "{ (A:B), (C:D) }", chain.toString() );
+    }
+
+    public void testDefault()
+    {
+        run( "HS0 HSO HMR HMS HSI HEC HSC" );
+    }
+    
+    public void testChained() throws Exception
+    {
+        chain.addLast( "A", new EventOrderTestFilter( 'A' ) );
+        chain.addLast( "B", new EventOrderTestFilter( 'B' ) );
+        run( "AS0 BS0 HS0" +
+             "ASO BSO HSO" +
+             "AMR BMR HMR" +
+             "BFW AFW AMS BMS HMS" +
+             "ASI BSI HSI" +
+             "AEC BEC HEC" +
+             "ASC BSC HSC" );
+    }
+    
+    public void testAddRemove() throws Exception
+    {
+        IoFilter filter = new AddRemoveTestFilter();
+
+        chain.addFirst( "A", filter );
+        assertEquals( "ADDED", result );
+        
+        chain.remove( "A" );
+        assertEquals( "ADDEDREMOVED", result );
+    }
+    
+    private void run( String expectedResult )
+    {
+        chain.sessionCreated( session );
+        chain.sessionOpened( session );
+        chain.messageReceived( session, new Object() );
+        chain.filterWrite( session, new WriteRequest( new Object() ) );
+        chain.sessionIdle( session, IdleStatus.READER_IDLE );
+        chain.exceptionCaught( session, new Exception() );
+        chain.sessionClosed( session );
+        
+        result = formatResult( result );
+        expectedResult = formatResult( expectedResult );
+        
+        System.out.println( "Expected: " + expectedResult );
+        System.out.println( "Actual:   " + result );
+        Assert.assertEquals( expectedResult, result );
+    }
+    
+    private String formatResult( String result )
+    {
+        result = result.replaceAll( "\\s", "" );
+        StringBuffer buf = new StringBuffer( result.length() * 4 / 3 );
+        for( int i = 0; i < result.length(); i++ )
+        {
+            buf.append( result.charAt( i ) );
+            if( i % 3 == 2 )
+            {
+                buf.append(' ');
+            }
+        }
+        
+        return buf.toString();
+    }
+
+    private class TestSession extends BaseIoSession implements IoSession
+    {
+        private IoHandler handler = new IoHandlerAdapter()
+        {
+            public void sessionCreated(IoSession session) {
+                result += "HS0";
+            }
+
+            public void sessionOpened(IoSession session) {
+                result += "HSO";
+            }
+
+            public void sessionClosed(IoSession session) {
+                result += "HSC";
+            }
+
+            public void sessionIdle(IoSession session, IdleStatus status) {
+                result += "HSI";
+            }
+
+            public void exceptionCaught(IoSession session, Throwable cause) {
+                result += "HEC";
+                if( cause.getClass() != Exception.class )
+                {
+                    cause.printStackTrace( System.out );
+                }
+            }
+
+            public void messageReceived(IoSession session, Object message) {
+                result += "HMR";
+            }
+
+            public void messageSent(IoSession session, Object message) {
+                result += "HMS";
+            }
+        };
+
+        public IoHandler getHandler() {
+            return handler;
+        }
+
+        public CloseFuture close() {
+            return null;
+        }
+
+        public WriteFuture write(Object message) {
+            return null;
+        }
+
+        public TransportType getTransportType() {
+            return TransportType.VM_PIPE;
+        }
+
+        public boolean isConnected() {
+            return false;
+        }
+
+        public SocketAddress getRemoteAddress() {
+            return null;
+        }
+
+        public SocketAddress getLocalAddress() {
+            return null;
+        }
+
+        public IoFilterChain getFilterChain()
+        {
+            return new AbstractIoFilterChain( this )
+            {
+                protected void doWrite( IoSession session, WriteRequest writeRequest )
+                {
+                }
+
+                protected void doClose( IoSession session, CloseFuture closeFuture )
+                {
+                }
+            };
+        }
+
+        public int getScheduledWriteRequests()
+        {
+            return 0;
+        }
+
+        protected void updateTrafficMask()
+        {
+        }
+
+        public boolean isClosing()
+        {
+            return false;
+        }
+
+        public IoSessionManager getManager()
+        {
+            return null;
+        }
+    }
+
+    private class EventOrderTestFilter extends IoFilterAdapter
+    {
+        private final char id;
+
+        private EventOrderTestFilter( char id )
+        {
+            this.id = id;
+        }
+        
+        public void sessionCreated( NextFilter nextFilter, IoSession session )
+        {
+            result += id + "S0";
+            nextFilter.sessionCreated( session );
+        }
+
+        public void sessionOpened( NextFilter nextFilter, IoSession session )
+        {
+            result += id + "SO";
+            nextFilter.sessionOpened( session );
+        }
+
+        public void sessionClosed(NextFilter nextFilter, IoSession session) {
+            result += id + "SC";
+            nextFilter.sessionClosed( session );
+        }
+
+        public void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status) {
+            result += id + "SI";
+            nextFilter.sessionIdle( session, status );
+        }
+
+        public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) {
+            result += id + "EC";
+            nextFilter.exceptionCaught( session, cause );
+        }
+
+        public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest ) {
+            result += id + "FW";
+            nextFilter.filterWrite( session, writeRequest );
+        }
+
+        public void messageReceived(NextFilter nextFilter, IoSession session, Object message) {
+            result += id + "MR";
+            nextFilter.messageReceived( session, message );
+        }
+
+        public void messageSent(NextFilter nextFilter, IoSession session, Object message) {
+            result += id + "MS";
+            nextFilter.messageSent( session, message );
+        }
+
+        public void filterClose( NextFilter nextFilter, IoSession session, CloseFuture closeFuture ) throws Exception
+        {
+            nextFilter.filterClose( session, closeFuture );
+        }
+    }
+
+    private class AddRemoveTestFilter extends IoFilterAdapter
+    {
+        public void onPostAdd( IoFilterChain parent, String name, NextFilter nextFilter )
+        {
+            result += "ADDED";
+        }
+        
+        public void onPostRemove( IoFilterChain parent, String name, NextFilter nextFilter )
+        {
+            result += "REMOVED";
+        }
+    }
+
+    private static class IoFilterChainImpl extends AbstractIoFilterChain
+    {
+        protected IoFilterChainImpl()
+        {
+            super( new BaseIoSession()
+            {
+                protected void updateTrafficMask()
+                {
+                }
+
+                public IoSessionManager getManager()
+                {
+                    return null;
+                }
+
+                public IoHandler getHandler()
+                {
+                    return null;
+                }
+
+                public IoFilterChain getFilterChain()
+                {
+                    return null;
+                }
+
+                public TransportType getTransportType()
+                {
+                    return null;
+                }
+
+                public SocketAddress getRemoteAddress()
+                {
+                    return null;
+                }
+
+                public SocketAddress getLocalAddress()
+                {
+                    return null;
+                }
+
+                public int getScheduledWriteRequests()
+                {
+                    return 0;
+                }
+            } );
+        }
+
+        protected void doWrite( IoSession session, WriteRequest writeRequest )
+        {
+            messageSent( session, writeRequest.getMessage() );
+        }
+
+        protected void doClose( IoSession session, CloseFuture closeFuture )
+        {
+        }
+    }
+    
+}

Modified: directory/network/trunk/src/test/org/apache/mina/common/TransportTypeTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/common/TransportTypeTest.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/common/TransportTypeTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/common/TransportTypeTest.java Wed Nov 30 21:17:41 2005
@@ -1,67 +1,67 @@
-/*
- *   @(#) $Id$
- *
- *   Copyright 2004 The Apache Software Foundation
- *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- *
- */
-package org.apache.mina.common;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-/**
- * Tests {@link TransportType}.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class TransportTypeTest extends TestCase {
-
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(TransportTypeTest.class);
-    }
-    
-    public void testRegistration()
-    {
-        TransportType myType = new TransportType( new String[] { "a", "b", "c" }, true );
-        
-        Assert.assertSame( myType, TransportType.getInstance( "a" ) );
-        Assert.assertSame( myType, TransportType.getInstance( "A" ) );
-        Assert.assertSame( myType, TransportType.getInstance( "b" ) );
-        Assert.assertSame( myType, TransportType.getInstance( "B" ) );
-        Assert.assertSame( myType, TransportType.getInstance( "c" ) );
-        Assert.assertSame( myType, TransportType.getInstance( "C" ) );
-        try
-        {
-            TransportType.getInstance( "unknown" );
-            Assert.fail();
-        }
-        catch( IllegalArgumentException e )
-        {
-            // ignore
-        }
-        
-        try
-        {
-            new TransportType( new String[] { "A" }, false );
-            Assert.fail();
-        }
-        catch( IllegalArgumentException e )
-        {
-            // ignore
-        }
-    }
-
-}
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.common;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Tests {@link TransportType}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class TransportTypeTest extends TestCase {
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(TransportTypeTest.class);
+    }
+    
+    public void testRegistration()
+    {
+        TransportType myType = new TransportType( new String[] { "a", "b", "c" }, true );
+        
+        Assert.assertSame( myType, TransportType.getInstance( "a" ) );
+        Assert.assertSame( myType, TransportType.getInstance( "A" ) );
+        Assert.assertSame( myType, TransportType.getInstance( "b" ) );
+        Assert.assertSame( myType, TransportType.getInstance( "B" ) );
+        Assert.assertSame( myType, TransportType.getInstance( "c" ) );
+        Assert.assertSame( myType, TransportType.getInstance( "C" ) );
+        try
+        {
+            TransportType.getInstance( "unknown" );
+            Assert.fail();
+        }
+        catch( IllegalArgumentException e )
+        {
+            // ignore
+        }
+        
+        try
+        {
+            new TransportType( new String[] { "A" }, false );
+            Assert.fail();
+        }
+        catch( IllegalArgumentException e )
+        {
+            // ignore
+        }
+    }
+
+}

Modified: directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AbstractTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AbstractTest.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AbstractTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AbstractTest.java Wed Nov 30 21:17:41 2005
@@ -1,168 +1,168 @@
-/*
- *   @(#) $Id$
- *
- *   Copyright 2004 The Apache Software Foundation
- *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- *
- */
-package org.apache.mina.examples.echoserver;
-
-import java.io.IOException;
-
-import junit.framework.TestCase;
-
-import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.common.TransportType;
-import org.apache.mina.filter.LoggingFilter;
-import org.apache.mina.filter.SSLFilter;
-import org.apache.mina.registry.Service;
-import org.apache.mina.registry.ServiceRegistry;
-import org.apache.mina.registry.SimpleServiceRegistry;
-import org.apache.mina.transport.socket.nio.SocketAcceptor;
-import org.apache.mina.util.SessionLog;
-
-/**
- * Tests echo server example.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class AbstractTest extends TestCase
-{
-    protected int port;
-
-    protected ServiceRegistry registry;
-    
-    protected AbstractTest()
-    {
-    }
-
-    protected static void assertEquals( byte[] expected, byte[] actual )
-    {
-        assertEquals( toString( expected ), toString( actual ) );
-    }
-
-    protected static void assertEquals( ByteBuffer expected, ByteBuffer actual )
-    {
-        assertEquals( toString( expected ), toString( actual ) );
-    }
-
-    protected static String toString( byte[] buf )
-    {
-        StringBuffer str = new StringBuffer( buf.length * 4 );
-        for( int i = 0; i < buf.length; i ++ )
-        {
-            str.append( buf[ i ] );
-            str.append( ' ' );
-        }
-        return str.toString();
-    }
-    
-    protected static String toString( ByteBuffer buf )
-    {
-        return buf.getHexDump();
-    }
-
-    protected void setUp() throws Exception
-    {
-        registry = new SimpleServiceRegistry();
-
-        // Find an availble test port and bind to it.
-        boolean socketBound = false;
-        boolean datagramBound = false;
-
-        final SocketAcceptor acceptor = ( SocketAcceptor ) registry.getAcceptor( TransportType.SOCKET );
-        acceptor.setReuseAddress( true );
-
-        // Let's start from port #1 to detect possible resource leak
-        // because test will fail in port 1-1023 if user run this test
-        // as a normal user.
-        for( port = 1; port <= 65535; port ++ )
-        {
-            socketBound = false;
-            datagramBound = false;
-            
-            Service socketService = new Service( "echo", TransportType.SOCKET, port );
-            Service datagramService = new Service( "echo", TransportType.DATAGRAM, port );
-            
-            try
-            {
-                registry.bind( socketService, new EchoProtocolHandler()
-                {
-                    // This is for TLS reentrance test
-                    public void messageReceived( IoSession session, Object message ) throws Exception
-                    {
-                        if( !( message instanceof ByteBuffer ) )
-                        {
-                            return;
-                        }
-                        
-                        ByteBuffer buf = ( ByteBuffer ) message;
-                        if( buf.remaining() == 1 && buf.get() == ( byte ) '.' )
-                        {
-                            SessionLog.info( session, "TLS Reentrance" );
-                            ( ( SSLFilter ) acceptor.getFilterChain().get( "SSL" ) ).startSSL( session );
-
-                            // Send a response
-                            buf = ByteBuffer.allocate( 1 );
-                            buf.put( ( byte ) '.' );
-                            buf.flip();
-                            session.setAttribute( SSLFilter.DISABLE_ENCRYPTION_ONCE );
-                            session.write( buf );
-                        }
-                        else
-                        {
-                            super.messageReceived( session, message );
-                        }
-                    }
-                } );
-                socketBound = true;
-
-                registry.bind( datagramService, new EchoProtocolHandler() );
-                datagramBound = true;
-
-                break;
-            }
-            catch( IOException e )
-            {
-            }
-            finally
-            {
-                if( !socketBound || !datagramBound )
-                {
-                    registry.unbindAll();
-                }
-            }
-        }
-
-        // If there is no port available, test fails.
-        if( !socketBound || !datagramBound )
-        {
-            throw new IOException( "Cannot bind any test port." );
-        }
-
-        registry.getAcceptor( TransportType.SOCKET ).getFilterChain().addLast( "logger", new LoggingFilter() );
-        registry.getAcceptor( TransportType.DATAGRAM ).getFilterChain().addLast( "logger", new LoggingFilter() );
-
-        System.out.println( "Using port " + port + " for testing." );
-    }
-
-    protected void tearDown() throws Exception
-    {
-        registry.unbindAll();
-        registry.getAcceptor( TransportType.SOCKET ).getFilterChain().remove( "logger" );
-        registry.getAcceptor( TransportType.DATAGRAM ).getFilterChain().remove( "logger" );
-    }
-}
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.echoserver;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.TransportType;
+import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.SSLFilter;
+import org.apache.mina.registry.Service;
+import org.apache.mina.registry.ServiceRegistry;
+import org.apache.mina.registry.SimpleServiceRegistry;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.apache.mina.util.SessionLog;
+
+/**
+ * Tests echo server example.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractTest extends TestCase
+{
+    protected int port;
+
+    protected ServiceRegistry registry;
+    
+    protected AbstractTest()
+    {
+    }
+
+    protected static void assertEquals( byte[] expected, byte[] actual )
+    {
+        assertEquals( toString( expected ), toString( actual ) );
+    }
+
+    protected static void assertEquals( ByteBuffer expected, ByteBuffer actual )
+    {
+        assertEquals( toString( expected ), toString( actual ) );
+    }
+
+    protected static String toString( byte[] buf )
+    {
+        StringBuffer str = new StringBuffer( buf.length * 4 );
+        for( int i = 0; i < buf.length; i ++ )
+        {
+            str.append( buf[ i ] );
+            str.append( ' ' );
+        }
+        return str.toString();
+    }
+    
+    protected static String toString( ByteBuffer buf )
+    {
+        return buf.getHexDump();
+    }
+
+    protected void setUp() throws Exception
+    {
+        registry = new SimpleServiceRegistry();
+
+        // Find an availble test port and bind to it.
+        boolean socketBound = false;
+        boolean datagramBound = false;
+
+        final SocketAcceptor acceptor = ( SocketAcceptor ) registry.getAcceptor( TransportType.SOCKET );
+        acceptor.setReuseAddress( true );
+
+        // Let's start from port #1 to detect possible resource leak
+        // because test will fail in port 1-1023 if user run this test
+        // as a normal user.
+        for( port = 1; port <= 65535; port ++ )
+        {
+            socketBound = false;
+            datagramBound = false;
+            
+            Service socketService = new Service( "echo", TransportType.SOCKET, port );
+            Service datagramService = new Service( "echo", TransportType.DATAGRAM, port );
+            
+            try
+            {
+                registry.bind( socketService, new EchoProtocolHandler()
+                {
+                    // This is for TLS reentrance test
+                    public void messageReceived( IoSession session, Object message ) throws Exception
+                    {
+                        if( !( message instanceof ByteBuffer ) )
+                        {
+                            return;
+                        }
+                        
+                        ByteBuffer buf = ( ByteBuffer ) message;
+                        if( buf.remaining() == 1 && buf.get() == ( byte ) '.' )
+                        {
+                            SessionLog.info( session, "TLS Reentrance" );
+                            ( ( SSLFilter ) acceptor.getFilterChain().get( "SSL" ) ).startSSL( session );
+
+                            // Send a response
+                            buf = ByteBuffer.allocate( 1 );
+                            buf.put( ( byte ) '.' );
+                            buf.flip();
+                            session.setAttribute( SSLFilter.DISABLE_ENCRYPTION_ONCE );
+                            session.write( buf );
+                        }
+                        else
+                        {
+                            super.messageReceived( session, message );
+                        }
+                    }
+                } );
+                socketBound = true;
+
+                registry.bind( datagramService, new EchoProtocolHandler() );
+                datagramBound = true;
+
+                break;
+            }
+            catch( IOException e )
+            {
+            }
+            finally
+            {
+                if( !socketBound || !datagramBound )
+                {
+                    registry.unbindAll();
+                }
+            }
+        }
+
+        // If there is no port available, test fails.
+        if( !socketBound || !datagramBound )
+        {
+            throw new IOException( "Cannot bind any test port." );
+        }
+
+        registry.getAcceptor( TransportType.SOCKET ).getFilterChain().addLast( "logger", new LoggingFilter() );
+        registry.getAcceptor( TransportType.DATAGRAM ).getFilterChain().addLast( "logger", new LoggingFilter() );
+
+        System.out.println( "Using port " + port + " for testing." );
+    }
+
+    protected void tearDown() throws Exception
+    {
+        registry.unbindAll();
+        registry.getAcceptor( TransportType.SOCKET ).getFilterChain().remove( "logger" );
+        registry.getAcceptor( TransportType.DATAGRAM ).getFilterChain().remove( "logger" );
+    }
+}

Modified: directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java Wed Nov 30 21:17:41 2005
@@ -1,211 +1,211 @@
-/*
- *   @(#) $Id$
- *
- *   Copyright 2004 The Apache Software Foundation
- *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- *
- */
-package org.apache.mina.examples.echoserver;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.SocketTimeoutException;
-import java.net.UnknownHostException;
-
-import javax.net.ServerSocketFactory;
-import javax.net.SocketFactory;
-
-import org.apache.commons.net.EchoTCPClient;
-import org.apache.commons.net.EchoUDPClient;
-import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.TransportType;
-import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
-import org.apache.mina.examples.echoserver.ssl.SSLServerSocketFactory;
-import org.apache.mina.examples.echoserver.ssl.SSLSocketFactory;
-import org.apache.mina.filter.SSLFilter;
-
-/**
- * Tests echo server example.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class AcceptorTest extends AbstractTest
-{
-    public AcceptorTest()
-    {
-    }
-
-    public void testTCP() throws Exception
-    {
-        EchoTCPClient client = new EchoTCPClient();
-        testTCP0( client );
-    }
-
-    public void testTCPWithSSL() throws Exception
-    {
-        // Add an SSL filter
-        SSLFilter sslFilter =
-            new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
-        IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
-        acceptor.getFilterChain().addLast( "SSL", sslFilter );
-        
-        // Create a commons-net socket factory
-        SSLSocketFactory.setSslEnabled(true);
-        SSLServerSocketFactory.setSslEnabled(true);
-        org.apache.commons.net.SocketFactory factory = new org.apache.commons.net.SocketFactory() {
-
-            private SocketFactory f = SSLSocketFactory.getSocketFactory();
-            private ServerSocketFactory ssf = SSLServerSocketFactory.getServerSocketFactory();
-
-            public Socket createSocket( String arg0, int arg1 ) throws UnknownHostException, IOException
-            {
-                return f.createSocket(arg0, arg1);
-            }
-
-            public Socket createSocket( InetAddress arg0, int arg1 ) throws IOException
-            {
-                return f.createSocket(arg0, arg1);
-            }
-
-            public Socket createSocket( String arg0, int arg1, InetAddress arg2, int arg3 ) throws UnknownHostException, IOException
-            {
-                return f.createSocket(arg0, arg1, arg2, arg3);
-            }
-
-            public Socket createSocket( InetAddress arg0, int arg1, InetAddress arg2, int arg3 ) throws IOException
-            {
-                return f.createSocket(arg0, arg1, arg2, arg3);
-            }
-
-            public ServerSocket createServerSocket( int arg0 ) throws IOException
-            {
-                return ssf.createServerSocket(arg0);
-            }
-
-            public ServerSocket createServerSocket( int arg0, int arg1 ) throws IOException
-            {
-                return ssf.createServerSocket(arg0, arg1);
-            }
-
-            public ServerSocket createServerSocket( int arg0, int arg1, InetAddress arg2 ) throws IOException
-            {
-                return ssf.createServerSocket(arg0, arg1, arg2);
-            }
-            
-        };
-        
-        // Create a echo client with SSL factory and test it.
-        EchoTCPClient client = new EchoTCPClient();
-        client.setSocketFactory( factory );
-        testTCP0( client );
-    }
-    
-    private void testTCP0( EchoTCPClient client ) throws Exception
-    {
-        client.connect( InetAddress.getLocalHost(), port );
-        byte[] writeBuf = new byte[ 16 ];
-
-        for( int i = 0; i < 10; i ++ )
-        {
-            fillWriteBuffer( writeBuf, i );
-            client.getOutputStream().write( writeBuf );
-        }
-
-        client.setSoTimeout( 30000 );
-
-        byte[] readBuf = new byte[ writeBuf.length ];
-
-        for( int i = 0; i < 10; i ++ )
-        {
-            fillWriteBuffer( writeBuf, i );
-
-            int readBytes = 0;
-            while( readBytes < readBuf.length )
-            {
-                int nBytes = client.getInputStream().read( readBuf,
-                        readBytes, readBuf.length - readBytes );
-
-                if( nBytes < 0 )
-                    fail( "Unexpected disconnection." );
-
-                readBytes += nBytes;
-            }
-
-            assertEquals( writeBuf, readBuf );
-        }
-
-        client.setSoTimeout( 500 );
-
-        try
-        {
-            client.getInputStream().read();
-            fail( "Unexpected incoming data." );
-        }
-        catch( SocketTimeoutException e )
-        {
-        }
-
-        client.disconnect();
-    }
-
-    public void testUDP() throws Exception
-    {
-        EchoUDPClient client = new EchoUDPClient();
-        client.open();
-        client.setSoTimeout( 3000 );
-
-        byte[] writeBuf = new byte[ 16 ];
-        byte[] readBuf = new byte[ writeBuf.length ];
-
-        client.setSoTimeout( 500 );
-
-        for( int i = 0; i < 10; i ++ )
-        {
-            fillWriteBuffer( writeBuf, i );
-            client.send( writeBuf, writeBuf.length, InetAddress
-                    .getLocalHost(), port );
-
-            assertEquals( readBuf.length, client.receive( readBuf,
-                    readBuf.length ) );
-            assertEquals( writeBuf, readBuf );
-        }
-
-        try
-        {
-            client.receive( readBuf );
-            fail( "Unexpected incoming data." );
-        }
-        catch( SocketTimeoutException e )
-        {
-        }
-
-        client.close();
-    }
-
-    private void fillWriteBuffer( byte[] writeBuf, int i )
-    {
-        for( int j = writeBuf.length - 1; j >= 0; j -- )
-        {
-            writeBuf[ j ] = ( byte ) ( j + i );
-        }
-    }
-
-    public static void main( String[] args )
-    {
-        junit.textui.TestRunner.run( AcceptorTest.class );
-    }
-}
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.echoserver;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketTimeoutException;
+import java.net.UnknownHostException;
+
+import javax.net.ServerSocketFactory;
+import javax.net.SocketFactory;
+
+import org.apache.commons.net.EchoTCPClient;
+import org.apache.commons.net.EchoUDPClient;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.TransportType;
+import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
+import org.apache.mina.examples.echoserver.ssl.SSLServerSocketFactory;
+import org.apache.mina.examples.echoserver.ssl.SSLSocketFactory;
+import org.apache.mina.filter.SSLFilter;
+
+/**
+ * Tests echo server example.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class AcceptorTest extends AbstractTest
+{
+    public AcceptorTest()
+    {
+    }
+
+    public void testTCP() throws Exception
+    {
+        EchoTCPClient client = new EchoTCPClient();
+        testTCP0( client );
+    }
+
+    public void testTCPWithSSL() throws Exception
+    {
+        // Add an SSL filter
+        SSLFilter sslFilter =
+            new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
+        IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
+        acceptor.getFilterChain().addLast( "SSL", sslFilter );
+        
+        // Create a commons-net socket factory
+        SSLSocketFactory.setSslEnabled(true);
+        SSLServerSocketFactory.setSslEnabled(true);
+        org.apache.commons.net.SocketFactory factory = new org.apache.commons.net.SocketFactory() {
+
+            private SocketFactory f = SSLSocketFactory.getSocketFactory();
+            private ServerSocketFactory ssf = SSLServerSocketFactory.getServerSocketFactory();
+
+            public Socket createSocket( String arg0, int arg1 ) throws UnknownHostException, IOException
+            {
+                return f.createSocket(arg0, arg1);
+            }
+
+            public Socket createSocket( InetAddress arg0, int arg1 ) throws IOException
+            {
+                return f.createSocket(arg0, arg1);
+            }
+
+            public Socket createSocket( String arg0, int arg1, InetAddress arg2, int arg3 ) throws UnknownHostException, IOException
+            {
+                return f.createSocket(arg0, arg1, arg2, arg3);
+            }
+
+            public Socket createSocket( InetAddress arg0, int arg1, InetAddress arg2, int arg3 ) throws IOException
+            {
+                return f.createSocket(arg0, arg1, arg2, arg3);
+            }
+
+            public ServerSocket createServerSocket( int arg0 ) throws IOException
+            {
+                return ssf.createServerSocket(arg0);
+            }
+
+            public ServerSocket createServerSocket( int arg0, int arg1 ) throws IOException
+            {
+                return ssf.createServerSocket(arg0, arg1);
+            }
+
+            public ServerSocket createServerSocket( int arg0, int arg1, InetAddress arg2 ) throws IOException
+            {
+                return ssf.createServerSocket(arg0, arg1, arg2);
+            }
+            
+        };
+        
+        // Create a echo client with SSL factory and test it.
+        EchoTCPClient client = new EchoTCPClient();
+        client.setSocketFactory( factory );
+        testTCP0( client );
+    }
+    
+    private void testTCP0( EchoTCPClient client ) throws Exception
+    {
+        client.connect( InetAddress.getLocalHost(), port );
+        byte[] writeBuf = new byte[ 16 ];
+
+        for( int i = 0; i < 10; i ++ )
+        {
+            fillWriteBuffer( writeBuf, i );
+            client.getOutputStream().write( writeBuf );
+        }
+
+        client.setSoTimeout( 30000 );
+
+        byte[] readBuf = new byte[ writeBuf.length ];
+
+        for( int i = 0; i < 10; i ++ )
+        {
+            fillWriteBuffer( writeBuf, i );
+
+            int readBytes = 0;
+            while( readBytes < readBuf.length )
+            {
+                int nBytes = client.getInputStream().read( readBuf,
+                        readBytes, readBuf.length - readBytes );
+
+                if( nBytes < 0 )
+                    fail( "Unexpected disconnection." );
+
+                readBytes += nBytes;
+            }
+
+            assertEquals( writeBuf, readBuf );
+        }
+
+        client.setSoTimeout( 500 );
+
+        try
+        {
+            client.getInputStream().read();
+            fail( "Unexpected incoming data." );
+        }
+        catch( SocketTimeoutException e )
+        {
+        }
+
+        client.disconnect();
+    }
+
+    public void testUDP() throws Exception
+    {
+        EchoUDPClient client = new EchoUDPClient();
+        client.open();
+        client.setSoTimeout( 3000 );
+
+        byte[] writeBuf = new byte[ 16 ];
+        byte[] readBuf = new byte[ writeBuf.length ];
+
+        client.setSoTimeout( 500 );
+
+        for( int i = 0; i < 10; i ++ )
+        {
+            fillWriteBuffer( writeBuf, i );
+            client.send( writeBuf, writeBuf.length, InetAddress
+                    .getLocalHost(), port );
+
+            assertEquals( readBuf.length, client.receive( readBuf,
+                    readBuf.length ) );
+            assertEquals( writeBuf, readBuf );
+        }
+
+        try
+        {
+            client.receive( readBuf );
+            fail( "Unexpected incoming data." );
+        }
+        catch( SocketTimeoutException e )
+        {
+        }
+
+        client.close();
+    }
+
+    private void fillWriteBuffer( byte[] writeBuf, int i )
+    {
+        for( int j = writeBuf.length - 1; j >= 0; j -- )
+        {
+            writeBuf[ j ] = ( byte ) ( j + i );
+        }
+    }
+
+    public static void main( String[] args )
+    {
+        junit.textui.TestRunner.run( AcceptorTest.class );
+    }
+}

Modified: directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java Wed Nov 30 21:17:41 2005
@@ -1,274 +1,274 @@
-/*
- *   @(#) $Id$
- *
- *   Copyright 2004 The Apache Software Foundation
- *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- *
- */
-package org.apache.mina.examples.echoserver;
-
-import java.net.BindException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-
-import junit.framework.Assert;
-
-import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.ConnectFuture;
-import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.IoConnector;
-import org.apache.mina.common.IoHandlerAdapter;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.common.TransportType;
-import org.apache.mina.common.WriteFuture;
-import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
-import org.apache.mina.filter.LoggingFilter;
-import org.apache.mina.filter.SSLFilter;
-import org.apache.mina.transport.socket.nio.DatagramConnector;
-import org.apache.mina.transport.socket.nio.SocketConnector;
-import org.apache.mina.util.AvailablePortFinder;
-import org.apache.mina.util.SessionLog;
-
-/**
- * Tests echo server example.
- * 
- * @author The Apache Directory Project (dev@directory.apache.org)
- * @version $Rev$, $Date$
- */
-public class ConnectorTest extends AbstractTest
-{
-    private static final int TIMEOUT = 10000; // 10 seconds
-    private final int COUNT = 10;
-    private final int DATA_SIZE = 16;
-
-    public ConnectorTest()
-    {
-    }
-
-    public void testTCP() throws Exception
-    {
-        IoConnector connector = new SocketConnector();
-        testConnector( connector );
-    }
-    
-    public void testTCPWithSSL() throws Exception
-    {
-        // Add an SSL filter to acceptor
-        SSLFilter acceptorSSLFilter =
-            new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
-        IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
-        acceptor.getFilterChain().addLast( "SSL", acceptorSSLFilter );
-        
-        // Create a connector
-        IoConnector connector = new SocketConnector();
-        
-        // Add an SSL filter to connector
-        SSLFilter connectorSSLFilter =
-            new SSLFilter( BogusSSLContextFactory.getInstance( false ) );
-        connectorSSLFilter.setUseClientMode( true ); // set client mode
-        connector.getFilterChain().addLast( "SSL", connectorSSLFilter );
-
-        testConnector( connector );
-    }
-    
-    public void testUDP() throws Exception
-    {
-        IoConnector connector = new DatagramConnector();
-        testConnector( connector );
-    }
-    
-    private void testConnector( IoConnector connector ) throws Exception
-    {
-        System.out.println("* Without localAddress");
-        testConnector( connector, false );
-            
-        System.out.println("* With localAddress");
-        testConnector( connector, true );
-    }
-    
-    private void testConnector( IoConnector connector, boolean useLocalAddress ) throws Exception
-    {
-        EchoConnectorHandler handler = new EchoConnectorHandler();
-        
-        IoSession session = null;
-        if( !useLocalAddress )
-        {
-            ConnectFuture future = connector.connect(
-                    new InetSocketAddress( InetAddress.getLocalHost(), port ),
-                    handler );
-            future.join();
-            session = future.getSession();
-        }
-        else
-        {
-            int clientPort = port;
-            for( int i = 0; i < 65536; i ++ )
-            {
-                clientPort = AvailablePortFinder.getNextAvailable( clientPort + 1 );
-                try
-                {
-                    ConnectFuture future = connector.connect(
-                            new InetSocketAddress( InetAddress.getLocalHost(), port ),
-                            new InetSocketAddress( clientPort ),
-                            handler );
-                    future.join();
-                    session = future.getSession();
-                    break;
-                }
-                catch( BindException e )
-                {
-                    // Try again until we succeed to bind.
-                }
-            }
-
-            if( session == null )
-            {
-                Assert.fail( "Failed to find out an appropriate local address." );
-            }
-        }
-        
-        // Run a basic connector test.
-        testConnector0( session );
-        
-        // Send closeNotify to test TLS closure if it is TLS connection.
-        SSLFilter sslf = ( SSLFilter ) connector.getFilterChain().get("SSL");
-        if( sslf != null )
-        {
-            connector.getFilterChain().addFirst( "log", new LoggingFilter() );
-            sslf.stopSSL( session ).join();
-            
-            System.out.println( "-------------------------------------------------------------------------------" );
-            // Test again after we finished TLS session.
-            testConnector0( session );
-            
-            System.out.println( "-------------------------------------------------------------------------------" );
-            
-            // Test if we can enter TLS mode again.
-            //// Send StartTLS request.
-            handler.readBuf.clear();
-            ByteBuffer buf = ByteBuffer.allocate( 1 );
-            buf.put( ( byte ) '.' );
-            buf.flip();
-            session.write( buf ).join();
-            
-            //// Wait for StartTLS response.
-            waitForResponse( handler, 1 );
-
-            handler.readBuf.flip();
-            Assert.assertEquals( 1, handler.readBuf.remaining() );
-            Assert.assertEquals( ( byte ) '.', handler.readBuf.get() );
-            
-            // Now start TLS connection
-            Assert.assertTrue( sslf.startSSL( session ) );
-            testConnector0( session );
-            connector.getFilterChain().remove( "log" );
-        }
-        
-        session.close().join();
-    }
-
-    private void testConnector0( IoSession session ) throws InterruptedException
-    {
-        EchoConnectorHandler handler = ( EchoConnectorHandler ) session.getHandler();
-        ByteBuffer readBuf = handler.readBuf;
-        readBuf.clear();
-        WriteFuture writeFuture = null;
-        for( int i = 0; i < COUNT; i ++ )
-        {
-            ByteBuffer buf = ByteBuffer.allocate( DATA_SIZE );
-            buf.limit( DATA_SIZE );
-            fillWriteBuffer( buf, i );
-            buf.flip();
-            
-            writeFuture = session.write( buf );
-            
-            if( session.getTransportType().isConnectionless() ) 
-            {
-                // This will align message arrival order in connectionless transport types
-                waitForResponse( handler, ( i + 1 ) * DATA_SIZE );
-            }
-        }
-        
-        writeFuture.join();
-
-        waitForResponse( handler, DATA_SIZE * COUNT );
-
-        // Assert data
-        //// Please note that BufferOverflowException can be thrown
-        //// in SocketIoProcessor if there was a read timeout because
-        //// we share readBuf.
-        readBuf.flip();
-        SessionLog.info( session, "readBuf: " + readBuf );
-        Assert.assertEquals( DATA_SIZE * COUNT, readBuf.remaining() );
-        ByteBuffer expectedBuf = ByteBuffer.allocate( DATA_SIZE * COUNT );
-        for( int i = 0; i < COUNT; i ++ ) {
-            expectedBuf.limit( ( i + 1 ) * DATA_SIZE );
-            fillWriteBuffer( expectedBuf, i );
-        }
-        expectedBuf.position( 0 );
-        
-        assertEquals(expectedBuf, readBuf);
-    }
-
-    private void waitForResponse( EchoConnectorHandler handler, int bytes ) throws InterruptedException
-    {
-        for( int j = 0; j < TIMEOUT / 10; j ++ )
-        {
-            if( handler.readBuf.position() >= bytes )
-            {
-                break;
-            }
-            Thread.sleep( 10 );
-        }
-        
-        Assert.assertEquals( bytes, handler.readBuf.position() );
-    }
-    
-    private void fillWriteBuffer( ByteBuffer writeBuf, int i )
-    {
-        while( writeBuf.remaining() > 0 )
-        {
-            writeBuf.put( ( byte ) ( i ++ ) );
-        }
-    }
-
-    public static void main( String[] args )
-    {
-        junit.textui.TestRunner.run( ConnectorTest.class );
-    }
-    
-    private static class EchoConnectorHandler extends IoHandlerAdapter
-    {
-        private ByteBuffer readBuf = ByteBuffer.allocate( 1024 );
-        
-        private EchoConnectorHandler()
-        {
-            readBuf.setAutoExpand( true );
-        }
-
-        public void messageReceived( IoSession session, Object message )
-        {
-            readBuf.put( ( ByteBuffer ) message );
-        }
-        
-        public void messageSent( IoSession session, Object message )
-        {
-        }
-
-        public void exceptionCaught( IoSession session, Throwable cause )
-        {
-            cause.printStackTrace();
-        }
-    }
-}
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.examples.echoserver;
+
+import java.net.BindException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
+import junit.framework.Assert;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.TransportType;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
+import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.SSLFilter;
+import org.apache.mina.transport.socket.nio.DatagramConnector;
+import org.apache.mina.transport.socket.nio.SocketConnector;
+import org.apache.mina.util.AvailablePortFinder;
+import org.apache.mina.util.SessionLog;
+
+/**
+ * Tests echo server example.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ConnectorTest extends AbstractTest
+{
+    private static final int TIMEOUT = 10000; // 10 seconds
+    private final int COUNT = 10;
+    private final int DATA_SIZE = 16;
+
+    public ConnectorTest()
+    {
+    }
+
+    public void testTCP() throws Exception
+    {
+        IoConnector connector = new SocketConnector();
+        testConnector( connector );
+    }
+    
+    public void testTCPWithSSL() throws Exception
+    {
+        // Add an SSL filter to acceptor
+        SSLFilter acceptorSSLFilter =
+            new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
+        IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
+        acceptor.getFilterChain().addLast( "SSL", acceptorSSLFilter );
+        
+        // Create a connector
+        IoConnector connector = new SocketConnector();
+        
+        // Add an SSL filter to connector
+        SSLFilter connectorSSLFilter =
+            new SSLFilter( BogusSSLContextFactory.getInstance( false ) );
+        connectorSSLFilter.setUseClientMode( true ); // set client mode
+        connector.getFilterChain().addLast( "SSL", connectorSSLFilter );
+
+        testConnector( connector );
+    }
+    
+    public void testUDP() throws Exception
+    {
+        IoConnector connector = new DatagramConnector();
+        testConnector( connector );
+    }
+    
+    private void testConnector( IoConnector connector ) throws Exception
+    {
+        System.out.println("* Without localAddress");
+        testConnector( connector, false );
+            
+        System.out.println("* With localAddress");
+        testConnector( connector, true );
+    }
+    
+    private void testConnector( IoConnector connector, boolean useLocalAddress ) throws Exception
+    {
+        EchoConnectorHandler handler = new EchoConnectorHandler();
+        
+        IoSession session = null;
+        if( !useLocalAddress )
+        {
+            ConnectFuture future = connector.connect(
+                    new InetSocketAddress( InetAddress.getLocalHost(), port ),
+                    handler );
+            future.join();
+            session = future.getSession();
+        }
+        else
+        {
+            int clientPort = port;
+            for( int i = 0; i < 65536; i ++ )
+            {
+                clientPort = AvailablePortFinder.getNextAvailable( clientPort + 1 );
+                try
+                {
+                    ConnectFuture future = connector.connect(
+                            new InetSocketAddress( InetAddress.getLocalHost(), port ),
+                            new InetSocketAddress( clientPort ),
+                            handler );
+                    future.join();
+                    session = future.getSession();
+                    break;
+                }
+                catch( BindException e )
+                {
+                    // Try again until we succeed to bind.
+                }
+            }
+
+            if( session == null )
+            {
+                Assert.fail( "Failed to find out an appropriate local address." );
+            }
+        }
+        
+        // Run a basic connector test.
+        testConnector0( session );
+        
+        // Send closeNotify to test TLS closure if it is TLS connection.
+        SSLFilter sslf = ( SSLFilter ) connector.getFilterChain().get( "SSL" );
+        if( sslf != null )
+        {
+            connector.getFilterChain().addFirst( "log", new LoggingFilter() );
+            sslf.stopSSL( session ).join();
+            
+            System.out.println( "-------------------------------------------------------------------------------" );
+            // Test again after we finished TLS session.
+            testConnector0( session );
+            
+            System.out.println( "-------------------------------------------------------------------------------" );
+            
+            // Test if we can enter TLS mode again.
+            //// Send StartTLS request.
+            handler.readBuf.clear();
+            ByteBuffer buf = ByteBuffer.allocate( 1 );
+            buf.put( ( byte ) '.' );
+            buf.flip();
+            session.write( buf ).join();
+            
+            //// Wait for StartTLS response.
+            waitForResponse( handler, 1 );
+
+            handler.readBuf.flip();
+            Assert.assertEquals( 1, handler.readBuf.remaining() );
+            Assert.assertEquals( ( byte ) '.', handler.readBuf.get() );
+            
+            // Now start TLS connection
+            Assert.assertTrue( sslf.startSSL( session ) );
+            testConnector0( session );
+            connector.getFilterChain().remove( "log" );
+        }
+        
+        session.close().join();
+    }
+
+    private void testConnector0( IoSession session ) throws InterruptedException
+    {
+        EchoConnectorHandler handler = ( EchoConnectorHandler ) session.getHandler();
+        ByteBuffer readBuf = handler.readBuf;
+        readBuf.clear();
+        WriteFuture writeFuture = null;
+        for( int i = 0; i < COUNT; i ++ )
+        {
+            ByteBuffer buf = ByteBuffer.allocate( DATA_SIZE );
+            buf.limit( DATA_SIZE );
+            fillWriteBuffer( buf, i );
+            buf.flip();
+            
+            writeFuture = session.write( buf );
+            
+            if( session.getTransportType().isConnectionless() ) 
+            {
+                // This will align message arrival order in connectionless transport types
+                waitForResponse( handler, ( i + 1 ) * DATA_SIZE );
+            }
+        }
+        
+        writeFuture.join();
+
+        waitForResponse( handler, DATA_SIZE * COUNT );
+
+        // Assert data
+        //// Please note that BufferOverflowException can be thrown
+        //// in SocketIoProcessor if there was a read timeout because
+        //// we share readBuf.
+        readBuf.flip();
+        SessionLog.info( session, "readBuf: " + readBuf );
+        Assert.assertEquals( DATA_SIZE * COUNT, readBuf.remaining() );
+        ByteBuffer expectedBuf = ByteBuffer.allocate( DATA_SIZE * COUNT );
+        for( int i = 0; i < COUNT; i ++ ) {
+            expectedBuf.limit( ( i + 1 ) * DATA_SIZE );
+            fillWriteBuffer( expectedBuf, i );
+        }
+        expectedBuf.position( 0 );
+        
+        assertEquals(expectedBuf, readBuf);
+    }
+
+    private void waitForResponse( EchoConnectorHandler handler, int bytes ) throws InterruptedException
+    {
+        for( int j = 0; j < TIMEOUT / 10; j ++ )
+        {
+            if( handler.readBuf.position() >= bytes )
+            {
+                break;
+            }
+            Thread.sleep( 10 );
+        }
+        
+        Assert.assertEquals( bytes, handler.readBuf.position() );
+    }
+    
+    private void fillWriteBuffer( ByteBuffer writeBuf, int i )
+    {
+        while( writeBuf.remaining() > 0 )
+        {
+            writeBuf.put( ( byte ) ( i ++ ) );
+        }
+    }
+
+    public static void main( String[] args )
+    {
+        junit.textui.TestRunner.run( ConnectorTest.class );
+    }
+    
+    private static class EchoConnectorHandler extends IoHandlerAdapter
+    {
+        private ByteBuffer readBuf = ByteBuffer.allocate( 1024 );
+        
+        private EchoConnectorHandler()
+        {
+            readBuf.setAutoExpand( true );
+        }
+
+        public void messageReceived( IoSession session, Object message )
+        {
+            readBuf.put( ( ByteBuffer ) message );
+        }
+        
+        public void messageSent( IoSession session, Object message )
+        {
+        }
+
+        public void exceptionCaught( IoSession session, Throwable cause )
+        {
+            cause.printStackTrace();
+        }
+    }
+}

Modified: directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java?rev=350169&r1=350168&r2=350169&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java Wed Nov 30 21:17:41 2005
@@ -10,6 +10,7 @@
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionManager;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.common.WriteFuture;
 import org.apache.mina.common.IoFilter.NextFilter;
@@ -19,7 +20,7 @@
 
 public class ThreadPoolFilterRegressionTest extends TestCase
 {
-    private static final IoFilterChain FILTER_PARENT = new AbstractIoFilterChain( new Object() )
+    private static final IoFilterChain FILTER_PARENT = new AbstractIoFilterChain( new DummySession() )
     {
         protected void doWrite( IoSession session, WriteRequest writeRequest )
         {
@@ -35,15 +36,15 @@
     {
     }
     
-    public void setUp()
+    public void setUp() throws Exception
     {
         filter = new ThreadPoolFilter();
-        filter.init( FILTER_PARENT, null );
+        filter.init();
     }
     
-    public void tearDown()
+    public void tearDown() throws Exception
     {
-        filter.destroy( FILTER_PARENT, null );
+        filter.destroy();
         Assert.assertEquals( 0, filter.getPoolSize() );
         filter = null;
     }
@@ -122,8 +123,8 @@
             
             future.join();
             
-            filter.destroy( FILTER_PARENT, null );
-            filter.init( FILTER_PARENT, null );
+            filter.onPostRemove( FILTER_PARENT, "", null );
+            filter.onPostAdd( FILTER_PARENT, "", null );
         }
     }
     
@@ -194,6 +195,11 @@
         {
             return false;
         }
+
+        public IoSessionManager getManager()
+        {
+            return null;
+        }
     }
     
     private static class EventOrderChecker implements NextFilter
@@ -302,6 +308,11 @@
         public boolean isClosing()
         {
             return false;
+        }
+
+        public IoSessionManager getManager()
+        {
+            return null;
         }
     }