Bug 4105: Choose Owner for an Entity based on first come first served basis
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / entityownership / EntityOwnershipShardTest.java
index d4c59cc39657ff020d20b6485b36280194758a4c..a6bf30c01ea3f9dfeee1cbf1b8570ce801684682 100644 (file)
@@ -15,6 +15,7 @@ import akka.actor.Props;
 import akka.actor.UntypedActor;
 import akka.dispatch.Dispatchers;
 import akka.testkit.TestActorRef;
+import com.google.common.base.Function;
 import com.google.common.base.Stopwatch;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.util.concurrent.Uninterruptibles;
@@ -95,6 +96,8 @@ public class EntityOwnershipShardTest extends AbstractEntityOwnershipTest {
         kit.expectMsgClass(SuccessReply.class);
 
         verifyCommittedEntityCandidate(shard, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
+
+        verifyOwner(shard, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
     }
 
     @Test
@@ -122,6 +125,8 @@ public class EntityOwnershipShardTest extends AbstractEntityOwnershipTest {
         peer.underlyingActor().grantVote = true;
 
         verifyCommittedEntityCandidate(shard, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
+
+        verifyOwner(shard, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
     }
 
     @Test
@@ -160,7 +165,10 @@ public class EntityOwnershipShardTest extends AbstractEntityOwnershipTest {
         // Resume AppendEntries - the follower should ack the commit which should then result in the candidate
         // write being applied to the state.
         follower.dropAppendEntries = false;
+
         verifyCommittedEntityCandidate(shard, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
+
+        verifyOwner(shard, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
     }
 
     @Test
@@ -197,6 +205,8 @@ public class EntityOwnershipShardTest extends AbstractEntityOwnershipTest {
         // Resume AppendEntries - the candidate write should now be committed.
         follower.dropAppendEntries = false;
         verifyCommittedEntityCandidate(shard, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
+
+        verifyOwner(shard, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
     }
 
     @Test
@@ -304,6 +314,20 @@ public class EntityOwnershipShardTest extends AbstractEntityOwnershipTest {
         return null;
     }
 
+    private void verifyOwner(final TestActorRef<EntityOwnershipShard> shard, String entityType, YangInstanceIdentifier entityId,
+            String localMemberName) {
+        verifyOwner(localMemberName, entityType, entityId, new Function<YangInstanceIdentifier, NormalizedNode<?,?>>() {
+            @Override
+            public NormalizedNode<?, ?> apply(YangInstanceIdentifier path) {
+                try {
+                    return AbstractShardTest.readStore(shard, path);
+                } catch(Exception e) {
+                    return null;
+                }
+            }
+        });
+    }
+
     private Props newShardProps() {
         return newShardProps(Collections.<String,String>emptyMap());
     }