diff options
Diffstat (limited to 'qpid/java/common/src')
| -rw-r--r-- | qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java | 53 |
1 files changed, 2 insertions, 51 deletions
diff --git a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java b/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java index 8a14466aeb..ec06400b7d 100644 --- a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java +++ b/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java @@ -29,8 +29,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.net.DatagramSocket; -import java.net.ServerSocket; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -166,9 +164,10 @@ public class QpidTestCase extends TestCase throw new IllegalArgumentException("Invalid start port: " + fromPort); } + PortHelper portHelper = new PortHelper(); for (int i = fromPort; i <= MAX_PORT_NUMBER; i++) { - if (available(i)) { + if (portHelper.isPortAvailable(i)) { return i; } } @@ -176,54 +175,6 @@ public class QpidTestCase extends TestCase throw new NoSuchElementException("Could not find an available port above " + fromPort); } - /** - * Checks to see if a specific port is available. - * - * @param port the port to check for availability - */ - private boolean available(int port) - { - if ((port < MIN_PORT_NUMBER) || (port > MAX_PORT_NUMBER)) - { - throw new IllegalArgumentException("Invalid start port: " + port); - } - - ServerSocket ss = null; - DatagramSocket ds = null; - try - { - ss = new ServerSocket(port); - ss.setReuseAddress(true); - ds = new DatagramSocket(port); - ds.setReuseAddress(true); - return true; - } - catch (IOException e) - { - } - finally - { - if (ds != null) - { - ds.close(); - } - - if (ss != null) - { - try - { - ss.close(); - } - catch (IOException e) - { - /* should not be thrown */ - } - } - } - - return false; - } - public int findFreePort() { return getNextAvailable(10000); |
