Remove MockReplicatedLogEntry
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / RaftActorTestKit.java
index 815047423426e559b9099150f6c85d31aafe53ce..d2a0dc8802b0e45f39923c5f2cd603f59a9faa81 100644 (file)
@@ -13,17 +13,20 @@ import akka.pattern.Patterns;
 import akka.testkit.JavaTestKit;
 import akka.util.Timeout;
 import com.google.common.util.concurrent.Uninterruptibles;
+import java.util.Optional;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
 import org.junit.Assert;
 import org.opendaylight.controller.cluster.raft.client.messages.FindLeader;
 import org.opendaylight.controller.cluster.raft.client.messages.FindLeaderReply;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import scala.concurrent.Await;
 import scala.concurrent.Future;
 import scala.concurrent.duration.Duration;
 import scala.concurrent.duration.FiniteDuration;
 
 public class RaftActorTestKit extends JavaTestKit {
+    private static final Logger LOG = LoggerFactory.getLogger(RaftActorTestKit.class);
     private final ActorRef raftActor;
 
     public RaftActorTestKit(ActorSystem actorSystem, String actorName) {
@@ -38,7 +41,7 @@ public class RaftActorTestKit extends JavaTestKit {
         return raftActor;
     }
 
-    public boolean waitForLogMessage(final Class<?> logEventClass, String message){
+    public boolean waitForLogMessage(final Class<?> logEventClass, String message) {
         // Wait for a specific log message to show up
         return
             new JavaTestKit.EventFilter<Boolean>(logEventClass
@@ -54,30 +57,28 @@ public class RaftActorTestKit extends JavaTestKit {
 
     }
 
-    protected void waitUntilLeader(){
+    protected void waitUntilLeader() {
         waitUntilLeader(raftActor);
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public static void waitUntilLeader(ActorRef actorRef) {
         FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
-        for(int i = 0; i < 20 * 5; i++) {
-            Future<Object> future = Patterns.ask(actorRef, new FindLeader(), new Timeout(duration));
+        for (int i = 0; i < 20 * 5; i++) {
+            Future<Object> future = Patterns.ask(actorRef, FindLeader.INSTANCE, new Timeout(duration));
             try {
-                FindLeaderReply resp = (FindLeaderReply) Await.result(future, duration);
-                if(resp.getLeaderActor() != null) {
+                final Optional<String> maybeLeader = ((FindLeaderReply)Await.result(future, duration)).getLeaderActor();
+                if (maybeLeader.isPresent()) {
                     return;
                 }
-            } catch(TimeoutException e) {
-            } catch(Exception e) {
-                System.err.println("FindLeader threw ex");
-                e.printStackTrace();
+            } catch (Exception e) {
+                LOG.error("FindLeader failed", e);
             }
 
-
             Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
         }
 
         Assert.fail("Leader not found for actorRef " + actorRef.path());
     }
 
-}
\ No newline at end of file
+}