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=ac9f8da34ee6365d5bdc66dcb67a512cf449dfae;hb=24a5bafd22b83c4d838b7c3fc5225934fe969561;hp=815047423426e559b9099150f6c85d31aafe53ce;hpb=11dadddb4d9ba26ae0b1795921c7a218a6d893c2;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 8150474234..ac9f8da34e 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 @@ -13,17 +13,21 @@ 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) { @@ -61,19 +65,17 @@ public class RaftActorTestKit extends JavaTestKit { public static void waitUntilLeader(ActorRef actorRef) { FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS); for(int i = 0; i < 20 * 5; i++) { - Future future = Patterns.ask(actorRef, new FindLeader(), new Timeout(duration)); + Future future = Patterns.ask(actorRef, FindLeader.INSTANCE, new Timeout(duration)); try { - FindLeaderReply resp = (FindLeaderReply) Await.result(future, duration); - if(resp.getLeaderActor() != null) { + final Optional 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(); + LOG.error("FindLeader failed", e); } - Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS); }