Author: bago
Date: Thu Aug  3 16:17:17 2006
New Revision: 428561

URL: http://svn.apache.org/viewvc?rev=428561&view=rev
Log:
Backported from trunk for failing tests:
r427689: Improve the next free port acquisition algorythm trying to bind it 
before returning.
r427729: Make sure that the test socket is reusable. I have not seen problems 
without this but maybe this is needed with different implementations.

Modified:
    james/server/branches/v2.3/src/test/org/apache/james/test/util/Util.java

Modified: 
james/server/branches/v2.3/src/test/org/apache/james/test/util/Util.java
URL: 
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/test/util/Util.java?rev=428561&r1=428560&r2=428561&view=diff
==============================================================================
--- james/server/branches/v2.3/src/test/org/apache/james/test/util/Util.java 
(original)
+++ james/server/branches/v2.3/src/test/org/apache/james/test/util/Util.java 
Thu Aug  3 16:17:17 2006
@@ -20,6 +20,9 @@
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.james.smtpserver.*;
 
+import java.io.IOException;
+import java.net.ServerSocket;
+
 /**
  * some utilities for James unit testing
  */
@@ -50,8 +53,21 @@
      * @return port number
      */
     protected synchronized static int getNextNonPrivilegedPort() {
+        // Hack to increase probability that the port is bindable
+        while (true) {
+            try {
         PORT_LAST_USED++;
         if (PORT_LAST_USED > PORT_RANGE_END) PORT_LAST_USED = PORT_RANGE_START;
+                ServerSocket ss;
+                ss = new ServerSocket(PORT_LAST_USED);
+                ss.setReuseAddress(true);
+                ss.close();
+                break;
+            } catch (IOException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
         return PORT_LAST_USED;
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to