Merge "Migrate JMX plugin's use of BindingGeneratorUtil"
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / utils / MessageCollectorActor.java
index 448c28e8c8e9f090dacdbab184b7760f85c66893..62f163fb7d0270a2415e934d193136d610e01ca3 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.controller.cluster.raft.utils;
 
 import akka.actor.ActorRef;
+import akka.actor.Props;
 import akka.actor.UntypedActor;
 import akka.pattern.Patterns;
 import akka.util.Timeout;
@@ -75,14 +76,21 @@ public class MessageCollectorActor extends UntypedActor {
         return null;
     }
 
-    public static <T> T expectFirstMatching(ActorRef actor, Class<T> clazz) throws Exception {
-        for(int i = 0; i < 50; i++) {
-            T message = getFirstMatching(actor, clazz);
-            if(message != null) {
-                return message;
-            }
+    public static <T> T expectFirstMatching(ActorRef actor, Class<T> clazz) {
+        return expectFirstMatching(actor, clazz, 5000);
+    }
+
+    public static <T> T expectFirstMatching(ActorRef actor, Class<T> clazz, long timeout) {
+        int count = (int) (timeout / 50);
+        for(int i = 0; i < count; i++) {
+            try {
+                T message = getFirstMatching(actor, clazz);
+                if(message != null) {
+                    return message;
+                }
+            } catch (Exception e) {}
 
-            Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
+            Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
         }
 
         Assert.fail("Did not receive message of type " + clazz);
@@ -116,4 +124,8 @@ public class MessageCollectorActor extends UntypedActor {
 
         throw new TimeoutException("Actor not ready in time.");
     }
+
+    public static Props props() {
+        return Props.create(MessageCollectorActor.class);
+    }
 }