private final TipProducingDataTree dataTree;
private SchemaContext schemaContext;
- ShardDataTree(final SchemaContext schemaContext) {
+ public ShardDataTree(final SchemaContext schemaContext) {
dataTree = InMemoryDataTreeFactory.getInstance().create();
updateSchemaContext(schemaContext);
}
- TipProducingDataTree getDataTree() {
+ public TipProducingDataTree getDataTree() {
return dataTree;
}
return ensureTransactionChain(chainId).newReadWriteTransaction(txId);
}
- void notifyListeners(final DataTreeCandidate candidate) {
+ public void notifyListeners(final DataTreeCandidate candidate) {
LOG.debug("Notifying listeners on candidate {}", candidate);
// DataTreeChanges first, as they are more light-weight
return new SimpleEntry<>(reg, event);
}
- Entry<ListenerRegistration<DOMDataTreeChangeListener>, DataTreeCandidate> registerTreeChangeListener(final YangInstanceIdentifier path,
+ public Entry<ListenerRegistration<DOMDataTreeChangeListener>, DataTreeCandidate> registerTreeChangeListener(final YangInstanceIdentifier path,
final DOMDataTreeChangeListener listener) {
final ListenerRegistration<DOMDataTreeChangeListener> reg = treeChangePublisher.registerTreeChangeListener(path, listener);
--- /dev/null
+/*
+ * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.datastore.entityownership;
+
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_ID_QNAME;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_OWNERS_PATH;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_OWNER_NODE_ID;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_QNAME;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_TYPE_QNAME;
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import java.util.Collection;
+import java.util.Map.Entry;
+import org.opendaylight.controller.cluster.datastore.ShardDataTree;
+import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.EntityType;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A DataChangeListener that listeners for entity owner changes and notifies the EntityOwnershipListenerSupport
+ * appropriately.
+ *
+ * @author Thomas Pantelis
+ */
+class EntityOwnerChangeListener implements DOMDataTreeChangeListener {
+ private static final Logger LOG = LoggerFactory.getLogger(EntityOwnerChangeListener.class);
+
+ private final String localMemberName;
+ private final EntityOwnershipListenerSupport listenerSupport;
+
+ EntityOwnerChangeListener(String localMemberName, EntityOwnershipListenerSupport listenerSupport) {
+ this.localMemberName = localMemberName;
+ this.listenerSupport = listenerSupport;
+ }
+
+ void init(ShardDataTree shardDataTree) {
+ shardDataTree.registerTreeChangeListener(YangInstanceIdentifier.builder(ENTITY_OWNERS_PATH).
+ node(EntityType.QNAME).node(EntityType.QNAME).node(ENTITY_QNAME).node(ENTITY_QNAME).build(), this);
+ }
+
+ @Override
+ public void onDataTreeChanged(Collection<DataTreeCandidate> changes) {
+ for(DataTreeCandidate change: changes) {
+ MapEntryNode entityNode = (MapEntryNode) change.getRootNode().getDataAfter().get();
+
+ LOG.debug("Entity node updated: {}", change.getRootPath());
+
+ String newOwner = extractOwner(entityNode);
+
+ String origOwner = null;
+ Optional<NormalizedNode<?, ?>> dataBefore = change.getRootNode().getDataBefore();
+ if(dataBefore.isPresent()) {
+ MapEntryNode origEntityNode = (MapEntryNode) change.getRootNode().getDataBefore().get();
+ origOwner = extractOwner(origEntityNode);
+ }
+
+ LOG.debug("New owner: {}, Original owner: {}", newOwner, origOwner);
+
+ boolean isOwner = Objects.equal(localMemberName, newOwner);
+ boolean wasOwner = Objects.equal(localMemberName, origOwner);
+ if(isOwner || wasOwner) {
+ Entity entity = createEntity(change.getRootPath());
+
+ LOG.debug("Calling notifyEntityOwnershipListeners: entity: {}, wasOwner: {}, isOwner: {}",
+ entity, wasOwner, isOwner);
+
+ listenerSupport.notifyEntityOwnershipListeners(entity, wasOwner, isOwner);
+ }
+ }
+ }
+
+ private Entity createEntity(YangInstanceIdentifier entityPath) {
+ String entityType = null;
+ YangInstanceIdentifier entityId = null;
+ for(PathArgument pathArg: entityPath.getPathArguments()) {
+ if(pathArg instanceof NodeIdentifierWithPredicates) {
+ NodeIdentifierWithPredicates nodeKey = (NodeIdentifierWithPredicates) pathArg;
+ Entry<QName, Object> key = nodeKey.getKeyValues().entrySet().iterator().next();
+ if(ENTITY_TYPE_QNAME.equals(key.getKey())) {
+ entityType = key.getValue().toString();
+ } else if(ENTITY_ID_QNAME.equals(key.getKey())) {
+ entityId = (YangInstanceIdentifier) key.getValue();
+ }
+ }
+ }
+
+ return new Entity(entityType, entityId);
+ }
+
+ private String extractOwner(MapEntryNode entityNode) {
+ Optional<DataContainerChild<? extends PathArgument, ?>> ownerNode = entityNode.getChild(ENTITY_OWNER_NODE_ID);
+ return ownerNode.isPresent() ? (String) ownerNode.get().getValue() : null;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.datastore.entityownership;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.EntityOwners;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.EntityType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.entity.type.entity.Candidate;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
+
+/**
+ * Utility methods for entity-owners yang model.
+ *
+ * @author Thomas Pantelis
+ */
+final class EntityOwnersModel {
+ static final QName ENTITY_QNAME = org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.
+ md.sal.clustering.entity.owners.rev150804.entity.owners.entity.type.Entity.QNAME;
+ static final QName CANDIDATE_NAME_QNAME = QName.create(Candidate.QNAME, "name");
+ static final QName ENTITY_ID_QNAME = QName.create(ENTITY_QNAME, "id");
+ static final QName ENTITY_OWNER_QNAME = QName.create(ENTITY_QNAME, "owner");
+ static final QName ENTITY_TYPE_QNAME = QName.create(EntityType.QNAME, "type");
+
+ static final NodeIdentifier ENTITY_OWNERS_NODE_ID = new NodeIdentifier(EntityOwners.QNAME);
+ static final NodeIdentifier ENTITY_OWNER_NODE_ID = new NodeIdentifier(ENTITY_OWNER_QNAME);
+ static final YangInstanceIdentifier ENTITY_OWNERS_PATH = YangInstanceIdentifier.of(EntityOwners.QNAME);
+
+ static YangInstanceIdentifier entityPath(String entityType, YangInstanceIdentifier entityId) {
+ return YangInstanceIdentifier.builder(ENTITY_OWNERS_PATH).node(EntityType.QNAME).
+ nodeWithKey(EntityType.QNAME, ENTITY_TYPE_QNAME, entityType).node(ENTITY_QNAME).
+ nodeWithKey(ENTITY_QNAME, ENTITY_ID_QNAME, entityId).build();
+
+ }
+
+ static NormalizedNode<?, ?> entityOwnersWithCandidate(String entityType, YangInstanceIdentifier entityId,
+ String candidateName) {
+ return entityOwnersWithEntityTypeEntry(entityTypeEntryWithEntityEntry(entityType,
+ entityEntryWithCandidateEntry(entityId, candidateName)));
+ }
+
+ static ContainerNode entityOwnersWithEntityTypeEntry(MapEntryNode entityTypeNode) {
+ return ImmutableContainerNodeBuilder.create().withNodeIdentifier(
+ ENTITY_OWNERS_NODE_ID).addChild(ImmutableNodes.mapNodeBuilder(EntityType.QNAME).
+ addChild(entityTypeNode).build()).build();
+ }
+
+ static MapEntryNode entityTypeEntryWithEntityEntry(String entityType, MapEntryNode entityNode) {
+ return ImmutableNodes.mapEntryBuilder(EntityType.QNAME,
+ ENTITY_TYPE_QNAME, entityType).addChild(ImmutableNodes.mapNodeBuilder(
+ ENTITY_QNAME).addChild(entityNode).build()).build();
+ }
+
+ static MapEntryNode entityEntryWithCandidateEntry(YangInstanceIdentifier entityId, String candidateName) {
+ return ImmutableNodes.mapEntryBuilder(ENTITY_QNAME, ENTITY_ID_QNAME, entityId).addChild(
+ candidateEntry(candidateName)).build();
+ }
+
+ static MapNode candidateEntry(String candidateName) {
+ return ImmutableNodes.mapNodeBuilder(Candidate.QNAME).addChild(ImmutableNodes.mapEntry(
+ Candidate.QNAME, CANDIDATE_NAME_QNAME, candidateName)).build();
+ }
+
+ static NormalizedNode<?, ?> entityEntryWithOwner(YangInstanceIdentifier entityId, String owner) {
+ return ImmutableNodes.mapEntryBuilder(ENTITY_QNAME, ENTITY_ID_QNAME, entityId).addChild(
+ ImmutableNodes.leafNode(ENTITY_OWNER_QNAME, owner)).build();
+ }
+}
*/
package org.opendaylight.controller.cluster.datastore.entityownership;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_OWNERS_PATH;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.entityOwnersWithCandidate;
import akka.actor.ActorSelection;
import akka.actor.Props;
import akka.dispatch.OnComplete;
import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications;
import org.opendaylight.controller.cluster.datastore.messages.SuccessReply;
import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
-import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.EntityOwners;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.EntityType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.entity.type.entity.Candidate;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import scala.concurrent.Future;
* @author Thomas Pantelis
*/
class EntityOwnershipShard extends Shard {
- static final YangInstanceIdentifier ENTITY_OWNERS_PATH = YangInstanceIdentifier.of(EntityOwners.QNAME);
- static final QName ENTITY_QNAME = org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.
- md.sal.clustering.entity.owners.rev150804.entity.owners.entity.type.Entity.QNAME;
- static final QName CANDIDATE_NAME = QName.create(Candidate.QNAME, "name");
- static final QName ENTITY_ID = QName.create(ENTITY_QNAME, "id");
- static final QName ENTITY_TYPE = QName.create(EntityType.QNAME, "type");
-
private int transactionIDCounter = 0;
private final String localMemberName;
private final List<BatchedModifications> retryModifications = new ArrayList<>();
modifications.setReady(true);
modifications.setTotalMessagesSent(1);
- NormalizedNode<?, ?> entityOwners = createEntityOwnersWithCandidate(registerCandidate.getEntity(), localMemberName);
+ NormalizedNode<?, ?> entityOwners = entityOwnersWithCandidate(registerCandidate.getEntity().getType(),
+ registerCandidate.getEntity().getId(), localMemberName);
modifications.addModification(new MergeModification(ENTITY_OWNERS_PATH, entityOwners));
tryCommitModifications(modifications);
getSender().tell(SuccessReply.INSTANCE, getSelf());
}
- private NormalizedNode<?, ?> createEntityOwnersWithCandidate(Entity entity, String memberName) {
- MapNode candidateNode = ImmutableNodes.mapNodeBuilder(Candidate.QNAME).addChild(
- ImmutableNodes.mapEntry(Candidate.QNAME, CANDIDATE_NAME, memberName)).build();
-
- MapEntryNode entityNode = ImmutableNodes.mapEntryBuilder(ENTITY_QNAME, ENTITY_ID, entity.getId()).
- addChild(candidateNode).build();
-
- MapEntryNode entityTypeNode = ImmutableNodes.mapEntryBuilder(EntityType.QNAME, ENTITY_TYPE, entity.getType()).
- addChild(ImmutableNodes.mapNodeBuilder(ENTITY_QNAME).addChild(entityNode).build()).build();
-
- return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(EntityOwners.QNAME)).
- addChild(ImmutableNodes.mapNodeBuilder(EntityType.QNAME).addChild(entityTypeNode).build()).build();
- }
-
private void tryCommitModifications(final BatchedModifications modifications) {
if(isLeader()) {
if(isIsolatedLeader()) {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.CANDIDATE_NAME_QNAME;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_ID_QNAME;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_QNAME;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_TYPE_QNAME;
import com.google.common.base.Optional;
import org.opendaylight.controller.cluster.datastore.AbstractActorTest;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.EntityOwners;
ContainerNode entityOwnersNode = (ContainerNode) node;
MapEntryNode entityTypeEntry = getMapEntryNodeChild(entityOwnersNode, EntityType.QNAME,
- EntityOwnershipShard.ENTITY_TYPE, entityType);
+ ENTITY_TYPE_QNAME, entityType);
- MapEntryNode entityEntry = getMapEntryNodeChild(entityTypeEntry, EntityOwnershipShard.ENTITY_QNAME,
- EntityOwnershipShard.ENTITY_ID, entityId);
+ MapEntryNode entityEntry = getMapEntryNodeChild(entityTypeEntry, ENTITY_QNAME, ENTITY_ID_QNAME, entityId);
- getMapEntryNodeChild(entityEntry, Candidate.QNAME, EntityOwnershipShard.CANDIDATE_NAME, candidateName);
+ getMapEntryNodeChild(entityEntry, Candidate.QNAME, CANDIDATE_NAME_QNAME, candidateName);
} catch(AssertionError e) {
throw new AssertionError("Verification of enitity candidate failed - returned data was: " + node, e);
}
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_OWNERS_PATH;
import akka.actor.ActorRef;
import akka.actor.PoisonPill;
import akka.actor.Props;
Stopwatch sw = Stopwatch.createStarted();
while(sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) {
DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
- Optional<NormalizedNode<?, ?>> optional = readTx.read(EntityOwnershipShard.ENTITY_OWNERS_PATH).
+ Optional<NormalizedNode<?, ?>> optional = readTx.read(ENTITY_OWNERS_PATH).
checkedGet(5, TimeUnit.SECONDS);
if(optional.isPresent()) {
return optional.get();
--- /dev/null
+/*
+ * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.datastore.entityownership;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.verify;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_OWNERS_PATH;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.entityEntryWithOwner;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.entityOwnersWithCandidate;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.entityPath;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.cluster.datastore.ShardDataTree;
+import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper;
+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;
+
+/**
+ * Unit tests for EntityOwnerChangeListener.
+ *
+ * @author Thomas Pantelis
+ */
+public class EntityOwnerChangeListenerTest {
+ private static final String LOCAL_MEMBER_NAME = "member-1";
+ private static final String REMOTE_MEMBER_NAME1 = "member-2";
+ private static final String REMOTE_MEMBER_NAME2 = "member-3";
+ private static final String ENTITY_TYPE = "test";
+ private static final YangInstanceIdentifier ENTITY_ID1 =
+ YangInstanceIdentifier.of(QName.create("test", "2015-08-14", "entity1"));
+ private static final YangInstanceIdentifier ENTITY_ID2 =
+ YangInstanceIdentifier.of(QName.create("test", "2015-08-14", "entity2"));
+ 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 EntityOwnershipListenerSupport mockListenerSupport = mock(EntityOwnershipListenerSupport.class);
+ private EntityOwnerChangeListener listener;
+
+ @Before
+ public void setup() {
+ listener = new EntityOwnerChangeListener(LOCAL_MEMBER_NAME, mockListenerSupport);
+ listener.init(shardDataTree);
+ }
+
+ @Test
+ public void testOnDataChanged() 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());
+
+ writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, LOCAL_MEMBER_NAME));
+
+ verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY1, false, true);
+
+ reset(mockListenerSupport);
+ writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, REMOTE_MEMBER_NAME1));
+
+ verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY1, true, false);
+
+ reset(mockListenerSupport);
+ writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, REMOTE_MEMBER_NAME2));
+
+ verify(mockListenerSupport, never()).notifyEntityOwnershipListeners(any(Entity.class), anyBoolean(), anyBoolean());
+
+ writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, LOCAL_MEMBER_NAME));
+
+ verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY1, false, true);
+
+ reset(mockListenerSupport);
+ writeNode(entityPath(ENTITY_TYPE, ENTITY_ID2), entityEntryWithOwner(ENTITY_ID2, REMOTE_MEMBER_NAME1));
+
+ verify(mockListenerSupport, never()).notifyEntityOwnershipListeners(any(Entity.class), anyBoolean(), anyBoolean());
+
+ reset(mockListenerSupport);
+ writeNode(entityPath(ENTITY_TYPE, ENTITY_ID2), entityEntryWithOwner(ENTITY_ID2, LOCAL_MEMBER_NAME));
+
+ verify(mockListenerSupport).notifyEntityOwnershipListeners(ENTITY2, false, true);
+ }
+
+ 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);
+ }
+}
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
+import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_OWNERS_PATH;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;
private NormalizedNode<?, ?> readEntityOwners(TestActorRef<EntityOwnershipShard> shard) throws Exception {
Stopwatch sw = Stopwatch.createStarted();
while(sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) {
- NormalizedNode<?, ?> node = AbstractShardTest.readStore(shard, EntityOwnershipShard.ENTITY_OWNERS_PATH);
+ NormalizedNode<?, ?> node = AbstractShardTest.readStore(shard, ENTITY_OWNERS_PATH);
if(node != null) {
return node;
}