From 06931155aa9709d40784f98bd5e68a5fd854e0d5 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 6 Apr 2018 13:46:27 +0200 Subject: [PATCH] Migrate RaftActorTestKit to javadsl.TestKit JavaTestKit is deprecated, migrate RaftActorTestKit to the new equivalent. Change-Id: Id7f051aaac0154795c4242bb0ffc275dad06aaa4 Signed-off-by: Robert Varga --- .../cluster/raft/RaftActorTestKit.java | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) 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..0b4e2cb78e 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; @@ -25,36 +26,23 @@ 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,7 +50,7 @@ public class RaftActorTestKit extends JavaTestKit { } @SuppressWarnings("checkstyle:IllegalCatch") - public static void waitUntilLeader(ActorRef actorRef) { + public static void waitUntilLeader(final ActorRef actorRef) { FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS); for (int i = 0; i < 20 * 5; i++) { Future future = Patterns.ask(actorRef, FindLeader.INSTANCE, new Timeout(duration)); @@ -80,5 +68,4 @@ public class RaftActorTestKit extends JavaTestKit { Assert.fail("Leader not found for actorRef " + actorRef.path()); } - } -- 2.36.6