Search in sources :

Example 6 with FindLeaderReply

use of org.opendaylight.controller.cluster.raft.client.messages.FindLeaderReply in project controller by opendaylight.

the class ShardTestKit method waitUntilLeader.

@SuppressWarnings("checkstyle:IllegalCatch")
public static String waitUntilLeader(final ActorRef shard) {
    FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
    for (int i = 0; i < 20 * 5; i++) {
        Future<Object> future = Patterns.ask(shard, FindLeader.INSTANCE, new Timeout(duration));
        try {
            final Optional<String> maybeLeader = ((FindLeaderReply) Await.result(future, duration)).getLeaderActor();
            if (maybeLeader.isPresent()) {
                return maybeLeader.get();
            }
        } catch (TimeoutException e) {
            LOG.trace("FindLeader timed out", e);
        } catch (Exception e) {
            LOG.error("FindLeader failed", e);
        }
        Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
    }
    Assert.fail("Leader not found for shard " + shard.path());
    return null;
}
Also used : FindLeaderReply(org.opendaylight.controller.cluster.raft.client.messages.FindLeaderReply) Timeout(akka.util.Timeout) FiniteDuration(scala.concurrent.duration.FiniteDuration) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

FindLeaderReply (org.opendaylight.controller.cluster.raft.client.messages.FindLeaderReply)6 Timeout (akka.util.Timeout)3 FiniteDuration (scala.concurrent.duration.FiniteDuration)3 ActorRef (akka.actor.ActorRef)2 Creator (akka.japi.Creator)2 TestActorRef (akka.testkit.TestActorRef)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TimeoutException (java.util.concurrent.TimeoutException)2 Test (org.junit.Test)2 RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)2 ElectionTimeout (org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 RegisterChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener)1 RegisterDataTreeChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener)1 MockDataChangeListener (org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener)1 MockDataTreeChangeListener (org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener)1 ApplyState (org.opendaylight.controller.cluster.raft.base.messages.ApplyState)1 InitiateCaptureSnapshot (org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot)1 LeaderTransitioning (org.opendaylight.controller.cluster.raft.base.messages.LeaderTransitioning)1 SwitchBehavior (org.opendaylight.controller.cluster.raft.base.messages.SwitchBehavior)1