From 307ca59f47c62824732c29352e9360e5056bce59 Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Mon, 23 Apr 2012 22:18:50 +0000
Subject: [PATCH] Fix OPENDJ-469.  This last commit resolves issues with the Nightly tests.

---
 opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java           |   28 +++++----
 opends/tests/unit-tests-testng/src/server/org/opends/server/replication/InitOnLineTest.java |  118 ++++++++++++++++++--------------------
 2 files changed, 72 insertions(+), 74 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java b/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
index cb56540..3df579b 100644
--- a/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
+++ b/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
@@ -2618,7 +2618,7 @@
   public void replay(LDAPUpdateMsg msg)
   {
     Operation op = null;
-    boolean done = false;
+    boolean replayDone = false;
     boolean dependency = false;
     ChangeNumber changeNumber = null;
     int retryCount = 10;
@@ -2633,7 +2633,7 @@
         op = msg.createOperation(conn);
         dependency = remotePendingChanges.checkDependencies(op, msg);
 
-        while ((!dependency) && (!done) && (retryCount-- > 0))
+        while ((!dependency) && (!replayDone) && (retryCount-- > 0))
         {
           // Try replay the operation
           op.setInternalOperation(true);
@@ -2656,7 +2656,7 @@
               // was a no-op. For example, an add which has already been
               // replayed, or a modify DN operation on an entry which has been
               // renamed by a more recent modify DN.
-              done = true;
+              replayDone = true;
             }
             else if (op instanceof ModifyOperation)
             {
@@ -2664,14 +2664,14 @@
               dependency = remotePendingChanges
                   .checkDependencies(newOp);
               ModifyMsg modifyMsg = (ModifyMsg) msg;
-              done = solveNamingConflict(newOp, modifyMsg);
+              replayDone = solveNamingConflict(newOp, modifyMsg);
             }
             else if (op instanceof DeleteOperation)
             {
               DeleteOperation newOp = (DeleteOperation) op;
               dependency = remotePendingChanges
                   .checkDependencies(newOp);
-              done = solveNamingConflict(newOp, msg);
+              replayDone = solveNamingConflict(newOp, msg);
             }
             else if (op instanceof AddOperation)
             {
@@ -2679,19 +2679,19 @@
               AddMsg addMsg = (AddMsg) msg;
               dependency = remotePendingChanges
                   .checkDependencies(newOp);
-              done = solveNamingConflict(newOp, addMsg);
+              replayDone = solveNamingConflict(newOp, addMsg);
             }
             else if (op instanceof ModifyDNOperationBasis)
             {
               ModifyDNOperationBasis newOp = (ModifyDNOperationBasis) op;
-              done = solveNamingConflict(newOp, msg);
+              replayDone = solveNamingConflict(newOp, msg);
             }
             else
             {
-              done = true; // unknown type of operation ?!
+              replayDone = true; // unknown type of operation ?!
             }
 
-            if (done)
+            if (replayDone)
             {
               // the update became a dummy update and the result
               // of the conflict resolution phase is to do nothing.
@@ -2711,11 +2711,11 @@
           }
           else
           {
-            done = true;
+            replayDone = true;
           }
         }
 
-        if (!done && !dependency)
+        if (!replayDone && !dependency)
         {
           // Continue with the next change but the servers could now become
           // inconsistent.
@@ -2781,7 +2781,7 @@
       msg = remotePendingChanges.getNextUpdate();
 
       // Prepare restart of loop
-      done = false;
+      replayDone = false;
       dependency = false;
       changeNumber = null;
       retryCount = 10;
@@ -4178,6 +4178,8 @@
         importConfig.setIncludeBranches(includeBranches);
         importConfig.setAppendToExistingData(false);
         importConfig.setSkipDNValidation(true);
+        // We should not validate schema for replication
+        importConfig.setValidateSchema(false);
         // Allow fractional replication ldif import plugin to be called
         importConfig.setInvokeImportPlugins(true);
         // Reset the follow import flag and message before starting the import
@@ -4590,6 +4592,8 @@
                 "ds-cfg-enabled: " + (!getBackend().isPrivateBackend()));
             LDIFImportConfig ldifImportConfig = new LDIFImportConfig(
                 new StringReader(ldif));
+            // No need to validate schema in replication
+            ldifImportConfig.setValidateSchema(false);
             LDIFReader reader = new LDIFReader(ldifImportConfig);
             Entry eclEntry = reader.readEntry();
             DirectoryServer.getConfigHandler().addEntry(eclEntry, null);
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/InitOnLineTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/InitOnLineTest.java
index 6299768..6f548f5 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/InitOnLineTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/InitOnLineTest.java
@@ -23,7 +23,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2011 ForgeRock AS
+ *      Portions Copyright 2011-2012 ForgeRock AS
  */
 package org.opends.server.replication;
 
@@ -68,8 +68,6 @@
 import org.opends.server.replication.protocol.DoneMsg;
 import org.opends.server.replication.protocol.EntryMsg;
 import org.opends.server.replication.protocol.ErrorMsg;
-import org.opends.server.replication.protocol.AddMsg;
-import org.opends.server.replication.protocol.HeartbeatThread;
 import org.opends.server.replication.protocol.InitializeRequestMsg;
 import org.opends.server.replication.protocol.InitializeTargetMsg;
 import org.opends.server.replication.protocol.ReplicationMsg;
@@ -175,6 +173,7 @@
    *           If the environment could not be set up.
    */
   @BeforeClass
+  @Override
   public void setUp() throws Exception
   {
     super.setUp();
@@ -358,7 +357,7 @@
           DirectoryStringSyntax.DECODER,
           logMessages);
       if (taskState != TaskState.COMPLETED_SUCCESSFULLY &&
-          logMessages.size() == 0)
+          logMessages.isEmpty())
       {
         fail("No log messages were written to the task entry on a failed task");
       }
@@ -458,39 +457,36 @@
     String[] entries = new String[entriesCnt + 2];
     String filler = "000000000000000000000000000000000000";
 
-    entries[0] = new String(
-        "dn: " + EXAMPLE_DN + "\n"
-        + "objectClass: top\n"
-        + "objectClass: domain\n"
-        + "dc: example\n"
-        + "entryUUID: 21111111-1111-1111-1111-111111111111\n"
-        + "\n");
-    entries[1] = new String(
-          "dn: ou=People," + EXAMPLE_DN + "\n"
-        + "objectClass: top\n"
-        + "objectClass: organizationalUnit\n"
-        + "ou: People\n"
-        + "entryUUID: 21111111-1111-1111-1111-111111111112\n"
-        + "\n");
+    entries[0] = "dn: " + EXAMPLE_DN + "\n"
+                 + "objectClass: top\n"
+                 + "objectClass: domain\n"
+                 + "dc: example\n"
+                 + "entryUUID: 21111111-1111-1111-1111-111111111111\n"
+                 + "\n";
+    entries[1] = "dn: ou=People," + EXAMPLE_DN + "\n"
+               + "objectClass: top\n"
+               + "objectClass: organizationalUnit\n"
+               + "ou: People\n"
+               + "entryUUID: 21111111-1111-1111-1111-111111111112\n"
+               + "\n";
 
     for (int i=0; i<entriesCnt; i++)
     {
       String useri="0000"+i;
-      entries[i+2] = new String(
-          "dn: cn="+useri+",ou=people," + EXAMPLE_DN + "\n"
-        + "objectclass: top\n"
-        + "objectclass: person\n"
-        + "objectclass: organizationalPerson\n"
-        + "objectclass: inetOrgPerson\n"
-        + "cn: "+useri+"_cn"+"\n"
-        + "sn: "+useri+"_sn"+"\n"
-        + "uid: "+useri+"_uid"+"\n"
-        + "telephonenumber:: "+ Base64.encode(
-            new String(bigAttributeValue).getBytes())+"\n"
-        + "entryUUID: 21111111-1111-1111-1111-"+useri+
-        filler.substring(0, 12-useri.length())+"\n"
-        + "\n");
-    };
+      entries[i+2] = "dn: cn="+useri+",ou=people," + EXAMPLE_DN + "\n"
+                   + "objectclass: top\n"
+                   + "objectclass: person\n"
+                   + "objectclass: organizationalPerson\n"
+                   + "objectclass: inetOrgPerson\n"
+                   + "cn: "+useri+"_cn"+"\n"
+                   + "sn: "+useri+"_sn"+"\n"
+                   + "uid: "+useri+"_uid"+"\n"
+                   + "telephonenumber:: "+ Base64.encode(
+                       new String(bigAttributeValue).getBytes())+"\n"
+                   + "entryUUID: 21111111-1111-1111-1111-"+useri+
+                   filler.substring(0, 12-useri.length())+"\n"
+                   + "\n";
+    }
 
     return entries;
   }
@@ -510,20 +506,19 @@
 
     String useri="0000"+entryCnt;
 
-    return  new String(
-        "dn: cn="+useri+",ou=people," + EXAMPLE_DN + "\n"
-        + "objectclass: top\n"
-        + "objectclass: person\n"
-        + "objectclass: organizationalPerson\n"
-        + "objectclass: inetOrgPerson\n"
-        + "cn: "+useri+"_cn"+"\n"
-        + "sn: "+useri+"_sn"+"\n"
-        + "uid: "+useri+"_uid"+"\n"
-        + "telephonenumber:: "+ Base64.encode(
-            new String(bigAttributeValue).getBytes())+"\n"
-            + "entryUUID: 21111111-1111-1111-1111-"+useri+
-            filler.substring(0, 12-useri.length())+"\n"
-            + "\n");
+    return  "dn: cn="+useri+",ou=people," + EXAMPLE_DN + "\n"
+            + "objectclass: top\n"
+            + "objectclass: person\n"
+            + "objectclass: organizationalPerson\n"
+            + "objectclass: inetOrgPerson\n"
+            + "cn: "+useri+"_cn"+"\n"
+            + "sn: "+useri+"_sn"+"\n"
+            + "uid: "+useri+"_uid"+"\n"
+            + "telephonenumber:: "+ Base64.encode(
+                new String(bigAttributeValue).getBytes())+"\n"
+                + "entryUUID: 21111111-1111-1111-1111-"+useri+
+                filler.substring(0, 12-useri.length())+"\n"
+                + "\n";
 
   }
 
@@ -629,7 +624,7 @@
         ") == Expected entries("+updatedEntries.length+")");
 
     broker.setGenerationID(EMPTY_DN_GENID);
-    broker.reStart(true);    
+    broker.reStart(true);
     try { Thread.sleep(500); } catch(Exception e) {}
 
   }
@@ -665,8 +660,7 @@
    */
   private ReplicationServer createChangelogServer(int changelogId, String testCase)
   {
-    SortedSet<String> servers = null;
-    servers = new TreeSet<String>();
+    SortedSet<String> servers = new TreeSet<String>();
     try
     {
       if (changelogId != changelog1ID)
@@ -772,13 +766,13 @@
 
   /**
    * Tests the import side of the Initialize task
-   * Test steps : 
+   * Test steps :
    * - create a task 'InitFromS2' in S1
    * - make S2 export its entries
    * - test that S1 has succesfully imported the entries and completed the task.
-   * 
-   * TODO: Error case: make S2 crash/disconnect in the middle of the export 
-   * and test that, on S1 side, the task ends with an error. 
+   *
+   * TODO: Error case: make S2 crash/disconnect in the middle of the export
+   * and test that, on S1 side, the task ends with an error.
    * State of the backend on S1 partially initialized: ?
    */
   @Test(enabled=true, groups="slow")
@@ -837,7 +831,7 @@
 
   /**
    * Tests the export side of the Initialize task
-   * Test steps : 
+   * Test steps :
    * - add entries in S1, make S2 publish InitRequest
    * - test that S1 has succesfully exported the entries (by receiving them
    *   on S2 side).
@@ -884,7 +878,7 @@
 
   /**
    * Tests the import side of the InitializeTarget task
-   * Test steps : 
+   * Test steps :
    * - add entries in S1 and create a task 'InitTargetS2' in S1
    * - wait task completed
    * - test that S2 has succesfully received the entries
@@ -935,11 +929,11 @@
 
   /**
    * Tests the import side of the InitializeTarget task
-   * Test steps : 
+   * Test steps :
    * - addEntries in S1, create a task 'InitAll' in S1
    * - wait task completed on S1
    * - test that S2 and S3 have succesfully imported the entries.
-   * 
+   *
    * TODO: Error case: make S1 crash in the middle of the export and test that
    * the task ends with an error. State of the backend on both S2 and S3: ?
    *
@@ -1036,7 +1030,7 @@
 
       if (readGenerationId != EXPECTED_GENERATION_ID)
       {
-        fail(testCase + " Import success waited longer than expected \n" + 
+        fail(testCase + " Import success waited longer than expected \n" +
             TestCaseUtils.threadStacksToString());
       }
 
@@ -1164,7 +1158,7 @@
           "ds-task-initialize-domain-dn: " + baseDn,
           "ds-task-initialize-replica-server-id: -3");
       addTask(taskInit, ResultCode.OTHER,
-          ERR_INVALID_IMPORT_SOURCE.get(baseDn.toNormalizedString(), 
+          ERR_INVALID_IMPORT_SOURCE.get(baseDn.toNormalizedString(),
               Integer.toString(server1ID),"-3",""));
 
       // Scope containing a serverID absent from the domain
@@ -1341,7 +1335,7 @@
     }
     catch(Exception e)
     {
-      log(testCase + e.getLocalizedMessage());      
+      log(testCase + e.getLocalizedMessage());
     }
     finally
     {
@@ -1472,7 +1466,7 @@
         "ds-task-initialize-replica-server-id: " + server1ID);
 
       addTask(taskInit, ResultCode.OTHER, ERR_INVALID_IMPORT_SOURCE.get(
-          baseDn.toNormalizedString(), 
+          baseDn.toNormalizedString(),
           Integer.toString(server1ID),"20",""));
 
       if (replDomain != null)

--
Gitblit v1.10.0