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;fp=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fentityownership%2FAbstractEntityOwnershipTest.java;h=525e03bb37b9047c7f73119116d4ee2223853f44;hp=0e282fbbbfe09123f17a9ff8998d95fb5e3b8a80;hb=a785966182ba80592f99be5a27a9af1d4c2ac37f;hpb=9f292bb1b22e7afda167ec2f15e75a2ce90dd7f7 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 0e282fbbbf..525e03bb37 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 @@ -13,6 +13,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; 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_OWNERS_PATH; import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_OWNER_QNAME; import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_QNAME; import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_TYPE_QNAME; @@ -68,6 +69,24 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { } } + protected void verifyEntityCandidate(String entityType, YangInstanceIdentifier entityId, String candidateName, + Function> reader) { + AssertionError lastError = null; + Stopwatch sw = Stopwatch.createStarted(); + while(sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) { + NormalizedNode node = reader.apply(ENTITY_OWNERS_PATH); + try { + verifyEntityCandidate(node, entityType, entityId, candidateName); + return; + } catch (AssertionError e) { + lastError = e; + Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); + } + } + + throw lastError; + } + protected MapEntryNode getMapEntryNodeChild(DataContainerNode parent, QName childMap, QName child, Object key) { Optional> childNode = @@ -85,19 +104,40 @@ public class AbstractEntityOwnershipTest extends AbstractActorTest { protected void verifyOwner(String expected, String entityType, YangInstanceIdentifier entityId, Function> reader) { + AssertionError lastError = null; YangInstanceIdentifier entityPath = entityPath(entityType, entityId).node(ENTITY_OWNER_QNAME); Stopwatch sw = Stopwatch.createStarted(); while(sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) { - NormalizedNode node = reader.apply(entityPath); - if(node != null) { + 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; - } else { + } catch(AssertionError e) { + lastError = e; + Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); + } + } + + throw lastError; + } + + protected void verifyNodeRemoved(YangInstanceIdentifier path, + Function> reader) { + AssertionError lastError = null; + Stopwatch sw = Stopwatch.createStarted(); + 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) { + lastError = e; Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } } - fail("Owner was not set for entityId: " + entityId); + throw lastError; } static void writeNode(YangInstanceIdentifier path, NormalizedNode node, ShardDataTree shardDataTree)