X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FRaftActorTestKit.java;h=6386d6c6ba1e7a9453161c3f67caa146e1dcd543;hb=d9a03a6870a6e980ef6c5afce9237265932cdb19;hp=d2a0dc8802b0e45f39923c5f2cd603f59a9faa81;hpb=e1eca73a5ae2ffae8dd78c6fe5281cd2f45d5ef3;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTestKit.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTestKit.java index d2a0dc8802..6386d6c6ba 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTestKit.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTestKit.java @@ -10,7 +10,8 @@ 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; @@ -22,39 +23,25 @@ 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(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() { @@ -62,8 +49,8 @@ public class RaftActorTestKit extends JavaTestKit { } @SuppressWarnings("checkstyle:IllegalCatch") - public static void waitUntilLeader(ActorRef actorRef) { - FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS); + public static void waitUntilLeader(final ActorRef actorRef) { + FiniteDuration duration = FiniteDuration.create(100, TimeUnit.MILLISECONDS); for (int i = 0; i < 20 * 5; i++) { Future future = Patterns.ask(actorRef, FindLeader.INSTANCE, new Timeout(duration)); try { @@ -80,5 +67,4 @@ public class RaftActorTestKit extends JavaTestKit { Assert.fail("Leader not found for actorRef " + actorRef.path()); } - }