From 79c2bd96a15b5cb331f6e1a58ca8838b280c8a18 Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Tue, 16 Jan 2007 09:10:31 +0000
Subject: [PATCH] This change includes a set of new unit tests dedicated to the startup phase of the synchronization server (former changelog server) and the connection phase of client LDAP server to this synchronization server. These tests cover various cases of this connection checking that the adequate changes are then sent to the client.

---
 opendj-sdk/opends/src/server/org/opends/server/synchronization/plugin/PersistentServerState.java |  100 ++++++++++++++++++++++++++-----------------------
 1 files changed, 53 insertions(+), 47 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/synchronization/plugin/PersistentServerState.java b/opendj-sdk/opends/src/server/org/opends/server/synchronization/plugin/PersistentServerState.java
index f2c2d70..fd1f3d1 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/synchronization/plugin/PersistentServerState.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/synchronization/plugin/PersistentServerState.java
@@ -118,57 +118,18 @@
       return;
 
     savedStatus = true;
-
-    ArrayList<ASN1OctetString> values = this.toASN1ArrayList();
-
-    if (values.size() == 0)
-      return;
-
-    LDAPAttribute attr =
-      new LDAPAttribute(SYNCHRONIZATION_STATE, values);
-    LDAPModification mod = new LDAPModification(ModificationType.REPLACE, attr);
-    ArrayList<LDAPModification> mods = new ArrayList<LDAPModification>(1);
-    mods.add(mod);
-
-    boolean done = false;
-    while (!done)
+    ResultCode resultCode = updateStateEntry();
+    if (resultCode != ResultCode.SUCCESS)
     {
-      /*
-       * Generate a modify operation on the Server State Entry :
-       * cn=ffffffff-ffffffff-ffffffff-ffffffff, baseDn
-       */
-      ModifyOperation op =
-        new ModifyOperation(conn, InternalClientConnection.nextOperationID(),
-            InternalClientConnection.nextMessageID(),
-            new ArrayList<Control>(0), serverStateAsn1Dn,
-            mods);
-      op.setInternalOperation(true);
-      op.setSynchronizationOperation(true);
-
-      op.run();
-      ResultCode resultCode = op.getResultCode();
-      if (resultCode != ResultCode.SUCCESS)
+      if (resultCode == ResultCode.NO_SUCH_OBJECT)
       {
-        if (resultCode == ResultCode.NO_SUCH_OBJECT)
-        {
-          createStateEntry();
-        }
-        else
-        {
-          savedStatus = false;
-          int msgID = MSGID_ERROR_UPDATING_RUV;
-          String message = getMessage(msgID,
-              op.getResultCode().getResultCodeName(),
-              op.toString(), op.getErrorMessage(),
-              baseDn.toString());
-          logError(ErrorLogCategory.SYNCHRONIZATION,
-              ErrorLogSeverity.SEVERE_ERROR,
-              message, msgID);
-          break;
-        }
+        createStateEntry();
       }
       else
-        done = true;
+      {
+        savedStatus = false;
+
+      }
     }
   }
 
@@ -297,6 +258,51 @@
   }
 
   /**
+   * Save the current values of this PersistentState object
+   * in the appropiate entry of the database.
+   *
+   * @return a ResultCode indicating if the method was successfull.
+   */
+  private ResultCode updateStateEntry()
+  {
+    /*
+     * Generate a modify operation on the Server State Entry :
+     * cn=ffffffff-ffffffff-ffffffff-ffffffff, baseDn
+     */
+    ArrayList<ASN1OctetString> values = this.toASN1ArrayList();
+
+    if (values.size() == 0)
+      return ResultCode.SUCCESS;
+
+    LDAPAttribute attr =
+      new LDAPAttribute(SYNCHRONIZATION_STATE, values);
+    LDAPModification mod = new LDAPModification(ModificationType.REPLACE, attr);
+    ArrayList<LDAPModification> mods = new ArrayList<LDAPModification>(1);
+    mods.add(mod);
+
+    ModifyOperation op =
+      new ModifyOperation(conn, InternalClientConnection.nextOperationID(),
+          InternalClientConnection.nextMessageID(),
+          new ArrayList<Control>(0), serverStateAsn1Dn,
+          mods);
+    op.setInternalOperation(true);
+    op.setSynchronizationOperation(true);
+
+    op.run();
+
+    ResultCode result = op.getResultCode();
+    if (result != ResultCode.SUCCESS)
+    {
+      int msgID = MSGID_ERROR_UPDATING_RUV;
+      String message = getMessage(msgID, op.getResultCode().getResultCodeName(),
+          op.toString(), op.getErrorMessage(), baseDn.toString());
+      logError(ErrorLogCategory.SYNCHRONIZATION, ErrorLogSeverity.SEVERE_ERROR,
+          message, msgID);
+    }
+    return result;
+  }
+
+  /**
    * Get the Dn where the ServerState is stored.
    * @return Returns the serverStateDn.
    */

--
Gitblit v1.10.0