From f73b655466092169abac34833fb628fce1fcdebe Mon Sep 17 00:00:00 2001
From: jcduff <jcduff@localhost>
Date: Thu, 23 Oct 2008 14:04:24 +0000
Subject: [PATCH] The commit will bring the following features :     - An updated version of the underlying database. BDB JE 3.3 is now used.     - Attribute API refactoring providing a better abstraction and offering improved performances.     - A new GUI called the Control-Panel to replace the Status-Panel: the specifications for this       GUI are available on OpenDS Wiki and contains a link to a mockup.        See <https://www.opends.org/wiki/page/ControlPanelUISpecification>.     - Some changes in the replication protocol to implement "Assured Replication Mode". The        specifications are on OpenDS Wiki at <https://www.opends.org/wiki/page/AssuredMode> and section 7       described some of the replication changes required to support this. Assured Replication is not finished,       but the main replication protocol changes to support it are done. As explained by Gilles on an email on       the Dev mailing list (http://markmail.org/message/46rgo3meq3vriy4a), with these changes the newer versions       of OpenDS may not be able to replicate with OpenDS 1.0 instances.     - Support for Service Tags on the platforms where the functionality is available and enabled. Specifications       are published at <https://www.opends.org/wiki/page/OpenDSServiceTagEnabled>. For more information on       Service Tags see <http://wikis.sun.com/display/ServiceTag/Sun+Service+Tag+FAQ>.     - The Admin Connector service. In order to provide agentry of the OpenDS server at any time, a new service       has been added, dedicated to the administration, configuration and monitoring of the server.       An overview of the Admin Connector service and it's use is available on the       OpenDS wiki <https://www.opends.org/wiki/page/ManagingAdministrationTrafficToTheServer>     - Updates to the various command line tools to support the Admin Connector service.     - Some internal re-architecting of the server to put the foundation of future developments such as virtual       directory services. The new NetworkGroups and WorkFlow internal services which have been specified in       <https://www.opends.org/wiki/page/BasicOperationRoutingThroughNetworkGroup> are now implemented.     - Many bug fixes...

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java |  131 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 107 insertions(+), 24 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 9240a02..3fedc9c 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
@@ -44,6 +44,7 @@
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.StringReader;
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
@@ -55,7 +56,6 @@
 import java.util.logging.Logger;
 
 import org.opends.messages.Message;
-import org.opends.messages.Severity;
 import org.opends.server.admin.client.ManagementContext;
 import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
 import org.opends.server.admin.client.ldap.LDAPConnection;
@@ -129,13 +129,21 @@
   
   /**
    * 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.
+   * 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.opends.server.LdapPort";
 
   /**
+   * The name of the system property that specifies the admin 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_ADMIN_PORT =
+       "org.opends.server.AdminPort";
+
+  /**
    * If this System property is set to true, then the classes/ directory
    * will be copied into the server package setup for the tests.  This allows
    * the server tools (e.g. ldapsearch) to be used on a live server, but it
@@ -152,6 +160,11 @@
   public static final String TEST_ROOT_DN_STRING = "o=test";
   
   /**
+   * The backend if for the test backend
+   */
+  public static final String TEST_BACKEND_ID = "test";
+
+  /**
    * The string representation of the OpenDMK jar file location
    * that will be used as base to determine if snmp is included or not
    */
@@ -184,16 +197,16 @@
   public static boolean SERVER_STARTED = false;
 
   /**
-   * The memory-based backend configured for use in the server.
-   */
-  private static MemoryBackend memoryBackend = null;
-
-  /**
    * The LDAP port the server is bound to on start.
    */
   private static int serverLdapPort;
 
   /**
+   * The Administration port the server is bound to on start.
+   */
+  private static int serverAdminPort;
+
+  /**
    * The JMX port the server is bound to on start.
    */
   private static int serverJmxPort;
@@ -383,9 +396,11 @@
           } catch (Exception e) {}
         }
       }
+
       // Find some free ports for the listeners and write them to the
       // config-chamges.ldif file.
       ServerSocket serverLdapSocket  = null;
+      ServerSocket serverAdminSocket  = null;
       ServerSocket serverJmxSocket   = null;
       ServerSocket serverLdapsSocket = null;
 
@@ -401,6 +416,18 @@
         serverLdapSocket = bindPort(serverLdapPort);
       }
 
+      String adminPort = System.getProperty(PROPERTY_ADMIN_PORT);
+      if (adminPort == null)
+      {
+        serverAdminSocket = bindFreePort();
+        serverAdminPort = serverAdminSocket.getLocalPort();
+      }
+      else
+      {
+        serverAdminPort = Integer.valueOf(adminPort);
+        serverAdminSocket = bindPort(serverAdminPort);
+      }
+
       serverJmxSocket = bindFreePort();
       serverJmxPort = serverJmxSocket.getLocalPort();
 
@@ -422,6 +449,7 @@
       while(line != null)
       {
         line = line.replaceAll("#ldapport#", String.valueOf(serverLdapPort));
+        line = line.replaceAll("#adminport#", String.valueOf(serverAdminPort));
         line = line.replaceAll("#jmxport#", String.valueOf(serverJmxPort));
         line = line.replaceAll("#ldapsport#", String.valueOf(serverLdapsPort));
 
@@ -434,6 +462,7 @@
       reader.close();
 
       serverLdapSocket.close();
+      serverAdminSocket.close();
       serverJmxSocket.close();
       serverLdapsSocket.close();
 
@@ -518,7 +547,14 @@
 
       clearJEBackends();
       restoreServerConfigLdif();
-      memoryBackend = null;  // We need it to be recreated and reregistered
+      // We need it to be recreated and reregistered
+      MemoryBackend memoryBackend =
+        (MemoryBackend) DirectoryServer.getBackend(TEST_BACKEND_ID);
+      if (memoryBackend != null)
+      {
+        memoryBackend.finalizeBackend();
+        DirectoryServer.deregisterBackend(memoryBackend);
+      }
 
       EmbeddedUtils.restartServer(null, null, DirectoryServer.getEnvironmentConfig());
       initializeTestBackend(true);
@@ -563,7 +599,10 @@
   public static void clearDataBackends() throws Exception
   {
     clearJEBackends();
-    memoryBackend.clearMemoryBackend();
+    MemoryBackend memoryBackend =
+      (MemoryBackend) DirectoryServer.getBackend(TEST_BACKEND_ID);
+    if (memoryBackend != null)
+      memoryBackend.clearMemoryBackend();
   }
 
   private static File getTestConfigDir()
@@ -708,11 +747,21 @@
     startServer();
 
     DN baseDN = DN.decode(TEST_ROOT_DN_STRING);
+
+    // Retrieve backend. Warning: it is important to perform this each time,
+    // because a test may have disabled then enabled the backend (i.e a test
+    // performing an import task). As it is a memory backend, when the backend
+    // is re-enabled, a new backend object is in fact created and old reference
+    // to memory backend must be invalidated. So to prevent this problem, we
+    // retrieve the memory backend reference each time before cleaning it.
+    MemoryBackend memoryBackend =
+        (MemoryBackend)DirectoryServer.getBackend(TEST_BACKEND_ID);
+
     if (memoryBackend == null)
     {
       memoryBackend = new MemoryBackend();
-      memoryBackend.setBackendID("test");
-      memoryBackend.setBaseDNs(new DN[] { baseDN });
+      memoryBackend.setBackendID(TEST_BACKEND_ID);
+      memoryBackend.setBaseDNs(new DN[] {baseDN});
       memoryBackend.initializeBackend();
       DirectoryServer.registerBackend(memoryBackend);
     }
@@ -915,6 +964,17 @@
   }
 
   /**
+   * Get the Admin port the test environment Directory Server instance is
+   * running on.
+   *
+   * @return The port number.
+   */
+  public static int getServerAdminPort()
+  {
+    return serverAdminPort;
+  }
+
+  /**
    * Get the JMX port the test environment Directory Server instance is
    * running on.
    *
@@ -1060,7 +1120,7 @@
   }
 
   /**
-   * This is a convience method that constructs an Entry from the specified
+   * This is a convenience method that constructs an Entry from the specified
    * lines of LDIF.  Here's a sample usage
    *
    <pre>
@@ -1078,7 +1138,7 @@
   }
 
   /**
-   * This is a convience method that constructs an List of EntryS from the
+   * This is a convenience method that constructs an List of EntryS from the
    * specified lines of LDIF.  Here's a sample usage
    *
    <pre>
@@ -1127,7 +1187,7 @@
 
 
   /**
-   * Deletess the provided entry from the Directory Server using an
+   * Deletes the provided entry from the Directory Server using an
    * internal operation.
    *
    * @param  entry  The entry to be added.
@@ -1259,7 +1319,7 @@
    *
    * @throws  Exception  If an unexpected problem occurs.
    */
-  public static int applyModifications(String... lines)
+  public static int applyModifications(boolean useAdminPort, String... lines)
          throws Exception
   {
     if (! SERVER_STARTED)
@@ -1278,8 +1338,23 @@
       "-a",
       "-f", path
     };
-
-    return LDAPModify.mainModify(args, false, null, null);
+    String[] adminArgs =
+    {
+      "--noPropertiesFile",
+      "-h", "127.0.0.1",
+      "-p", String.valueOf(serverAdminPort),
+      "-Z", "-X",
+      "-D", "cn=Directory Manager",
+      "-w", "password",
+      "-a",
+      "-f", path
+    };
+    
+    if (useAdminPort) {
+      return LDAPModify.mainModify(adminArgs, false, null, null);
+    } else {
+      return LDAPModify.mainModify(args, false, null, null);
+    }
   }
 
 
@@ -1630,19 +1705,27 @@
    */
   public static void dsconfig(String... args)
   {
-    String[] fullArgs = new String[args.length + 10];
+    String hostName;
+    try {
+      hostName = InetAddress.getLocalHost().getHostName();
+    } catch (Exception e) {
+       hostName="Unknown (" + e + ")";
+    }
+    
+    String[] fullArgs = new String[args.length + 11];
     fullArgs[0] = "-h";
-    fullArgs[1] = "127.0.0.1";
+    fullArgs[1] = hostName;
     fullArgs[2] = "-p";
-    fullArgs[3] = String.valueOf(serverLdapPort);
+    fullArgs[3] = String.valueOf(serverAdminPort);
     fullArgs[4] = "-D";
     fullArgs[5] = "cn=Directory Manager";
     fullArgs[6] = "-w";
     fullArgs[7] = "password";
     fullArgs[8] = "-n";
     fullArgs[9] = "--noPropertiesFile";
+    fullArgs[10] = "-X";
 
-    System.arraycopy(args, 0, fullArgs, 10, args.length);
+    System.arraycopy(args, 0, fullArgs, 11, args.length);
 
     assertEquals(DSConfig.main(fullArgs, false, System.out, System.err), 0);
   }
@@ -1667,9 +1750,9 @@
    */
   public static RootCfgClient getRootConfiguration() throws Exception
   {
-    LDAPConnection connection = JNDIDirContextAdaptor.simpleBind(
+    LDAPConnection connection = JNDIDirContextAdaptor.simpleSSLBind(
         "127.0.0.1",
-        serverLdapPort,
+        serverAdminPort,
         "cn=Directory Manager",
         "password");
 

--
Gitblit v1.10.0