+
+ protected void verifyOwner(String expected, String entityType, YangInstanceIdentifier entityId,
+ Function<YangInstanceIdentifier,NormalizedNode<?,?>> reader) {
+ 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) {
+ Assert.assertEquals("Entity owner", expected, node.getValue().toString());
+ return;
+ } else {
+ Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
+ }
+ }
+
+ fail("Owner was not set for entityId: " + entityId);
+ }
+
+ static void writeNode(YangInstanceIdentifier path, NormalizedNode<?, ?> node, ShardDataTree shardDataTree)
+ throws DataValidationFailedException {
+ DataTreeModification modification = shardDataTree.getDataTree().takeSnapshot().newModification();
+ modification.merge(path, node);
+ commit(shardDataTree, modification);
+ }
+
+ static void deleteNode(YangInstanceIdentifier path, ShardDataTree shardDataTree)
+ throws DataValidationFailedException {
+ DataTreeModification modification = shardDataTree.getDataTree().takeSnapshot().newModification();
+ modification.delete(path);
+ commit(shardDataTree, modification);
+ }
+
+ static void commit(ShardDataTree shardDataTree, DataTreeModification modification)
+ throws DataValidationFailedException {
+ modification.ready();
+
+ shardDataTree.getDataTree().validate(modification);
+ DataTreeCandidateTip candidate = shardDataTree.getDataTree().prepare(modification);
+ shardDataTree.getDataTree().commit(candidate);
+ shardDataTree.notifyListeners(candidate);
+ }