Search in sources :

Example 6 with OnDemandRaftState

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

the class MemberNode method verifyRaftState.

public static void verifyRaftState(final AbstractDataStore datastore, final String shardName, final RaftStateVerifier verifier) throws Exception {
    ActorContext actorContext = datastore.getActorContext();
    Future<ActorRef> future = actorContext.findLocalShardAsync(shardName);
    ActorRef shardActor = Await.result(future, Duration.create(10, TimeUnit.SECONDS));
    AssertionError lastError = null;
    Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
        OnDemandRaftState raftState = (OnDemandRaftState) actorContext.executeOperation(shardActor, GetOnDemandRaftState.INSTANCE);
        try {
            verifier.verify(raftState);
            return;
        } catch (AssertionError e) {
            lastError = e;
            Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        }
    }
    throw lastError;
}
Also used : ActorRef(akka.actor.ActorRef) Stopwatch(com.google.common.base.Stopwatch) OnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState) GetOnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext)

Aggregations

OnDemandRaftState (org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState)6 GetOnDemandRaftState (org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState)5 Stopwatch (com.google.common.base.Stopwatch)3 ActorRef (akka.actor.ActorRef)2 Timeout (akka.util.Timeout)2 InvalidActorNameException (akka.actor.InvalidActorNameException)1 DeleteSnapshotsFailure (akka.persistence.DeleteSnapshotsFailure)1 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Test (org.junit.Test)1 Dispatchers (org.opendaylight.controller.cluster.common.actor.Dispatchers)1 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)1 PeerAddressResolved (org.opendaylight.controller.cluster.datastore.messages.PeerAddressResolved)1 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)1 ChangeServersVotingStatus (org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus)1 FiniteDuration (scala.concurrent.duration.FiniteDuration)1