import akka.actor.ActorSystem;
import akka.actor.PoisonPill;
import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.Uninterruptibles;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
void waitUntilLeader(ActorContext actorContext, String... shardNames) {
for(String shardName: shardNames) {
- ActorRef shard = null;
- for(int i = 0; i < 20 * 5 && shard == null; i++) {
- Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
- Optional<ActorRef> shardReply = actorContext.findLocalShard(shardName);
- if(shardReply.isPresent()) {
- shard = shardReply.get();
- }
- }
+ ActorRef shard = findLocalShard(actorContext, shardName);
assertNotNull("Shard was not created", shard);
}
}
+ void waitUntilNoLeader(ActorContext actorContext, String... shardNames) {
+ for(String shardName: shardNames) {
+ ActorRef shard = findLocalShard(actorContext, shardName);
+ assertNotNull("No local shard found", shard);
+
+ waitUntilNoLeader(shard);
+ }
+ }
+
+ private ActorRef findLocalShard(ActorContext actorContext, String shardName) {
+ ActorRef shard = null;
+ for(int i = 0; i < 20 * 5 && shard == null; i++) {
+ Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
+ Optional<ActorRef> shardReply = actorContext.findLocalShard(shardName);
+ if(shardReply.isPresent()) {
+ shard = shardReply.get();
+ }
+ }
+ return shard;
+ }
+
void testWriteTransaction(DistributedDataStore dataStore, YangInstanceIdentifier nodePath,
NormalizedNode<?, ?> nodeToWrite) throws Exception {
cohort.commit().get(5, TimeUnit.SECONDS);
}
+ void doCommit(final ListenableFuture<Boolean> canCommitFuture, final DOMStoreThreePhaseCommitCohort cohort) throws Exception {
+ Boolean canCommit = canCommitFuture.get(7, TimeUnit.SECONDS);
+ assertEquals("canCommit", true, canCommit);
+ cohort.preCommit().get(5, TimeUnit.SECONDS);
+ cohort.commit().get(5, TimeUnit.SECONDS);
+ }
+
void cleanup(DistributedDataStore dataStore) {
if(dataStore != null) {
dataStore.getActorContext().getShardManager().tell(PoisonPill.getInstance(), null);