Bug 3195: Cleanup on error paths and error handling
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / IntegrationTestKit.java
index 94f20856ff43754dae02986b554259c9e637c212..53e43f817d2f996b358c5756ac3fca1147bb2604 100644 (file)
@@ -72,14 +72,7 @@ class IntegrationTestKit extends ShardTestKit {
 
     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);
 
@@ -87,6 +80,27 @@ class IntegrationTestKit extends ShardTestKit {
         }
     }
 
+    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 {