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%2FAbstractEntityOwnershipTest.java;h=05d37fd1b2a2dc74663c9f9f5b1bf486684dc0cb;hb=cd3a0e09db5a1def00c46a4be245dbdf648b539c;hp=eb797eebd1afebe6143a094ba2e0b7f0130d7ba2;hpb=0fab6c716548e89938c1a8493dc25991c006aa10;p=controller.git 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 eb797eebd1..05d37fd1b2 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 @@ -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; @@ -92,7 +93,7 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { entityId, true); getMapEntryNodeChild(entityEntry, Candidate.QNAME, CANDIDATE_NAME_QNAME, candidateName, expectPresent); - } catch(AssertionError e) { + } catch (AssertionError e) { throw new AssertionError("Verification of entity candidate failed - returned data was: " + node, e); } } @@ -101,7 +102,7 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { Function> reader, boolean expectPresent) { AssertionError lastError = null; Stopwatch sw = Stopwatch.createStarted(); - while(sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) { + while (sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) { NormalizedNode node = reader.apply(ENTITY_OWNERS_PATH); try { verifyEntityCandidate(node, entityType, entityId, candidateName, expectPresent); @@ -129,9 +130,9 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { MapNode entityTypeMapNode = (MapNode) childNode.get(); Optional entityTypeEntry = entityTypeMapNode.getChild(new NodeIdentifierWithPredicates( childMap, child, key)); - if(expectPresent && !entityTypeEntry.isPresent()) { + if (expectPresent && !entityTypeEntry.isPresent()) { fail("Missing " + childMap.toString() + " entry for " + key + ". Actual: " + entityTypeMapNode.getValue()); - } else if(!expectPresent && entityTypeEntry.isPresent()) { + } else if (!expectPresent && entityTypeEntry.isPresent()) { fail("Found unexpected " + childMap.toString() + " entry for " + key); } @@ -143,13 +144,13 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { AssertionError lastError = null; YangInstanceIdentifier entityPath = entityPath(entityType, entityId).node(ENTITY_OWNER_QNAME); Stopwatch sw = Stopwatch.createStarted(); - while(sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) { + while (sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) { try { NormalizedNode node = reader.apply(entityPath); Assert.assertNotNull("Owner was not set for entityId: " + entityId, node); Assert.assertEquals("Entity owner", expected, node.getValue().toString()); return; - } catch(AssertionError e) { + } catch (AssertionError e) { lastError = e; Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } @@ -158,16 +159,28 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { throw lastError; } + @SuppressWarnings("checkstyle:IllegalCatch") + static void verifyOwner(final TestActorRef shard, String entityType, + YangInstanceIdentifier entityId, String localMemberName) { + verifyOwner(localMemberName, entityType, entityId, path -> { + try { + return AbstractShardTest.readStore(shard, path); + } catch (Exception e) { + return null; + } + }); + } + protected void verifyNodeRemoved(YangInstanceIdentifier path, Function> reader) { AssertionError lastError = null; Stopwatch sw = Stopwatch.createStarted(); - while(sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) { + while (sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) { try { NormalizedNode node = reader.apply(path); Assert.assertNull("Node was not removed at path: " + path, node); return; - } catch(AssertionError e) { + } catch (AssertionError e) { lastError = e; Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } @@ -192,7 +205,11 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { static void commit(ShardDataTree shardDataTree, 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, @@ -206,9 +223,9 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { @Override public boolean matches(Object argument) { DOMEntityOwnershipChange change = (DOMEntityOwnershipChange) argument; - return expEntity.equals(change.getEntity()) && expWasOwner == change.getState().wasOwner() && - expIsOwner == change.getState().isOwner() && expHasOwner == change.getState().hasOwner() && - expInJeopardy == change.inJeopardy(); + return expEntity.equals(change.getEntity()) && expWasOwner == change.getState().wasOwner() + && expIsOwner == change.getState().isOwner() && expHasOwner == change.getState().hasOwner() + && expInJeopardy == change.inJeopardy(); } @Override @@ -235,23 +252,13 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { }); } - static void verifyOwner(final TestActorRef shard, String entityType, - YangInstanceIdentifier entityId, String localMemberName) { - verifyOwner(localMemberName, entityType, entityId, path -> { - try { - return AbstractShardTest.readStore(shard, path); - } catch(Exception e) { - return null; - } - }); - } - + @SuppressWarnings("checkstyle:IllegalCatch") static void verifyNoOwnerSet(TestActorRef shard, String entityType, YangInstanceIdentifier entityId) { YangInstanceIdentifier entityPath = entityPath(entityType, entityId).node(ENTITY_OWNER_QNAME); try { NormalizedNode node = AbstractShardTest.readStore(shard, entityPath); - if(node != null) { + if (node != null) { Assert.fail("Owner " + node.getValue() + " was set for " + entityPath); } @@ -260,11 +267,12 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { } } - static void verifyRaftState(final TestActorRef shard, Consumer verifier) + static void verifyRaftState(final TestActorRef shard, + Consumer verifier) throws Exception { AssertionError lastError = null; Stopwatch sw = Stopwatch.createStarted(); - while(sw.elapsed(TimeUnit.SECONDS) <= 5) { + while (sw.elapsed(TimeUnit.SECONDS) <= 5) { FiniteDuration operationDuration = Duration.create(5, TimeUnit.SECONDS); Future future = Patterns.ask(shard, GetOnDemandRaftState.INSTANCE, new Timeout(operationDuration)); OnDemandRaftState raftState = (OnDemandRaftState)Await.result(future, operationDuration); @@ -285,35 +293,37 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { "operational" + NEXT_SHARD_NUM.getAndIncrement()); } + @SuppressWarnings("checkstyle:IllegalCatch") void verifyEntityCandidateRemoved(final TestActorRef shard, String entityType, YangInstanceIdentifier entityId, String candidateName) { - verifyNodeRemoved(candidatePath(entityType, entityId, candidateName), - path -> { - try { - return AbstractShardTest.readStore(shard, path); - } catch(Exception e) { - throw new AssertionError("Failed to read " + path, e); - } - }); + verifyNodeRemoved(candidatePath(entityType, entityId, candidateName), path -> { + try { + return AbstractShardTest.readStore(shard, path); + } catch (Exception e) { + throw new AssertionError("Failed to read " + path, e); + } + }); } + @SuppressWarnings("checkstyle:IllegalCatch") void verifyCommittedEntityCandidate(final TestActorRef shard, String entityType, YangInstanceIdentifier entityId, String candidateName) { verifyEntityCandidate(entityType, entityId, candidateName, path -> { try { return AbstractShardTest.readStore(shard, path); - } catch(Exception e) { + } catch (Exception e) { throw new AssertionError("Failed to read " + path, e); } }); } + @SuppressWarnings("checkstyle:IllegalCatch") void verifyNoEntityCandidate(final TestActorRef shard, String entityType, YangInstanceIdentifier entityId, String candidateName) { verifyEntityCandidate(entityType, entityId, candidateName, path -> { try { return AbstractShardTest.readStore(shard, path); - } catch(Exception e) { + } catch (Exception e) { throw new AssertionError("Failed to read " + path, e); } }, false);