From af76a3750288d90c006022829887c92601a4737c Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 24 Jun 2013 11:56:44 +0000
Subject: [PATCH] OPENDJ-885 - Replication replay may lose changes if it can't acquire a writeLock

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java |   96 +++++++++---------------------------------------
 1 files changed, 18 insertions(+), 78 deletions(-)

diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java
index 13f15e1..fefecc1 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java
@@ -70,26 +70,28 @@
 import java.util.concurrent.locks.Lock;
 
 import static org.opends.server.config.ConfigConstants.*;
-import static org.opends.server.loggers.ErrorLogger.logError;
-import static org.opends.server.loggers.debug.DebugLogger.getTracer;
-import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
+import static org.opends.server.loggers.ErrorLogger.*;
+import static org.opends.server.loggers.debug.DebugLogger.*;
+import static org.opends.server.util.StaticUtils.*;
 import static org.testng.Assert.*;
 
 /**
  * An abstract class that all Replication unit test should extend.
  */
+@SuppressWarnings("javadoc")
 @Test(groups = { "precommit", "replication" }, sequential = true)
 public abstract class ReplicationTestCase extends DirectoryServerTestCase
 {
 
-  // The tracer object for the debug logger
+  /** The tracer object for the debug logger */
   private static final DebugTracer TRACER = getTracer();
 
-  // This is the generation id matching the memory test backend
-  // with its initial root entry o=test created.
-  // This matches the backend obtained calling:
-  // TestCaseUtils.initializeTestBackend(true).
-  // (using the default TestCaseUtils.TEST_ROOT_DN_STRING suffix)
+  /**
+   * This is the generation id matching the memory test backend with its initial
+   * root entry o=test created. This matches the backend obtained calling:
+   * TestCaseUtils.initializeTestBackend(true). (using the default
+   * TestCaseUtils.TEST_ROOT_DN_STRING suffix)
+   */
   protected static final long TEST_DN_WITH_ROOT_ENTRY_GENID = 5055L;
 
   /**
@@ -249,33 +251,6 @@
   }
 
   /**
-   * Open an ECL replicationServer session to the local ReplicationServer
-  protected ReplicationBroker openECLReplicationSession(
-        int window_size, int port, int timeout, boolean emptyOldChanges,
-        Short serverId)
-  throws Exception, SocketException
-  {
-    ServerState state = new ServerState();
-
-    //if (emptyOldChanges)
-    //   new PersistentServerState(baseDn, serverId, new ServerState());
-
-    ReplicationBroker broker = new ReplicationBroker(null,
-        state, "cn=changelog", serverId, window_size,
-        -1, 100000, getReplSessionSecurity(), (byte)1);
-    ArrayList<String> servers = new ArrayList<String>(1);
-    servers.add("localhost:" + port);
-    broker.start(servers);
-    if (timeout != 0)
-      broker.setSoTimeout(timeout);
-    checkConnection(30, broker, port); // give some time to the broker to connect
-                                       // to the replicationServer.
-    return broker;
-  }
-  */
-
-
-  /**
    * Check connection of the provided ds to the
    * replication server. Waits for connection to be ok up to secTimeout seconds
    * before failing.
@@ -437,7 +412,6 @@
     logError(Message.raw(Category.SYNC, Severity.NOTICE,
     "ReplicationTestCase/Cleaning entries"));
 
-    DeleteOperationBasis op;
     // Delete entries
     try
     {
@@ -564,7 +538,7 @@
 
       // Check that no entries have been found
       LinkedList<SearchResultEntry> entries = op.getSearchEntries();
-      assertTrue(entries != null);
+      assertNotNull(entries);
       StringBuilder sb = new StringBuilder();
       for (SearchResultEntry entry : entries)
       {
@@ -650,17 +624,7 @@
 
     do
     {
-      Entry newEntry;
-      Lock lock = null;
-      for (int j=0; j < 3; j++)
-      {
-        lock = LockManager.lockRead(dn);
-        if (lock != null)
-        {
-          break;
-        }
-      }
-
+      final Lock lock = LockManager.lockRead(dn);
       if (lock == null)
       {
         throw new Exception("could not lock entry " + dn);
@@ -668,9 +632,7 @@
 
       try
       {
-        newEntry = DirectoryServer.getEntry(dn);
-
-
+        final Entry newEntry = DirectoryServer.getEntry(dn);
         if (newEntry != null)
         {
           List<Attribute> tmpAttrList = newEntry.getAttribute(attrTypeStr);
@@ -683,7 +645,6 @@
             found = tmpAttr.contains(AttributeValues.create(attrType, valueString));
           }
         }
-
       }
       finally
       {
@@ -715,16 +676,7 @@
       count--;
     }
 
-    Lock lock = null;
-    for (int i=0; i < 3; i++)
-    {
-      lock = LockManager.lockRead(dn);
-      if (lock != null)
-      {
-        break;
-      }
-    }
-
+    final Lock lock = LockManager.lockRead(dn);
     if (lock == null)
     {
       throw new Exception("could not lock entry " + dn);
@@ -773,7 +725,7 @@
       lastCount = currentCount;
     } catch (Exception ex) {
       ex.printStackTrace();
-      assertTrue(false);
+      fail();
     }
     return delta;
   }
@@ -848,10 +800,7 @@
       }
     } while (completionTime == null);
 
-    if (completionTime == null)
-    {
-      fail("The task has not completed after 30 seconds.");
-    }
+    assertNotNull(completionTime, "The task has not completed after 30 seconds.");
 
     // Check that the task state is as expected.
     AttributeType taskStateType =
@@ -1091,16 +1040,7 @@
     {
       Thread.sleep(100);
 
-      Lock lock = null;
-      for (int i=0; i < 3; i++)
-      {
-        lock = LockManager.lockRead(dn);
-        if (lock != null)
-        {
-          break;
-        }
-      }
-
+      final Lock lock = LockManager.lockRead(dn);
       if (lock == null)
       {
         throw new Exception("could not lock entry " + dn);

--
Gitblit v1.10.0