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;
}
Aggregations