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

Jean-Noel Rouvignac
21.33.2015 3a2c384ad1231ad92674545100e6c3e6d6d5a715
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;
  }