From 9c99e9cd7d4467d04da5321ee411b5c83b451f4a Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 19 Dec 2013 09:21:31 +0000
Subject: [PATCH] Fixing test failure in Continuous Integration.

---
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java        |    2 
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java |  182 +++++++++++++++++++--------------------------
 2 files changed, 78 insertions(+), 106 deletions(-)

diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java
index a12522e..87b3581 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java
@@ -488,29 +488,20 @@
         StartSessionMsg startSessionMsg = (StartSessionMsg)msg;
 
         // Sanity checking for assured parameters
-        boolean receivedIsAssured = startSessionMsg.isAssured();
-        assertEquals(receivedIsAssured, isAssured);
+        assertEquals(startSessionMsg.isAssured(), isAssured);
         if (isAssured)
         {
-          AssuredMode receivedAssuredMode = startSessionMsg.getAssuredMode();
-          assertEquals(receivedAssuredMode, assuredMode);
-          byte receivedSafeDataLevel = startSessionMsg.getSafeDataLevel();
-          assertEquals(receivedSafeDataLevel, safeDataLevel);
+          assertEquals(startSessionMsg.getAssuredMode(), assuredMode);
+          assertEquals(startSessionMsg.getSafeDataLevel(), safeDataLevel);
         }
-        ServerStatus receivedServerStatus = startSessionMsg.getStatus();
-        assertEquals(receivedServerStatus, ServerStatus.NORMAL_STATUS);
-        List<String> receivedReferralsURLs = startSessionMsg.getReferralsURLs();
-        assertEquals(receivedReferralsURLs.size(), 0);
+        assertEquals(startSessionMsg.getStatus(), ServerStatus.NORMAL_STATUS);
+        Assertions.assertThat(startSessionMsg.getReferralsURLs()).isEmpty();
 
         debugInfo("Received start session assured parameters are ok.");
 
         // Send topo view
-        List<RSInfo> rsList = new ArrayList<RSInfo>();
         RSInfo rsInfo = new RSInfo(serverId, "localhost:" + port, generationId, groupId, 1);
-        rsList.add(rsInfo);
-        TopologyMsg topologyMsg = new TopologyMsg(new ArrayList<DSInfo>(),
-          rsList);
-        session.publish(topologyMsg);
+        session.publish(new TopologyMsg(new ArrayList<DSInfo>(), Arrays.asList(rsInfo)));
       }
       return true;
     }
@@ -521,7 +512,6 @@
      */
     public boolean isHandshakeOk()
     {
-
       return handshakeOk;
     }
 
@@ -531,7 +521,6 @@
      */
     public boolean isScenarioExecuted()
     {
-
       return scenarioExecuted;
     }
 
@@ -619,8 +608,7 @@
      */
     private void executeNotAssuredScenario() throws Exception
     {
-      UpdateMsg updateMsg = (UpdateMsg) session.receive();
-      checkUpdateAssuredParameters(updateMsg);
+      checkAssuredParametersOnReceivedUpdateMsg();
 
       scenarioExecuted = true;
     }
@@ -631,8 +619,7 @@
      */
     private void executeTimeoutScenario() throws Exception
     {
-      UpdateMsg updateMsg = (UpdateMsg) session.receive();
-      checkUpdateAssuredParameters(updateMsg);
+      checkAssuredParametersOnReceivedUpdateMsg();
 
       scenarioExecuted = true;
 
@@ -645,8 +632,7 @@
      */
     private void executeNoTimeoutScenario() throws Exception
     {
-      UpdateMsg updateMsg = (UpdateMsg) session.receive();
-      checkUpdateAssuredParameters(updateMsg);
+      UpdateMsg updateMsg = checkAssuredParametersOnReceivedUpdateMsg();
 
       // Sleep before sending back the ack
       sleep(NO_TIMEOUT_RS_SLEEP_TIME);
@@ -659,10 +645,13 @@
     }
 
     /**
-     * Check that received update assured parameters are as defined at RS start
+     * Receives an {@link UpdateMsg} and checks that received update assured
+     * parameters are as defined at RS start
      */
-    private void checkUpdateAssuredParameters(UpdateMsg updateMsg)
+    private UpdateMsg checkAssuredParametersOnReceivedUpdateMsg() throws Exception
     {
+      final UpdateMsg updateMsg = (UpdateMsg) session.receive();
+
       assertEquals(updateMsg.isAssured(), isAssured,
           "msg=" + ((updateMsg instanceof AddMsg)?
               ((AddMsg)updateMsg).getDN():updateMsg.getCSN()));
@@ -672,6 +661,8 @@
         assertEquals(updateMsg.getSafeDataLevel(), safeDataLevel);
       }
       debugInfo("Received update assured parameters are ok.");
+
+      return updateMsg;
     }
 
     /**
@@ -679,50 +670,37 @@
      */
     private void executeSafeReadManyErrorsScenario() throws Exception
     {
-      {
-        // Read first update
-        UpdateMsg updateMsg = (UpdateMsg) session.receive();
-        checkUpdateAssuredParameters(updateMsg);
+      // Read first update
+      UpdateMsg updateMsg = checkAssuredParametersOnReceivedUpdateMsg();
 
-        // Sleep before sending back the ack
-        sleep(NO_TIMEOUT_RS_SLEEP_TIME);
+      // Sleep before sending back the ack
+      sleep(NO_TIMEOUT_RS_SLEEP_TIME);
 
-        // Send an ack with errors:
-        // - replay error
-        // - server 10 error, server 20 error
-        List<Integer> serversInError = new ArrayList<Integer>();
-        serversInError.add(10);
-        serversInError.add(20);
-        AckMsg ackMsg = new AckMsg(updateMsg.getCSN(), false, false, true, serversInError);
-        session.publish(ackMsg);
+      // Send an ack with errors:
+      // - replay error
+      // - server 10 error, server 20 error
+      List<Integer> serversInError = Arrays.asList(10, 20);
+      session.publish(new AckMsg(updateMsg.getCSN(), false, false, true, serversInError));
 
-        // Read second update
-        updateMsg = (UpdateMsg) session.receive();
-        checkUpdateAssuredParameters(updateMsg);
+      // Read second update
+      updateMsg = checkAssuredParametersOnReceivedUpdateMsg();
 
-        // Sleep before sending back the ack
-        sleep(NO_TIMEOUT_RS_SLEEP_TIME);
+      // Sleep before sending back the ack
+      sleep(NO_TIMEOUT_RS_SLEEP_TIME);
 
-        // Send an ack with errors:
-        // - timeout error
-        // - wrong status error
-        // - replay error
-        // - server 10 error, server 20 error, server 30 error
-        serversInError = new ArrayList<Integer>();
-        serversInError.add(10);
-        serversInError.add(20);
-        serversInError.add(30);
-        ackMsg = new AckMsg(updateMsg.getCSN(), true, true, true, serversInError);
-        session.publish(ackMsg);
+      // Send an ack with errors:
+      // - timeout error
+      // - wrong status error
+      // - replay error
+      // - server 10 error, server 20 error, server 30 error
+      serversInError = Arrays.asList(10, 20, 30);
+      session.publish(new AckMsg(updateMsg.getCSN(), true, true, true, serversInError));
 
-        // Read third update
-        updateMsg = (UpdateMsg) session.receive();
-        checkUpdateAssuredParameters(updateMsg);
+      // Read third update
+      updateMsg = checkAssuredParametersOnReceivedUpdateMsg();
 
-        // let timeout occur
-
-        scenarioExecuted = true;
-      }
+      // let timeout occur
+      scenarioExecuted = true;
     }
 
     /**
@@ -730,46 +708,37 @@
      */
     private void executeSafeDataManyErrorsScenario() throws Exception
     {
-      {
-        // Read first update
-        UpdateMsg updateMsg = (UpdateMsg) session.receive();
-        checkUpdateAssuredParameters(updateMsg);
+      // Read first update
+      UpdateMsg updateMsg = checkAssuredParametersOnReceivedUpdateMsg();
 
-        // Sleep before sending back the ack
-        sleep(NO_TIMEOUT_RS_SLEEP_TIME);
+      // Sleep before sending back the ack
+      sleep(NO_TIMEOUT_RS_SLEEP_TIME);
 
-        // Send an ack with errors:
-        // - timeout error
-        // - server 10 error
-        List<Integer> serversInError = new ArrayList<Integer>();
-        serversInError.add(10);
-        AckMsg ackMsg = new AckMsg(updateMsg.getCSN(), true, false, false, serversInError);
-        session.publish(ackMsg);
+      // Send an ack with errors:
+      // - timeout error
+      // - server 10 error
+      List<Integer> serversInError = Arrays.asList(10);
+      session.publish(new AckMsg(updateMsg.getCSN(), true, false, false, serversInError));
 
-        // Read second update
-        updateMsg = (UpdateMsg) session.receive();
-        checkUpdateAssuredParameters(updateMsg);
+      // Read second update
+      updateMsg = checkAssuredParametersOnReceivedUpdateMsg();
 
-        // Sleep before sending back the ack
-        sleep(NO_TIMEOUT_RS_SLEEP_TIME);
+      // Sleep before sending back the ack
+      sleep(NO_TIMEOUT_RS_SLEEP_TIME);
 
-        // Send an ack with errors:
-        // - timeout error
-        // - server 10 error, server 20 error
-        serversInError = new ArrayList<Integer>();
-        serversInError.add(10);
-        serversInError.add(20);
-        ackMsg = new AckMsg(updateMsg.getCSN(), true, false, false, serversInError);
-        session.publish(ackMsg);
+      // Send an ack with errors:
+      // - timeout error
+      // - server 10 error, server 20 error
+      serversInError = Arrays.asList(10, 20);
+      session.publish(new AckMsg(updateMsg.getCSN(), true, false, false, serversInError));
 
-        // Read third update
-        updateMsg = (UpdateMsg) session.receive();
-        checkUpdateAssuredParameters(updateMsg);
+      // Read third update
+      updateMsg = checkAssuredParametersOnReceivedUpdateMsg();
 
-        // let timeout occur
-        scenarioExecuted = true;
-      }
+      // let timeout occur
+      scenarioExecuted = true;
     }
+
   }
 
   /**
@@ -802,13 +771,13 @@
       // safe data level 2
       replicationServer = new FakeReplicationServer(rsGroupId, replServerPort, RS_SERVER_ID,
         1, testcase);
-      if (rsGroupId != (byte)1)
+      if (rsGroupId != 1)
         replicationServer.setAssured(false);
       replicationServer.start(TIMEOUT_SCENARIO);
 
       long startTime;
       // Create a safe data assured domain
-      if (rsGroupId == (byte)1)
+      if (rsGroupId == 1)
       {
         safeDataDomainCfgEntry = createAssuredDomain(AssuredMode.SAFE_DATA_MODE, 1, TIMEOUT);
         // Wait for connection of domain to RS
@@ -838,7 +807,7 @@
 
       waitForScenarioExecutedOnRs(testcase, replicationServer);
 
-      if (rsGroupId == (byte)1)
+      if (rsGroupId == 1)
       {
         // RS has same group id as DS
         assertBlockedLongerThanTimeout(startTime, endTime, TIMEOUT);
@@ -852,7 +821,8 @@
           .assertValue("assured-sd-timeout-updates", 1)
           .assertRemainingValuesAreZero();
         assertServerErrorsSafeDataMode(baseDN, entry(RS_SERVER_ID, 1));
-      } else
+      }
+      else
       {
         // RS has a different group id, addEntry should have returned quickly
         assertTrue((endTime - startTime) < 3000);
@@ -910,14 +880,14 @@
       // Create and start a RS expecting clients in safe read assured mode
       replicationServer = new FakeReplicationServer(rsGroupId, replServerPort, RS_SERVER_ID,
         true, testcase);
-      if (rsGroupId != (byte)1)
+      if (rsGroupId != 1)
         replicationServer.setAssured(false);
       replicationServer.start(TIMEOUT_SCENARIO);
 
       long startTime;
 
       // Create a safe data assured domain
-      if (rsGroupId == (byte)1)
+      if (rsGroupId == 1)
       {
         // Create a safe read assured domain
         safeReadDomainCfgEntry = createAssuredDomain(AssuredMode.SAFE_READ_MODE, 0, TIMEOUT);
@@ -948,7 +918,7 @@
 
       waitForScenarioExecutedOnRs(testcase, replicationServer);
 
-      if (rsGroupId == (byte)1)
+      if (rsGroupId == 1)
       {
         assertBlockedLongerThanTimeout(startTime, endTime, TIMEOUT);
         assertTrue(replicationServer.isScenarioExecuted());
@@ -962,7 +932,8 @@
           .assertValue("assured-sr-timeout-updates", 1)
           .assertRemainingValuesAreZero();
         assertServerErrorsSafeReadMode(baseDN, entry(RS_SERVER_ID, 1));
-      } else
+      }
+      else
       {
         // RS has a different group id, addEntry should have returned quickly
         assertTrue((endTime - startTime) < 3000);
@@ -1186,7 +1157,7 @@
       try {
         AckMsg ackMsg = replicationServer.sendAssuredAddMsg(entry, parentUid);
 
-         if (rsGroupId == (byte)2)
+        if (rsGroupId == 2)
            fail("Should only go here for RS with same group id as DS");
 
         // Ack received, replay has occurred
@@ -1205,10 +1176,11 @@
           .assertValue("assured-sr-received-updates-acked", 1)
           .assertRemainingValuesAreZero();
         assertNoServerErrors(baseDN);
-      } catch (SocketTimeoutException e)
+      }
+      catch (SocketTimeoutException e)
       {
         // Expected
-        if (rsGroupId == (byte)1)
+        if (rsGroupId == 1)
            fail("Should only go here for RS with group id different from DS one");
 
         return;
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java
index 1fd9ceb..cb9f76f 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java
@@ -936,7 +936,7 @@
       // answers correctly to a WindowProbeMsg Message.
       session.publish(new WindowProbeMsg());
 
-      WindowMsg windowMsg = (WindowMsg) session.receive();
+      WindowMsg windowMsg = waitForSpecificMsg(session, WindowMsg.class);
       assertEquals(serverwindow, windowMsg.getNumAck());
 
       // check that this did not change the window by sending a probe again.

--
Gitblit v1.10.0