+
+ @SuppressWarnings("checkstyle:IllegalCatch")
+ static void verifyRaftState(final ActorRef raftActor, final Consumer<OnDemandRaftState> verifier) {
+ Timeout timeout = new Timeout(500, TimeUnit.MILLISECONDS);
+ AssertionError lastError = null;
+ Stopwatch sw = Stopwatch.createStarted();
+ while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
+ try {
+ OnDemandRaftState raftState = (OnDemandRaftState)Await.result(ask(raftActor,
+ GetOnDemandRaftState.INSTANCE, timeout), timeout.duration());
+ verifier.accept(raftState);
+ return;
+ } catch (AssertionError e) {
+ lastError = e;
+ Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
+ lastError = new AssertionError("OnDemandRaftState failed", e);
+ Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
+ }
+ }
+
+ throw lastError;
+ }