Author: berndf Date: Fri Aug 25 08:05:49 2006 New Revision: 436824 URL: http://svn.apache.org/viewvc?rev=436824&view=rev Log: avoid endless loop when no test port is available
Modified: james/server/trunk/src/test/org/apache/james/test/util/Util.java Modified: james/server/trunk/src/test/org/apache/james/test/util/Util.java URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/test/util/Util.java?rev=436824&r1=436823&r2=436824&view=diff ============================================================================== --- james/server/trunk/src/test/org/apache/james/test/util/Util.java (original) +++ james/server/trunk/src/test/org/apache/james/test/util/Util.java Fri Aug 25 08:05:49 2006 @@ -78,20 +78,25 @@ */ protected synchronized static int getNextNonPrivilegedPort() { // Hack to increase probability that the port is bindable + int nextPortCandidate = PORT_LAST_USED; while (true) { try { - PORT_LAST_USED++; - if (PORT_LAST_USED > PORT_RANGE_END) PORT_LAST_USED = PORT_RANGE_START; + nextPortCandidate++; + if (PORT_LAST_USED == nextPortCandidate) throw new RuntimeException("no free port found"); + if (nextPortCandidate > PORT_RANGE_END) nextPortCandidate = PORT_RANGE_START; // start over + + // test, port is available ServerSocket ss; - ss = new ServerSocket(PORT_LAST_USED); + ss = new ServerSocket(nextPortCandidate); ss.setReuseAddress(true); ss.close(); break; } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); + continue; // try next port } } + PORT_LAST_USED = nextPortCandidate; return PORT_LAST_USED; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]