Reset snapshot progress after timeout has been hit
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / RaftActorTestKit.java
index ac9f8da34ee6365d5bdc66dcb67a512cf449dfae..6386d6c6ba1e7a9453161c3f67caa146e1dcd543 100644 (file)
@@ -10,12 +10,12 @@ package org.opendaylight.controller.cluster.raft;
 import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
 import akka.pattern.Patterns;
-import akka.testkit.JavaTestKit;
+import akka.testkit.javadsl.EventFilter;
+import akka.testkit.javadsl.TestKit;
 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;
@@ -23,56 +23,42 @@ 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 {
+public class RaftActorTestKit extends TestKit {
     private static final Logger LOG = LoggerFactory.getLogger(RaftActorTestKit.class);
     private final ActorRef raftActor;
 
-    public RaftActorTestKit(ActorSystem actorSystem, String actorName) {
+    public RaftActorTestKit(final ActorSystem actorSystem, final String actorName) {
         super(actorSystem);
-
         raftActor = this.getSystem().actorOf(MockRaftActor.builder().id(actorName).props(), actorName);
-
     }
 
-
     public ActorRef getRaftActor() {
         return raftActor;
     }
 
-    public boolean waitForLogMessage(final Class<?> logEventClass, String message){
+    public boolean waitForLogMessage(final Class<?> logEventClass, final String message) {
         // Wait for a specific log message to show up
-        return
-            new JavaTestKit.EventFilter<Boolean>(logEventClass
-            ) {
-                @Override
-                protected Boolean run() {
-                    return true;
-                }
-            }.from(raftActor.path().toString())
-                .message(message)
-                .occurrences(1).exec();
-
-
+        return new EventFilter(logEventClass, getSystem()).from(raftActor.path().toString()).message(message)
+                .occurrences(1).intercept(() -> Boolean.TRUE);
     }
 
-    protected void waitUntilLeader(){
+    protected void waitUntilLeader() {
         waitUntilLeader(raftActor);
     }
 
-    public static void waitUntilLeader(ActorRef actorRef) {
-        FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
-        for(int i = 0; i < 20 * 5; i++) {
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    public static void waitUntilLeader(final ActorRef actorRef) {
+        FiniteDuration duration = FiniteDuration.create(100, TimeUnit.MILLISECONDS);
+        for (int i = 0; i < 20 * 5; i++) {
             Future<Object> future = Patterns.ask(actorRef, FindLeader.INSTANCE, new Timeout(duration));
             try {
                 final Optional<String> maybeLeader = ((FindLeaderReply)Await.result(future, duration)).getLeaderActor();
                 if (maybeLeader.isPresent()) {
                     return;
                 }
-            } catch(TimeoutException e) {
-            } catch(Exception e) {
+            } catch (Exception e) {
                 LOG.error("FindLeader failed", e);
             }
 
@@ -81,5 +67,4 @@ public class RaftActorTestKit extends JavaTestKit {
 
         Assert.fail("Leader not found for actorRef " + actorRef.path());
     }
-
-}
\ No newline at end of file
+}