From 210d5f1b76962b2722db7b4d74c3372c22bcd0ca Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 03 Jan 2014 14:34:26 +0000
Subject: [PATCH] Fixed test failure for JEChangeNumberIndexDBTest.testClear(). Problem was due to the CNIndexDB state not being properly cleaned up. I chose to rely on ReplicationTestCase.remove(ReplicationServer) to clean up the state of the ChangeNumberIndexDB.

---
 opends/src/server/org/opends/server/replication/server/changelog/je/JEChangeNumberIndexDB.java |   60 +++++++++++++++++-------------------------------------------
 1 files changed, 17 insertions(+), 43 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/server/changelog/je/JEChangeNumberIndexDB.java b/opends/src/server/org/opends/server/replication/server/changelog/je/JEChangeNumberIndexDB.java
index 8ae8161..5f1b63e 100644
--- a/opends/src/server/org/opends/server/replication/server/changelog/je/JEChangeNumberIndexDB.java
+++ b/opends/src/server/org/opends/server/replication/server/changelog/je/JEChangeNumberIndexDB.java
@@ -93,7 +93,6 @@
   private final AtomicLong lastGeneratedChangeNumber;
   private DbMonitorProvider dbMonitor = new DbMonitorProvider();
   private final AtomicBoolean shutdown = new AtomicBoolean(false);
-  private volatile boolean trimDone = false;
   /**
    * A dedicated thread loops trim().
    * <p>
@@ -252,15 +251,15 @@
       notifyAll();
     }
 
-    synchronized (this)
-    { /* Can we just do a thread.join() ? */
-      while (!trimDone)
+    if (trimmingThread != null)
+    {
+      try
       {
-        try
-        {
-          wait();
-        } catch (InterruptedException e)
-        { /* do nothing */ }
+        trimmingThread.join();
+      }
+      catch (InterruptedException ignored)
+      {
+        // Nothing can be done about it, just proceed
       }
     }
 
@@ -283,12 +282,16 @@
 
         synchronized (this)
         {
-          try
+          if (!shutdown.get())
           {
-            wait(1000);
-          } catch (InterruptedException e)
-          {
-            Thread.currentThread().interrupt();
+            try
+            {
+              wait(1000);
+            }
+            catch (InterruptedException e)
+            {
+              Thread.currentThread().interrupt();
+            }
           }
         }
       }
@@ -302,35 +305,6 @@
         }
         break;
       }
-      try {
-        trim(shutdown);
-
-        synchronized (this)
-        {
-          try
-          {
-            wait(1000);
-          } catch (InterruptedException e)
-          {
-            Thread.currentThread().interrupt();
-          }
-        }
-      } catch (Exception end)
-      {
-        logError(ERR_EXCEPTION_CHANGELOG_TRIM_FLUSH
-            .get(stackTraceToSingleLineString(end)));
-        if (replicationServer != null)
-        {
-          replicationServer.shutdown();
-        }
-        break;
-      }
-    }
-
-    synchronized (this)
-    {
-      trimDone = true;
-      notifyAll();
     }
   }
 

--
Gitblit v1.10.0