Search in sources :

Example 1 with OnDemandShardState

use of org.opendaylight.controller.cluster.datastore.messages.OnDemandShardState in project controller by opendaylight.

the class IntegrationTestKit method verifyShardState.

public static void verifyShardState(final AbstractDataStore datastore, final String shardName, final Consumer<OnDemandShardState> 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) {
        OnDemandShardState shardState = (OnDemandShardState) actorContext.executeOperation(shardActor, GetOnDemandRaftState.INSTANCE);
        try {
            verifier.accept(shardState);
            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) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) OnDemandShardState(org.opendaylight.controller.cluster.datastore.messages.OnDemandShardState)

Example 2 with OnDemandShardState

use of org.opendaylight.controller.cluster.datastore.messages.OnDemandShardState in project controller by opendaylight.

the class OnDemandShardStateCache method retrieveState.

private OnDemandShardState retrieveState() throws Exception {
    stateRetrievalTime = null;
    Timeout timeout = new Timeout(10, TimeUnit.SECONDS);
    Stopwatch timer = Stopwatch.createStarted();
    OnDemandShardState state = (OnDemandShardState) Await.result(Patterns.ask(shardActor, GetOnDemandRaftState.INSTANCE, timeout), timeout.duration());
    stateRetrievalTime = timer.stop().toString();
    return state;
}
Also used : Timeout(akka.util.Timeout) Stopwatch(com.google.common.base.Stopwatch) OnDemandShardState(org.opendaylight.controller.cluster.datastore.messages.OnDemandShardState)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)2 OnDemandShardState (org.opendaylight.controller.cluster.datastore.messages.OnDemandShardState)2 ActorRef (akka.actor.ActorRef)1 Timeout (akka.util.Timeout)1 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)1