diff options
| author | Keith Wall <kwall@apache.org> | 2014-07-10 12:46:42 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2014-07-10 12:46:42 +0000 |
| commit | 3f9ee367879754bbbca404244ac3a911dfda1c5c (patch) | |
| tree | 795f48ec6e7c0dd9bdb22f01bd7c3fc664e7c251 /qpid/java/qpid-test-utils | |
| parent | dba98eb0b4908eee8ed688b4480b4ba4b7f6a3c1 (diff) | |
| download | qpid-python-3f9ee367879754bbbca404244ac3a911dfda1c5c.tar.gz | |
NO-JIRA: [Java Test Framework] PortHelper, apply socket option *before* binding the socket
* Also removed the datagramsocket bind. We don't used datagram sockets at all at the moment, so
the complication/overhead seems unjustifiable.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1609454 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/qpid-test-utils')
| -rw-r--r-- | qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java b/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java index d3586c364f..e6e99175a1 100644 --- a/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java +++ b/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java @@ -19,7 +19,7 @@ package org.apache.qpid.test.utils; import java.io.IOException; -import java.net.DatagramSocket; +import java.net.InetSocketAddress; import java.net.ServerSocket; import java.util.Set; @@ -31,7 +31,7 @@ public class PortHelper private static final int DEFAULT_TIMEOUT_MILLIS = 5000; - private int timeout = DEFAULT_TIMEOUT_MILLIS; + private int _timeout = DEFAULT_TIMEOUT_MILLIS; public void waitUntilPortsAreFree(Set<Integer> ports) { @@ -48,14 +48,14 @@ public class PortHelper private void waitUntilPortIsFree(int port) { long startTime = System.currentTimeMillis(); - long deadline = startTime + timeout; + long deadline = startTime + _timeout; boolean alreadyFailed = false; while (true) { if (System.currentTimeMillis() > deadline) { - throw new RuntimeException("Timed out after " + timeout + " ms waiting for port " + port + " to become available"); + throw new RuntimeException("Timed out after " + _timeout + " ms waiting for port " + port + " to become available"); } if (isPortAvailable(port)) @@ -85,14 +85,12 @@ public class PortHelper public boolean isPortAvailable(int port) { ServerSocket serverSocket = null; - DatagramSocket datagramSocket = null; - try { - serverSocket = new ServerSocket(port); + serverSocket = new ServerSocket(); serverSocket.setReuseAddress(true); // ensures that the port is subsequently usable - datagramSocket = new DatagramSocket(port); - datagramSocket.setReuseAddress(true); + serverSocket.bind(new InetSocketAddress(port)); + return true; } catch (IOException e) @@ -110,18 +108,16 @@ public class PortHelper } catch (IOException e) { - throw new RuntimeException("Couldn't close port " + port + " that we created to check its availability", e); + throw new RuntimeException("Couldn't close port " + + port + + " that we created to check its availability", e); } } - if(datagramSocket != null) - { - datagramSocket.close(); - } } } public void setTimeout(int timeout) { - this.timeout = timeout; + this._timeout = timeout; } } |
