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

Jean-Noel Rouvignac
21.33.2015 3a2c384ad1231ad92674545100e6c3e6d6d5a715
AssuredReplicationPluginTest.java:
Used ReplicationTestCase.waitForSpecificMsg() and waitForSpecificMsgs() to ignore unrelated messages.

ReplicationTestCase.java:
Added methods:
- waitForSpecificMsgs(Session session, Class<?>... msgTypes)
- waitForSpecificMsgs(ReplicationBroker broker, Class<?>... msgTypes)
Changed
<T extends ReplicationMsg> T waitForSpecificMsg(Session session, ReplicationBroker broker, Class<T> msgType)
to
ReplicationMsg waitForSpecificMsgs(Session session, ReplicationBroker broker, Class<?>... msgTypes)
2 files modified
35 ■■■■■ changed files
opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java 25 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java 10 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java
@@ -833,7 +833,7 @@
   * @return The expected message if it comes in time or fails (assertion).
   */
  protected static <T extends ReplicationMsg> T waitForSpecificMsg(Session session, Class<T> msgType) {
    return waitForSpecificMsg(session, null, msgType);
    return (T) waitForSpecificMsgs(session, (ReplicationBroker) null, msgType);
  }
  /**
@@ -844,14 +844,24 @@
   * @return The expected message if it comes in time or fails (assertion).
   */
  protected static <T extends ReplicationMsg> T waitForSpecificMsg(ReplicationBroker broker, Class<T> msgType) {
    return waitForSpecificMsg(null, broker, msgType);
    return (T) waitForSpecificMsgs(null, broker, msgType);
  }
  protected static <T extends ReplicationMsg> T waitForSpecificMsg(Session session, ReplicationBroker broker, Class<T> msgType)
  protected static ReplicationMsg waitForSpecificMsgs(Session session, Class<?>... msgTypes) {
    return waitForSpecificMsgs(session, null, msgTypes);
  }
  protected static ReplicationMsg waitForSpecificMsgs(ReplicationBroker broker, Class<?>... msgTypes) {
    return waitForSpecificMsgs(null, broker, msgTypes);
  }
  private static ReplicationMsg waitForSpecificMsgs(Session session, ReplicationBroker broker, Class<?>... msgTypes)
  {
    assertTrue(session != null || broker != null, "One of Session or ReplicationBroker parameter must not be null");
    assertTrue(session == null || broker == null, "Only one of Session or ReplicationBroker parameter must not be null");
    List<Class<?>> msgTypes2 = Arrays.asList(msgTypes);
    final int timeOut = 5000; // 5 seconds max to wait for the desired message
    final long startTime = System.currentTimeMillis();
    final List<ReplicationMsg> msgs = new ArrayList<>();
@@ -872,21 +882,22 @@
      }
      catch (Exception ex)
      {
        fail("Exception waiting for " + msgType + " message : "
        ex.printStackTrace();
        fail("Exception waiting for " + msgTypes2 + " message : "
            + ex.getClass().getName() + " : " + ex.getMessage());
      }
      if (replMsg.getClass().equals(msgType))
      if (msgTypes2.contains(replMsg.getClass()))
      {
        // Ok, got it, let's return the expected message
        return (T) replMsg;
        return replMsg;
      }
      logger.trace("waitForSpecificMsg received : " + replMsg);
      msgs.add(replMsg);
      timedOut = System.currentTimeMillis() - startTime > timeOut;
    }
    // Timeout
    fail("Failed to receive an expected " + msgType + " message after 5 seconds."
    fail("Failed to receive an expected " + msgTypes2 + " message after 5 seconds."
        + " Also received the following messages during wait time: " + msgs);
    return null;
  }
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java
@@ -38,6 +38,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.AddOperation;
@@ -45,12 +46,10 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.SearchRequest;
import static org.opends.server.protocols.internal.Requests.*;
import org.opends.server.replication.ReplicationTestCase;
import org.opends.server.replication.common.*;
import org.opends.server.replication.protocol.*;
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.util.StaticUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
@@ -58,6 +57,7 @@
import static org.assertj.core.data.MapEntry.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.testng.Assert.*;
/**
@@ -443,7 +443,7 @@
    {
      {
        // Receive server start
        ServerStartMsg serverStartMsg = (ServerStartMsg) session.receive();
        ServerStartMsg serverStartMsg = waitForSpecificMsg(session, ServerStartMsg.class);
        baseDN = serverStartMsg.getBaseDN();
        serverState = serverStartMsg.getServerState();
@@ -464,7 +464,7 @@
        }
        // Read start session or stop
        ReplicationMsg msg = session.receive();
        ReplicationMsg msg = waitForSpecificMsgs(session, StopMsg.class, ServerStartMsg.class);
        if (msg instanceof StopMsg){
          // Disconnection of DS looking for best server
          return false;
@@ -584,7 +584,7 @@
        session.publish(addMsg);
        // Read and return matching ack
        return (AckMsg)session.receive();
        return waitForSpecificMsg(session, AckMsg.class);
      }
    }