X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fentityownership%2FAbstractEntityOwnershipTest.java;h=6b148af4fa1195150ce03d6ae42def94e4c46b5e;hp=da8de325a2e75408c48749dedef1a83ab68655ce;hb=20a32e6459fd1e27e7669bf1ebc7742b96787b94;hpb=5464f50be733df1bbbe31cf05665d542d3b7c5e7 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/AbstractEntityOwnershipTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/AbstractEntityOwnershipTest.java index da8de325a2..6b148af4fa 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/AbstractEntityOwnershipTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/AbstractEntityOwnershipTest.java @@ -24,9 +24,9 @@ import akka.pattern.Patterns; import akka.testkit.TestActorRef; import akka.util.Timeout; import com.google.common.base.Function; -import com.google.common.base.Optional; import com.google.common.base.Stopwatch; import com.google.common.util.concurrent.Uninterruptibles; +import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; @@ -58,6 +58,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode; 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.api.schema.tree.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; import org.slf4j.Logger; @@ -77,8 +78,8 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { private static final AtomicInteger NEXT_SHARD_NUM = new AtomicInteger(); - protected void verifyEntityCandidate(NormalizedNode node, String entityType, - YangInstanceIdentifier entityId, String candidateName, boolean expectPresent) { + protected void verifyEntityCandidate(final NormalizedNode node, final String entityType, + final YangInstanceIdentifier entityId, final String candidateName, final boolean expectPresent) { try { assertNotNull("Missing " + EntityOwners.QNAME.toString(), node); assertTrue(node instanceof ContainerNode); @@ -97,8 +98,9 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { } } - protected void verifyEntityCandidate(String entityType, YangInstanceIdentifier entityId, String candidateName, - Function> reader, boolean expectPresent) { + protected void verifyEntityCandidate(final String entityType, final YangInstanceIdentifier entityId, + final String candidateName, final Function> reader, + final boolean expectPresent) { AssertionError lastError = null; Stopwatch sw = Stopwatch.createStarted(); while (sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) { @@ -115,13 +117,13 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { throw lastError; } - protected void verifyEntityCandidate(String entityType, YangInstanceIdentifier entityId, String candidateName, - Function> reader) { + protected void verifyEntityCandidate(final String entityType, final YangInstanceIdentifier entityId, + final String candidateName, final Function> reader) { verifyEntityCandidate(entityType, entityId, candidateName, reader, true); } - protected MapEntryNode getMapEntryNodeChild(DataContainerNode parent, QName childMap, - QName child, Object key, boolean expectPresent) { + protected MapEntryNode getMapEntryNodeChild(final DataContainerNode parent, + final QName childMap, final QName child, final Object key, final boolean expectPresent) { Optional> childNode = parent.getChild(new NodeIdentifier(childMap)); assertEquals("Missing " + childMap.toString(), true, childNode.isPresent()); @@ -138,8 +140,8 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { return entityTypeEntry.isPresent() ? entityTypeEntry.get() : null; } - static void verifyOwner(String expected, String entityType, YangInstanceIdentifier entityId, - Function> reader) { + static void verifyOwner(final String expected, final String entityType, final YangInstanceIdentifier entityId, + final Function> reader) { AssertionError lastError = null; YangInstanceIdentifier entityPath = entityPath(entityType, entityId).node(ENTITY_OWNER_QNAME); Stopwatch sw = Stopwatch.createStarted(); @@ -159,8 +161,8 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { } @SuppressWarnings("checkstyle:IllegalCatch") - static void verifyOwner(final TestActorRef shard, String entityType, - YangInstanceIdentifier entityId, String localMemberName) { + static void verifyOwner(final TestActorRef shard, final String entityType, + final YangInstanceIdentifier entityId, final String localMemberName) { verifyOwner(localMemberName, entityType, entityId, path -> { try { return AbstractShardTest.readStore(shard, path); @@ -170,8 +172,8 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { }); } - protected void verifyNodeRemoved(YangInstanceIdentifier path, - Function> reader) { + protected void verifyNodeRemoved(final YangInstanceIdentifier path, + final Function> reader) { AssertionError lastError = null; Stopwatch sw = Stopwatch.createStarted(); while (sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) { @@ -188,23 +190,27 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { throw lastError; } - static void writeNode(YangInstanceIdentifier path, NormalizedNode node, ShardDataTree shardDataTree) - throws DataValidationFailedException { + static void writeNode(final YangInstanceIdentifier path, final NormalizedNode node, + final ShardDataTree shardDataTree) throws DataValidationFailedException { DataTreeModification modification = shardDataTree.newModification(); modification.merge(path, node); commit(shardDataTree, modification); } - static void deleteNode(YangInstanceIdentifier path, ShardDataTree shardDataTree) + static void deleteNode(final YangInstanceIdentifier path, final ShardDataTree shardDataTree) throws DataValidationFailedException { DataTreeModification modification = shardDataTree.newModification(); modification.delete(path); commit(shardDataTree, modification); } - static void commit(ShardDataTree shardDataTree, DataTreeModification modification) + static void commit(final ShardDataTree shardDataTree, final DataTreeModification modification) throws DataValidationFailedException { - shardDataTree.notifyListeners(shardDataTree.commit(modification)); + modification.ready(); + shardDataTree.getDataTree().validate(modification); + final DataTreeCandidate candidate = shardDataTree.getDataTree().prepare(modification); + shardDataTree.getDataTree().commit(candidate); + shardDataTree.notifyListeners(candidate); } static DOMEntityOwnershipChange ownershipChange(final DOMEntity expEntity, final boolean expWasOwner, @@ -216,7 +222,7 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { final boolean expIsOwner, final boolean expHasOwner, final boolean expInJeopardy) { return Matchers.argThat(new ArgumentMatcher() { @Override - public boolean matches(Object argument) { + public boolean matches(final Object argument) { DOMEntityOwnershipChange change = (DOMEntityOwnershipChange) argument; return expEntity.equals(change.getEntity()) && expWasOwner == change.getState().wasOwner() && expIsOwner == change.getState().isOwner() && expHasOwner == change.getState().hasOwner() @@ -224,7 +230,7 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { } @Override - public void describeTo(Description description) { + public void describeTo(final Description description) { description.appendValue(new DOMEntityOwnershipChange(expEntity, EntityOwnershipChangeState.from( expWasOwner, expIsOwner, expHasOwner), expInJeopardy)); } @@ -234,13 +240,13 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { static DOMEntityOwnershipChange ownershipChange(final DOMEntity expEntity) { return Matchers.argThat(new ArgumentMatcher() { @Override - public boolean matches(Object argument) { + public boolean matches(final Object argument) { DOMEntityOwnershipChange change = (DOMEntityOwnershipChange) argument; return expEntity.equals(change.getEntity()); } @Override - public void describeTo(Description description) { + public void describeTo(final Description description) { description.appendValue(new DOMEntityOwnershipChange(expEntity, EntityOwnershipChangeState.from( false, false, false))); } @@ -248,8 +254,8 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { } @SuppressWarnings("checkstyle:IllegalCatch") - static void verifyNoOwnerSet(TestActorRef shard, String entityType, - YangInstanceIdentifier entityId) { + static void verifyNoOwnerSet(final TestActorRef shard, final String entityType, + final YangInstanceIdentifier entityId) { YangInstanceIdentifier entityPath = entityPath(entityType, entityId).node(ENTITY_OWNER_QNAME); try { NormalizedNode node = AbstractShardTest.readStore(shard, entityPath); @@ -263,7 +269,7 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { } static void verifyRaftState(final TestActorRef shard, - Consumer verifier) + final Consumer verifier) throws Exception { AssertionError lastError = null; Stopwatch sw = Stopwatch.createStarted(); @@ -283,14 +289,14 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { throw lastError; } - static ShardIdentifier newShardId(String memberName) { + static ShardIdentifier newShardId(final String memberName) { return ShardIdentifier.create("entity-ownership", MemberName.forName(memberName), "operational" + NEXT_SHARD_NUM.getAndIncrement()); } @SuppressWarnings("checkstyle:IllegalCatch") - void verifyEntityCandidateRemoved(final TestActorRef shard, String entityType, - YangInstanceIdentifier entityId, String candidateName) { + void verifyEntityCandidateRemoved(final TestActorRef shard, final String entityType, + final YangInstanceIdentifier entityId, final String candidateName) { verifyNodeRemoved(candidatePath(entityType, entityId, candidateName), path -> { try { return AbstractShardTest.readStore(shard, path); @@ -301,8 +307,8 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { } @SuppressWarnings("checkstyle:IllegalCatch") - void verifyCommittedEntityCandidate(final TestActorRef shard, String entityType, - YangInstanceIdentifier entityId, String candidateName) { + void verifyCommittedEntityCandidate(final TestActorRef shard, + final String entityType, final YangInstanceIdentifier entityId, final String candidateName) { verifyEntityCandidate(entityType, entityId, candidateName, path -> { try { return AbstractShardTest.readStore(shard, path); @@ -313,8 +319,8 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { } @SuppressWarnings("checkstyle:IllegalCatch") - void verifyNoEntityCandidate(final TestActorRef shard, String entityType, - YangInstanceIdentifier entityId, String candidateName) { + void verifyNoEntityCandidate(final TestActorRef shard, final String entityType, + final YangInstanceIdentifier entityId, final String candidateName) { verifyEntityCandidate(entityType, entityId, candidateName, path -> { try { return AbstractShardTest.readStore(shard, path);