From d54f458902ba8de3503f8cd24e1f30821e151a56 Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Fri, 02 Oct 2009 06:47:04 +0000
Subject: [PATCH] Fix for 4265 : Unit test AssuredReplicationServerTest#testSafeDataLevelOne suffers randoms failures

---
 opendj-sdk/opends/src/server/org/opends/server/replication/server/MessageHandler.java                                       |   13 ++++++++++---
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/AssuredReplicationServerTest.java |   14 ++++++--------
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/server/MessageHandler.java b/opendj-sdk/opends/src/server/org/opends/server/replication/server/MessageHandler.java
index 1ad9574..b53ba96 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/server/MessageHandler.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/server/MessageHandler.java
@@ -403,9 +403,11 @@
             iterator.releaseCursor();
           }
           /*
-           * Check if the first change in the lateQueue is also on the regular
-           * queue
+           * If the late queue is empty then we could not find any
+           * messages in the replication log so the remote serevr is not
+           * late anymore.
            */
+
           if (lateQueue.isEmpty())
           {
             synchronized (msgQueue)
@@ -418,6 +420,11 @@
             }
           } else
           {
+            /*
+             * if the first change in the lateQueue is also on the regular
+             * queue, we can resume the processing from the regular queue
+             * -> set following to true and empty the lateQueue.
+             */
             msg = lateQueue.first();
             synchronized (msgQueue)
             {
@@ -432,7 +439,7 @@
                   msg1 = msgQueue.removeFirst();
                 } while (!msg.getChangeNumber().equals(msg1.getChangeNumber()));
                 this.updateServerState(msg);
-                return msg;
+                return msg1;
               }
             }
           }
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/AssuredReplicationServerTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/AssuredReplicationServerTest.java
index db3179d..7c7252b 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/AssuredReplicationServerTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/AssuredReplicationServerTest.java
@@ -29,6 +29,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.math.BigInteger;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
@@ -616,7 +617,6 @@
 
     private int scenario = -1;
     private long generationId = -1;
-    private ProtocolSession session = null;
 
     private ChangeNumberGenerator gen = null;
 
@@ -625,8 +625,6 @@
     // Number of received updates
     private int nReceivedUpdates = 0;
 
-    private boolean sameGidAsRs = true;
-
     private int nWrongReceivedUpdates = 0;
 
     /**
@@ -694,7 +692,6 @@
       ProtocolSession session)
     {
       super.sessionInitiated(initStatus, replicationServerState, generationId, session);
-      this.session = session;
     }
 
     @Override
@@ -1273,7 +1270,9 @@
    * All possible combinations tested thanks to the provider
    */
   @Test(dataProvider = "testSafeDataLevelOneProvider", groups = "slow", enabled = true)
-  public void testSafeDataLevelOne(int mainDsGid, boolean otherFakeDS, boolean fakeRS, int otherFakeDsGid, int fakeRsGid) throws Exception
+  public void testSafeDataLevelOne(
+      int mainDsGid, boolean otherFakeDS, boolean fakeRS,
+      int otherFakeDsGid, int fakeRsGid) throws Exception
   {
     String testCase = "testSafeDataLevelOne";
 
@@ -1314,7 +1313,7 @@
         // Timeout scenario used so that no reply is made if however the real RS
         // by mistake sends an assured error and expects an ack from this DS:
         // this would timeout. If main DS group id is not the same as the real RS one,
-        // the update will even not come to real RS as asured
+        // the update will even not come to real RS as assured
         fakeRd2 = createFakeReplicationDomain(FDS2_ID, otherFakeDsGid, RS1_ID,
           DEFAULT_GENID, false, AssuredMode.SAFE_DATA_MODE, 1, LONG_TIMEOUT,
           TIMEOUT_DS_SCENARIO);
@@ -1332,7 +1331,7 @@
         // Timeout scenario used so that no reply is made if however the real RS
         // by mistake sends an assured error and expects an ack from this fake RS:
         // this would timeout. If main DS group id is not the same as the real RS one,
-        // the update will even not come to real RS as asured
+        // the update will even not come to real RS as assured
         fakeRs1 = createFakeReplicationServer(FRS1_ID, fakeRsGid, RS1_ID,
           DEFAULT_GENID, false, AssuredMode.SAFE_DATA_MODE, 1, new ServerState(), TIMEOUT_RS_SCENARIO);
         assertNotNull(fakeRs1);
@@ -1373,7 +1372,6 @@
       }
 
       // Sanity check
-      sleep(500); // Let time to update to reach other servers
       assertEquals(fakeRd1.getReceivedUpdates(), 0);
       assertTrue(fakeRd1.receivedUpdatesOk());
       if (otherFakeDS)

--
Gitblit v1.10.0