From a3dad177f76ca95ba2a01ba58e53fb3441ebe0ac Mon Sep 17 00:00:00 2001
From: mrossign <mrossign@localhost>
Date: Fri, 19 Dec 2008 11:59:56 +0000
Subject: [PATCH] - support for dynamic domain group id reconfiguration in replication server - unit test for group id reconfiguration in replication server as well as in directory server

---
 opends/src/server/org/opends/server/replication/server/ReplicationServer.java                            |   19 ++++++++-
 opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java                      |   34 ++++++++++------
 opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/GroupIdHandshakeTest.java |   63 ++++++++++++++++++++++++++++++-
 3 files changed, 97 insertions(+), 19 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationServer.java b/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
index b0e043f..6d88711 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
+++ b/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
@@ -634,8 +634,9 @@
   public ConfigChangeResult applyConfigurationChange(
       ReplicationServerCfg configuration)
   {
-    // Changing those properties don't need specific code.
-    // They will be applied for next connections.
+    // Some of those properties change don't need specific code.
+    // They will be applied for next connections. Some others have immediate
+    // effect
 
     disconnectRemovedReplicationServers(configuration.getReplicationServer());
 
@@ -724,6 +725,18 @@
       }
     }
 
+    // Changed the group id ?
+    byte newGroupId = (byte)configuration.getGroupId();
+    if (newGroupId != groupId)
+    {
+      groupId = newGroupId;
+      // Have a new group id: Disconnect every servers.
+      for (ReplicationServerDomain replicationServerDomain : baseDNs.values())
+      {
+        replicationServerDomain.stopAllServers();
+      }
+    }
+
     if ((configuration.getReplicationDBDirectory() != null) &&
         (!dbDirname.equals(configuration.getReplicationDBDirectory())))
     {
@@ -1127,7 +1140,7 @@
 
     for (ReplicationServerDomain replicationServerDomain: baseDNs.values())
     {
-      replicationServerDomain.stopServers(serversToDisconnect);
+      replicationServerDomain.stopReplicationServers(serversToDisconnect);
     }
   }
 }
diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java b/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
index 2768301..df6b067 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
+++ b/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
@@ -886,12 +886,12 @@
   }
 
   /**
-   * Stop operations with a list of servers.
+   * Stop operations with a list of replication servers.
    *
    * @param replServers the replication servers for which
    * we want to stop operations
    */
-  public void stopServers(Collection<String> replServers)
+  public void stopReplicationServers(Collection<String> replServers)
   {
     for (ServerHandler handler : replicationServers.values())
     {
@@ -901,6 +901,24 @@
   }
 
   /**
+   * Stop operations with all servers this domain is connected with (RS and DS).
+   */
+  public void stopAllServers()
+  {
+    // Close session with other replication servers
+    for (ServerHandler serverHandler : replicationServers.values())
+    {
+      stopServer(serverHandler);
+    }
+
+    // Close session with other LDAP servers
+    for (ServerHandler serverHandler : directoryServers.values())
+    {
+      stopServer(serverHandler);
+    }
+  }
+
+  /**
    * Checks that a DS is not connected with same id.
    *
    * @param handler the DS we want to check
@@ -1478,17 +1496,7 @@
     // Terminate the assured timer
     assuredTimeoutTimer.cancel();
 
-    // Close session with other changelogs
-    for (ServerHandler serverHandler : replicationServers.values())
-    {
-      stopServer(serverHandler);
-    }
-
-    // Close session with other LDAP servers
-    for (ServerHandler serverHandler : directoryServers.values())
-    {
-      stopServer(serverHandler);
-    }
+    stopAllServers();
 
     // Shutdown the dbHandlers
     synchronized (sourceDbHandlers)
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/GroupIdHandshakeTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/GroupIdHandshakeTest.java
index 5da9444..705ef45 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/GroupIdHandshakeTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/GroupIdHandshakeTest.java
@@ -461,6 +461,10 @@
    * (not their group id)
    * - Restart RS2 and RS3, DS1 should reconnect to RS2 (with GID=2, his GID)
    * and DS2 should connect to RS3 (with GID=3, his GID)
+   * - Change group id of DS1 and DS2 to 1 : they should reconnect to RS1
+   * - Change group id of RS3 to 1
+   * - Change group id of RS1 to 3: DS1 and DS2 should reconnect to RS3
+   * - Change group id of DS1 and DS2 to 3 : they should reconnect to RS1
    * @throws Exception If a problem occurred
    */
   @Test (groups = "slow")
@@ -540,9 +544,62 @@
       checkConnection(30, DS2_ID, RS3_ID,
         "Restart RS2 and RS3, DS2 should reconnect to RS3 (with GID=3, his GID)");
 
-    // TODO: when dynamic change of configuration for group id is done. One could
-    // add here change of DS1 and DS2 GID to 1 and check they both come back
-    // to rs1.
+      //
+      // ENTERING CHANGE CONFIG TEST PART
+      //
+
+      /**
+       * Change group id of DS1 and DS2 to 1 and see them reconnect to RS1
+       */
+      SortedSet<String> replServers = createRSListForTestCase(testCase);
+      DN baseDn = DN.decode(TEST_ROOT_DN_STRING);
+      DomainFakeCfg domainConfWithNewGid =  new DomainFakeCfg(baseDn, DS1_ID, replServers, 1);
+      rd1.applyConfigurationChange(domainConfWithNewGid);
+      domainConfWithNewGid = new DomainFakeCfg(baseDn, DS2_ID, replServers, 1);
+      rd2.applyConfigurationChange(domainConfWithNewGid);
+      checkConnection(30, DS1_ID, RS1_ID,
+        "Change GID of DS1 to 1, it should reconnect to RS1 with GID=1");
+      checkConnection(30, DS2_ID, RS1_ID,
+        "Change GID of DS2 to 1, it should reconnect to RS1 with GID=1");
+
+      /**
+       * Change group id of RS3 to 1
+       */
+      SortedSet<String> otherReplServers = new TreeSet<String>();
+      otherReplServers.add("localhost:" + rs1Port);
+      otherReplServers.add("localhost:" + rs2Port);
+      String dir = "groupIdHandshakeTest" + RS3_ID + testCase + "Db";
+      ReplServerFakeConfiguration rsConfWithNewGid =
+        new ReplServerFakeConfiguration(rs3Port, dir, 0, RS3_ID, 0, 100,
+        otherReplServers, 1, 1000, 5000);
+      rs3.applyConfigurationChange(rsConfWithNewGid);
+
+      /**
+       * Change group id of RS1 to 3: DS1 and DS2 should reconnect to RS3
+       */
+      otherReplServers = new TreeSet<String>();
+      otherReplServers.add("localhost:" + rs2Port);
+      otherReplServers.add("localhost:" + rs3Port);
+      dir = "groupIdHandshakeTest" + RS1_ID + testCase + "Db";
+      rsConfWithNewGid = new ReplServerFakeConfiguration(rs1Port, dir, 0, RS1_ID,
+        0, 100, otherReplServers, 3, 1000, 5000);
+      rs1.applyConfigurationChange(rsConfWithNewGid);
+      checkConnection(30, DS1_ID, RS3_ID,
+        "Change GID of RS3 to 1 and RS1 to 3, DS1 should reconnect to RS3 with GID=1");
+      checkConnection(30, DS2_ID, RS3_ID,
+        "Change GID of RS3 to 1 and RS1 to 3, DS2 should reconnect to RS3 with GID=1");
+      
+      /**
+       * Change group id of DS1 and DS2 to 3 : they should reconnect to RS1
+       */
+      domainConfWithNewGid = new DomainFakeCfg(baseDn, DS1_ID, replServers, 3);
+      rd1.applyConfigurationChange(domainConfWithNewGid);      
+      domainConfWithNewGid = new DomainFakeCfg(baseDn, DS2_ID, replServers, 3);
+      rd2.applyConfigurationChange(domainConfWithNewGid);
+      checkConnection(30, DS1_ID, RS1_ID,
+        "Change GID of DS1 to 3, it should reconnect to RS1 with GID=3");
+      checkConnection(30, DS2_ID, RS1_ID,
+        "Change GID of DS2 to 3, it should reconnect to RS1 with GID=3");
 
     } finally
     {

--
Gitblit v1.10.0