Author: dkulp
Date: Tue Feb 14 18:43:25 2012
New Revision: 1244157
URL: http://svn.apache.org/viewvc?rev=1244157&view=rev
Log:
Merged revisions 1243632 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1243632 | dkulp | 2012-02-13 13:10:16 -0500 (Mon, 13 Feb 2012) | 3 lines
Change the dynamically allocated port algorithm to make it more
predictable and help make sure two servers aren't randomly assigned the
same port.
........
Modified:
cxf/branches/2.5.x-fixes/ (props changed)
cxf/branches/2.5.x-fixes/parent/pom.xml
cxf/branches/2.5.x-fixes/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java
Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.5.x-fixes/parent/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/parent/pom.xml?rev=1244157&r1=1244156&r2=1244157&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/parent/pom.xml (original)
+++ cxf/branches/2.5.x-fixes/parent/pom.xml Tue Feb 14 18:43:25 2012
@@ -339,7 +339,6 @@
<parallel>${cxf.surefire.parallel.mode}</parallel>
<systemPropertyVariables>
<org.apache.ws.commons.schema.protectReadOnlyCollections>${cxf.protect-xmlschema-collections}</org.apache.ws.commons.schema.protectReadOnlyCollections>
- <useRandomPorts>true</useRandomPorts>
<cxf.validateServiceSchemas>${cxf.validateServices}</cxf.validateServiceSchemas>
<java.awt.headless>${java.awt.headless}</java.awt.headless>
<java.util.logging.config.file>${basedir}/target/test-classes/logging.properties</java.util.logging.config.file>
Modified:
cxf/branches/2.5.x-fixes/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java?rev=1244157&r1=1244156&r2=1244157&view=diff
==============================================================================
---
cxf/branches/2.5.x-fixes/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java
(original)
+++
cxf/branches/2.5.x-fixes/testutils/src/main/java/org/apache/cxf/testutil/common/TestUtil.java
Tue Feb 14 18:43:25 2012
@@ -30,17 +30,24 @@ import java.util.Properties;
public final class TestUtil {
- private static boolean useRandomPorts =
Boolean.getBoolean("useRandomPorts");
private static int portNum = -1;
private static Properties ports = new Properties();
+ @SuppressWarnings("unused")
+ private static ServerSocket lock;
+
static {
int pn = 9000;
while (portNum == -1) {
try {
+ //we'll hold a socket open and allocate ports up from that
socket.
+ //if a second CXF build process (like running parallel builds)
+ //tries to open the socket, it will throw an exception and it
+ //will try again 100 ports up. At this point, 100 ports is
WAY
+ //more than enough. We can adjust later if needed.
ServerSocket sock = new ServerSocket(pn);
- sock.close();
- portNum = pn;
+ lock = sock;
+ portNum = pn + 1;
} catch (IOException ex) {
pn += 100;
}
@@ -110,21 +117,19 @@ public final class TestUtil {
ports.setProperty("testutil.ports." + name, p);
}
}
- if (p == null) {
- if (useRandomPorts) {
- try {
- ServerSocket sock = new ServerSocket(0);
- p = Integer.toString(sock.getLocalPort());
- sock.close();
- } catch (IOException ex) {
- //
- }
- } else {
- p = Integer.toString(portNum++);
+ while (p == null) {
+ int pn = portNum++;
+ try {
+ //make sure the port can be opened. Something MIGHT be
running on it.
+ ServerSocket sock = new ServerSocket(pn);
+ sock.close();
+ p = Integer.toString(pn);
+ } catch (IOException ex) {
+ //
}
- ports.put("testutil.ports." + name, p);
- System.setProperty("testutil.ports." + name, p);
}
+ ports.put("testutil.ports." + name, p);
+ System.setProperty("testutil.ports." + name, p);
return p;
}
}