directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r158871 - in directory/network/trunk/src: java/org/apache/mina/io/datagram/ java/org/apache/mina/io/socket/ java/org/apache/mina/util/ test/org/apache/mina/io/ test/org/apache/mina/io/datagram/ test/org/apache/mina/io/socket/ test/org/apache/mina/util/
Date Thu, 24 Mar 2005 03:14:40 GMT
Author: trustin
Date: Wed Mar 23 19:14:38 2005
New Revision: 158871

URL: http://svn.apache.org/viewcvs?view=rev&rev=158871
Log:
* Removed some System.out.println()s
* Added more test cases

Added:
    directory/network/trunk/src/test/org/apache/mina/io/
    directory/network/trunk/src/test/org/apache/mina/io/AbstractBindTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/io/datagram/
    directory/network/trunk/src/test/org/apache/mina/io/datagram/BindTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/io/socket/
    directory/network/trunk/src/test/org/apache/mina/io/socket/BindTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/util/QueueTest.java   (with props)
Modified:
    directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketAcceptor.java
    directory/network/trunk/src/java/org/apache/mina/util/Queue.java

Modified: directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java?view=diff&r1=158870&r2=158871
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java Wed
Mar 23 19:14:38 2005
@@ -459,7 +459,7 @@
                 break;
             }
 
-            DatagramChannel ch = ( DatagramChannel ) channels.get( request.address );
+            DatagramChannel ch = ( DatagramChannel ) channels.remove( request.address );
             // close the channel
             try
             {

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketAcceptor.java?view=diff&r1=158870&r2=158871
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketAcceptor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketAcceptor.java Wed Mar
23 19:14:38 2005
@@ -138,9 +138,7 @@
             {
                 try
                 {
-                    request.wait( 1000 );
-
-                    System.out.println( "request.done = " + request.done );
+                    request.wait();
                 }
                 catch( InterruptedException e )
                 {
@@ -291,8 +289,6 @@
             synchronized( registerQueue )
             {
                 req = ( RegistrationRequest ) registerQueue.pop();
-
-                System.out.println( "popped request = " + req );
             }
 
             if( req == null )
@@ -364,7 +360,7 @@
                 break;
             }
 
-            ServerSocketChannel ssc = ( ServerSocketChannel ) channels.get( request.address
);
+            ServerSocketChannel ssc = ( ServerSocketChannel ) channels.remove( request.address
);
             
             // close the channel
             try

Modified: directory/network/trunk/src/java/org/apache/mina/util/Queue.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/util/Queue.java?view=diff&r1=158870&r2=158871
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/util/Queue.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/util/Queue.java Wed Mar 23 19:14:38 2005
@@ -53,6 +53,14 @@
         items = new Object[ DEFAULT_CAPACITY ];
         mask = DEFAULT_MASK;
     }
+    
+    /**
+     * Returns the capacity of this queue.
+     */
+    public int capacity()
+    {
+        return items.length;
+    }
 
     /**
      * Clears this queue.

Added: directory/network/trunk/src/test/org/apache/mina/io/AbstractBindTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/io/AbstractBindTest.java?view=auto&rev=158871
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/io/AbstractBindTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/io/AbstractBindTest.java Wed Mar 23 19:14:38
2005
@@ -0,0 +1,107 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.io;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.mina.examples.echoserver.EchoProtocolHandler;
+
+public class AbstractBindTest extends TestCase
+{
+    protected final IoAcceptor acceptor;
+    protected int port;
+
+    public AbstractBindTest( IoAcceptor acceptor )
+    {
+        this.acceptor = acceptor;
+    }
+    
+    public void setUp() throws IOException
+    {
+        // Find an availble test port and bind to it.
+        boolean socketBound = false;
+
+        // 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;
+            try
+            {
+                acceptor.bind( new InetSocketAddress( port ),
+                        new EchoProtocolHandler() );
+                socketBound = true;
+                break;
+            }
+            catch( IOException e )
+            {
+            }
+        }
+
+        // If there is no port available, test fails.
+        if( !socketBound )
+        {
+            throw new IOException( "Cannot bind any test port." );
+        }
+
+        System.out.println( "Using port " + port + " for testing." );
+    }
+    
+    public void tearDown()
+    {
+        try
+        {
+            acceptor.unbind( new InetSocketAddress( port ) );
+        }
+        catch( Exception e )
+        {
+            // ignore
+        }
+    }
+    
+    public void testDuplicateBind()
+    {
+        try
+        {
+            acceptor.bind( new InetSocketAddress( port ), new EchoProtocolHandler() );
+            Assert.fail( "IOException is not thrown" );
+        }
+        catch( IOException e )
+        {
+        }
+    }
+
+    public void testDuplicateUnbind()
+    {
+        // this should succeed
+        acceptor.unbind( new InetSocketAddress( port ) );
+        
+        try
+        {
+            // this should fail
+            acceptor.unbind( new InetSocketAddress( port ) );
+            Assert.fail( "Exception is not thrown" );
+        }
+        catch( Exception e )
+        {
+        }
+    }
+    
+    public void testManyTimes() throws IOException
+    {
+        InetSocketAddress addr = new InetSocketAddress( port );
+        EchoProtocolHandler handler = new EchoProtocolHandler();
+        for( int i = 0; i < 8192; i++ )
+        {
+            acceptor.unbind( addr );
+            acceptor.bind( addr, handler );
+        }
+    }
+
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/io/AbstractBindTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/io/datagram/BindTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/io/datagram/BindTest.java?view=auto&rev=158871
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/io/datagram/BindTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/io/datagram/BindTest.java Wed Mar 23
19:14:38 2005
@@ -0,0 +1,18 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.io.datagram;
+
+import java.io.IOException;
+
+import org.apache.mina.io.AbstractBindTest;
+
+public class BindTest extends AbstractBindTest
+{
+
+    public BindTest() throws IOException
+    {
+        super( new DatagramAcceptor() );
+    }
+
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/io/datagram/BindTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/io/socket/BindTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/io/socket/BindTest.java?view=auto&rev=158871
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/io/socket/BindTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/io/socket/BindTest.java Wed Mar 23 19:14:38
2005
@@ -0,0 +1,18 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.io.socket;
+
+import java.io.IOException;
+
+import org.apache.mina.io.AbstractBindTest;
+
+public class BindTest extends AbstractBindTest
+{
+
+    public BindTest() throws IOException
+    {
+        super( new SocketAcceptor() );
+    }
+
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/io/socket/BindTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/util/QueueTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/util/QueueTest.java?view=auto&rev=158871
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/util/QueueTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/util/QueueTest.java Wed Mar 23 19:14:38
2005
@@ -0,0 +1,59 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.util;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class QueueTest extends TestCase
+{
+    private int pushCount;
+    private int popCount;
+    
+    public void setUp()
+    {
+        pushCount = 0;
+        popCount = 0;
+    }
+
+    public void testRotation()
+    {
+        Queue q = new Queue(); // DEFAULT_CAPACITY = 4
+        testRotation0( q );
+    }
+    
+    public void testExpandingRotation()
+    {
+        Queue q = new Queue(); // DEFAULT_CAPACITY = 4
+        for( int i = 0; i < 10; i ++ )
+        {
+            testRotation0( q );
+
+            // make expansion happen
+            int oldCapacity = q.capacity();
+            for( int j = q.capacity(); j >= 0; j-- )
+            {
+                q.push( new Integer( ++pushCount ) );
+            }
+            
+            Assert.assertTrue( q.capacity() > oldCapacity );
+            testRotation0( q );
+        }
+    }
+    
+    private void testRotation0( Queue q )
+    {
+        for( int i = 0; i < q.capacity() * 7 / 4; i ++ )
+        {
+            q.push( new Integer( ++pushCount ) );
+            Assert.assertEquals( ++popCount, ( ( Integer ) q.pop() ).intValue() );
+        }
+    }
+    
+    public static void main( String[] args )
+    {
+        junit.textui.TestRunner.run( QueueTest.class );
+    }
+
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/util/QueueTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision



Mime
View raw message