From 9e4f2aba042df34b753b119b91025948c0d698db Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Sat, 13 Oct 2012 09:16:20 +0000
Subject: [PATCH] OPENDJ-612: SDK: Race conditions installing client/server filter chains during connect/bind/accept
---
opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java | 60 ++++++++++--------------------------------------------------
1 files changed, 10 insertions(+), 50 deletions(-)
diff --git a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java
index b78acb4..a07a24f 100644
--- a/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java
+++ b/opendj3/opendj-ldap-sdk/src/test/java/org/forgerock/opendj/ldap/TestCaseUtils.java
@@ -38,28 +38,6 @@
*/
public final class TestCaseUtils {
/**
- * The name of the system property that specifies the ldap port. Set this
- * property when running the server if you want to use a given port number,
- * otherwise a port is chosen randomly at test startup time.
- */
- public static final String PROPERTY_LDAP_PORT = "org.forgerock.opendj.test.LdapPort";
-
- /**
- * Port number that's used by the server. Need to be used by the test cases
- * to create connections.
- */
- public static final int PORT;
-
- static {
- final String ldapPort = System.getProperty(PROPERTY_LDAP_PORT);
- if (ldapPort != null) {
- PORT = Integer.valueOf(ldapPort);
- } else {
- PORT = findFreePort();
- }
- }
-
- /**
* Creates a temporary text file with the specified contents. It will be
* marked for automatic deletion when the JVM exits.
*
@@ -88,24 +66,6 @@
*
* @return The free port.
*/
- public static int findFreePort() {
- try {
- ServerSocket serverLdapSocket = new ServerSocket();
- serverLdapSocket.setReuseAddress(true);
- serverLdapSocket.bind(new InetSocketAddress("127.0.0.1", 0));
- final int port = serverLdapSocket.getLocalPort();
- serverLdapSocket.close();
- return port;
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Finds a free server socket port on the local host.
- *
- * @return The free port.
- */
public static SocketAddress findFreeSocketAddress() {
try {
ServerSocket serverLdapSocket = new ServerSocket();
@@ -134,22 +94,13 @@
}
/**
- * Returns the port which the test server listens on.
- *
- * @return The LDAP port.
- */
- public static int getLdapPort() {
- return PORT;
- }
-
- /**
* Starts the test ldap server.
*
* @throws Exception
* If an error occurs when starting the server.
*/
public static void startServer() throws Exception {
- LDAPServer.getInstance().start(PORT);
+ LDAPServer.getInstance().start();
}
/**
@@ -158,4 +109,13 @@
public static void stopServer() {
LDAPServer.getInstance().stop();
}
+
+ /**
+ * Returns the socket address of the server.
+ *
+ * @return The socket address of the server.
+ */
+ public static SocketAddress getServerSocketAddress() {
+ return LDAPServer.getInstance().getSocketAddress();
+ }
}
--
Gitblit v1.10.0