X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fentityownership%2FEntityOwnerChangeListenerTest.java;h=cc228a4c71572037b7c0a863133ad841e773850c;hb=e86a9107fc3ae4451b5a7eb54a03f9ad6776fe72;hp=24913d2ea8d6939a5e112a42de1c074d54f647bb;hpb=a8f617e6dd21f9a453e9ece1e57f4549899584e7;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnerChangeListenerTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnerChangeListenerTest.java index 24913d2ea8..cc228a4c71 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnerChangeListenerTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnerChangeListenerTest.java @@ -25,9 +25,9 @@ import org.opendaylight.controller.md.sal.common.api.clustering.Entity; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; +import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; +; /** * Unit tests for EntityOwnerChangeListener. @@ -46,7 +46,8 @@ public class EntityOwnerChangeListenerTest { private static final Entity ENTITY1 = new Entity(ENTITY_TYPE, ENTITY_ID1); private static final Entity ENTITY2 = new Entity(ENTITY_TYPE, ENTITY_ID2); - private final ShardDataTree shardDataTree = new ShardDataTree(SchemaContextHelper.entityOwners()); + private final ShardDataTree shardDataTree = new ShardDataTree(SchemaContextHelper.entityOwners(), + TreeType.OPERATIONAL); private final EntityOwnershipListenerSupport mockListenerSupport = mock(EntityOwnershipListenerSupport.class); private EntityOwnerChangeListener listener; @@ -57,50 +58,81 @@ public class EntityOwnerChangeListenerTest { } @Test - public void testOnDataChanged() throws Exception { + public void testOnDataTreeChanged() throws Exception { writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID1, LOCAL_MEMBER_NAME)); writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID2, LOCAL_MEMBER_NAME)); - writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID1, REMOTE_MEMBER_NAME1)); + verify(mockListenerSupport, never()).notifyEntityOwnershipListeners(any(Entity.class), anyBoolean(), + anyBoolean(), anyBoolean()); - verify(mockListenerSupport, never()).notifyEntityOwnershipListeners(any(Entity.class), anyBoolean(), anyBoolean()); + // Write local member as owner for entity 1 writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, LOCAL_MEMBER_NAME)); + verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY1, false, true, true); + + // Add remote member 1 as candidate for entity 1 - listener support should not get notified + + reset(mockListenerSupport); + writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID1, REMOTE_MEMBER_NAME1)); + verify(mockListenerSupport, never()).notifyEntityOwnershipListeners(any(Entity.class), anyBoolean(), + anyBoolean(), anyBoolean()); - verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY1, false, true); + // Change owner to remote member 1 for entity 1 reset(mockListenerSupport); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, REMOTE_MEMBER_NAME1)); + verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY1, true, false, true); - verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY1, true, false); + // Change owner to remote member 2 for entity 1 reset(mockListenerSupport); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, REMOTE_MEMBER_NAME2)); + verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY1, false, false, true); - verify(mockListenerSupport, never()).notifyEntityOwnershipListeners(any(Entity.class), anyBoolean(), anyBoolean()); + // Clear the owner for entity 1 + + reset(mockListenerSupport); + writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, "")); + verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY1, false, false, false); + + // Change owner to the local member for entity 1 writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, LOCAL_MEMBER_NAME)); + verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY1, false, true, true); - verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY1, false, true); + // Change owner to remote member 2 for entity 2 reset(mockListenerSupport); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID2), entityEntryWithOwner(ENTITY_ID2, REMOTE_MEMBER_NAME1)); + verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY2, false, false, true); - verify(mockListenerSupport, never()).notifyEntityOwnershipListeners(any(Entity.class), anyBoolean(), anyBoolean()); + // Change owner to the local member for entity 2 reset(mockListenerSupport); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID2), entityEntryWithOwner(ENTITY_ID2, LOCAL_MEMBER_NAME)); + verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY2, false, true, true); + + // Write local member owner for entity 2 again - expect no change - verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY2, false, true); + reset(mockListenerSupport); + writeNode(entityPath(ENTITY_TYPE, ENTITY_ID2), entityEntryWithOwner(ENTITY_ID2, LOCAL_MEMBER_NAME)); + verify(mockListenerSupport, never()).notifyEntityOwnershipListeners(any(Entity.class), anyBoolean(), + anyBoolean(), anyBoolean()); + + // Clear the owner for entity 2 + + reset(mockListenerSupport); + writeNode(entityPath(ENTITY_TYPE, ENTITY_ID2), entityEntryWithOwner(ENTITY_ID2, null)); + verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY2, true, false, false); + + // Clear the owner for entity 2 again - expect no change + + reset(mockListenerSupport); + writeNode(entityPath(ENTITY_TYPE, ENTITY_ID2), entityEntryWithOwner(ENTITY_ID2, null)); + verify(mockListenerSupport, never()).notifyEntityOwnershipListeners(any(Entity.class), anyBoolean(), + anyBoolean(), anyBoolean()); } private void writeNode(YangInstanceIdentifier path, NormalizedNode node) throws DataValidationFailedException { - DataTreeModification modification = shardDataTree.getDataTree().takeSnapshot().newModification(); - modification.merge(path, node); - modification.ready(); - - shardDataTree.getDataTree().validate(modification); - DataTreeCandidateTip candidate = shardDataTree.getDataTree().prepare(modification); - shardDataTree.getDataTree().commit(candidate); - shardDataTree.notifyListeners(candidate); + AbstractEntityOwnershipTest.writeNode(path, node, shardDataTree); } }