mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

gbellato
02.47.2009 eb152f66224f9d6324640059a4d1114f7efa7fe1
Fix for 4265 : Unit test AssuredReplicationServerTest#testSafeDataLevelOne suffers randoms failures

The failures are caused by a real but very rare and minor bug.
When a Directory Server connects to a Replication Server at the same time a change is generated by
another server and this change is the first to be sent to the directory server it can be sent
with the wrong assured status.
This cause no harm in a real deployment but was causing test failure in our case.

This is fixed by using the message from the message queue rather than from the replication log
2 files modified
27 ■■■■■ changed files
opends/src/server/org/opends/server/replication/server/MessageHandler.java 13 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/AssuredReplicationServerTest.java 14 ●●●●● patch | view | raw | blame | history
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;
              }
            }
          }
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)