From 26ff1f0755680cbce7b5bdb136750b2b1bc9e4ed Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Fri, 10 Nov 2006 08:05:56 +0000
Subject: [PATCH] issue 508  These changes implement a window mechanism in the sycnhronization protocol.

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java |   38 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
index 2494e27..c534159 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -70,6 +70,14 @@
        "org.opends.server.BuildRoot";
 
   /**
+   * The name of the system property that specifies the ldap port.
+   * Set this prtoperty when running the server if you want to use a given
+   * port number, otherwise a port is choosed randomly at test startup time.
+   */
+  public static final String PROPERTY_LDAP_PORT =
+       "org.opends.server.LdapPort";
+  
+  /**
    * The string representation of the DN that will be used as the base entry for
    * the test backend.  This must not be changed, as there are a number of test
    * cases that depend on this specific value of "o=test".
@@ -205,8 +213,17 @@
     ServerSocket serverJmxSocket   = null;
     ServerSocket serverLdapsSocket = null;
 
-    serverLdapSocket = bindFreePort();
-    serverLdapPort = serverLdapSocket.getLocalPort();
+    String ldapPort = System.getProperty(PROPERTY_LDAP_PORT);
+    if (ldapPort == null)
+    {
+      serverLdapSocket = bindFreePort();
+      serverLdapPort = serverLdapSocket.getLocalPort();
+    }
+    else
+    {
+      serverLdapPort = Integer.valueOf(ldapPort);
+      serverLdapSocket = bindPort(serverLdapPort);
+    }
 
     serverJmxSocket = bindFreePort();
     serverJmxPort = serverJmxSocket.getLocalPort();
@@ -263,6 +280,23 @@
   }
 
   /**
+   * Binds to the given socket port on the local host.
+   * @return the bounded Server socket.
+   *
+   * @throws IOException in case of underlying exception.
+   * @throws SocketException in case of underlying exception.
+   */
+  private static ServerSocket bindPort(int port)
+          throws IOException, SocketException
+  {
+    ServerSocket serverLdapSocket;
+    serverLdapSocket = new ServerSocket();
+    serverLdapSocket.setReuseAddress(true);
+    serverLdapSocket.bind(new InetSocketAddress("127.0.0.1", port));
+    return serverLdapSocket;
+  }
+
+  /**
    * Find and binds to a free server socket port on the local host.
    * @return the bounded Server socket.
    *

--
Gitblit v1.10.0