summaryrefslogtreecommitdiff
path: root/qpid/java/common/src/test
diff options
context:
space:
mode:
authorRobert Godfrey <rgodfrey@apache.org>2012-06-12 17:01:14 +0000
committerRobert Godfrey <rgodfrey@apache.org>2012-06-12 17:01:14 +0000
commitb69978463135937995fbcd15a0f7b30aa63044e5 (patch)
treefa00fc5709725780ddd72d3efb5bd7dfbb41cfa2 /qpid/java/common/src/test
parent724940323509794bf8001beb6a6782cadf07cbd5 (diff)
downloadqpid-python-b69978463135937995fbcd15a0f7b30aa63044e5.tar.gz
QPID-4062 : [Java Tests] Java system tests sometimes fail due to JMX port already initialised (Applied patch from Philip Harvey
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1349443 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/common/src/test')
-rw-r--r--qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java53
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);