directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r329232 - in /directory/network: branches/0.8/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
Date Fri, 28 Oct 2005 16:02:36 GMT
Author: trustin
Date: Fri Oct 28 09:02:24 2005
New Revision: 329232

URL: http://svn.apache.org/viewcvs?rev=329232&view=rev
Log:
* Removed unused tests in ConnectorTest
* Merged the changes of ConnectorTest in trunk to branches/0.8


Modified:
    directory/network/branches/0.8/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
    directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java

Modified: directory/network/branches/0.8/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/0.8/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java?rev=329232&r1=329231&r2=329232&view=diff
==============================================================================
--- directory/network/branches/0.8/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
(original)
+++ directory/network/branches/0.8/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
Fri Oct 28 09:02:24 2005
@@ -18,9 +18,9 @@
  */
 package org.apache.mina.examples.echoserver;
 
+import java.net.BindException;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
-import java.net.SocketAddress;
 
 import junit.framework.Assert;
 
@@ -44,20 +44,10 @@
  */
 public class ConnectorTest extends AbstractTest
 {
-    private int clientPort;
-    
     public ConnectorTest()
     {
     }
 
-    public void setUp() throws Exception
-    {
-        super.setUp();
-        clientPort = port;
-        clientPort = AvailablePortFinder.getNextAvailable( clientPort + 1 );
-        System.out.println( "Using port " + clientPort + " as local address" );
-    }
-    
     public void testTCP() throws Exception
     {
         IoConnector connector = new SocketConnector();
@@ -95,42 +85,50 @@
     
     private void testConnector( IoConnector connector ) throws Exception
     {
-        InetSocketAddress localAddress = new InetSocketAddress( clientPort );
-
-        System.out.println("* Without localAddress and initializer");
-        testConnector( connector, null );
-        
-        System.out.println("* Without localAddress and with initializer");
-        testConnector( connector, null );
-
-        // Tests below fail in Windows platform.
-        if( System.getProperty("os.name").toLowerCase().indexOf( "windows" ) >= 0 )
-        {
-            // skip further tests
-            System.out.println( "** Skipping some tests that fails in Windows platform."
);
-            return;
-        }
-        
-        System.out.println("* With localAddress and without initializer");
-        testConnector( connector, localAddress );
+        System.out.println("* Without localAddress");
+        testConnector( connector, false );
         
-        // It takes some time for local address to be cleared by OS,
-        // so let's just get a new one rather than waiting for it.
-        clientPort = AvailablePortFinder.getNextAvailable( clientPort + 1 );
-        localAddress = new InetSocketAddress( clientPort );
-
-        System.out.println("* With localAddress and initializer");
-        testConnector( connector, localAddress );
+        System.out.println("* With localAddress");
+        testConnector( connector, true );
     }
     
-    private void testConnector( IoConnector connector, SocketAddress localAddress ) throws
Exception
+    private void testConnector( IoConnector connector, boolean useLocalAddress ) throws Exception
     {
         EchoConnectorHandler handler = new EchoConnectorHandler();
         ByteBuffer readBuf = handler.readBuf;
-        IoSession session = connector.connect(
-                new InetSocketAddress( InetAddress.getLocalHost(), port ),
-                localAddress,
-                handler );
+
+        IoSession session = null;
+        if( !useLocalAddress )
+        {
+            session = connector.connect(
+                    new InetSocketAddress( InetAddress.getLocalHost(), port ),
+                    handler );
+        }
+        else
+        {
+            int clientPort = port;
+            for( int i = 0; i < 65536; i ++ )
+            {
+                clientPort = AvailablePortFinder.getNextAvailable( clientPort + 1 );
+                try
+                {
+                    session = connector.connect(
+                            new InetSocketAddress( InetAddress.getLocalHost(), port ),
+                            new InetSocketAddress( clientPort ),
+                            handler );
+                    break;
+                }
+                catch( BindException e )
+                {
+                    // Try again until we succeed to bind.
+                }
+            }
+
+            if( session == null )
+            {
+                Assert.fail( "Failed to find out an appropriate local address." );
+            }
+        }
         
         for( int i = 0; i < 10; i ++ )
         {

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=329232&r1=329231&r2=329232&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
Fri Oct 28 09:02:24 2005
@@ -52,11 +52,6 @@
     {
     }
 
-    public void setUp() throws Exception
-    {
-        super.setUp();
-    }
-    
     public void testTCP() throws Exception
     {
         IoConnector connector = new SocketConnector();



Mime
View raw message