From 3a2c384ad1231ad92674545100e6c3e6d6d5a715 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 21 Aug 2015 14:33:17 +0000
Subject: [PATCH] AssuredReplicationPluginTest.java: Used ReplicationTestCase.waitForSpecificMsg() and waitForSpecificMsgs() to ignore unrelated messages.

---
 opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java
index c95e530..7a56c7d 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java
+++ b/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;
   }

--
Gitblit v1.10.0