use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project mdsal by opendaylight.
the class DOMDataTreeListenerTest method replaceContainerContainerInTreeTest.
@Test
public void replaceContainerContainerInTreeTest() throws ExecutionException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
final DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
DOMDataTreeWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
writeTx.commit().get();
final TestDataTreeListener listener = new TestDataTreeListener(latch);
final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener);
writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER_2);
writeTx.commit();
latch.await(5, TimeUnit.SECONDS);
assertEquals(2, listener.getReceivedChanges().size());
List<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
assertEquals(1, changes.size());
DataTreeCandidate candidate = changes.get(0);
assertNotNull(candidate);
DataTreeCandidateNode candidateRoot = candidate.getRootNode();
checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
changes = listener.getReceivedChanges().get(1);
assertEquals(1, changes.size());
candidate = changes.get(0);
assertNotNull(candidate);
candidateRoot = candidate.getRootNode();
checkChange(TEST_CONTAINER, TEST_CONTAINER_2, ModificationType.WRITE, candidateRoot);
listenerReg.close();
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project mdsal by opendaylight.
the class DOMDataTreeListenerTest method replaceChildListContainerInTreeTest.
@Test
public void replaceChildListContainerInTreeTest() throws ExecutionException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
final DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
DOMDataTreeWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
writeTx.commit().get();
final TestDataTreeListener listener = new TestDataTreeListener(latch);
final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener);
writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH, OUTER_LIST_2);
writeTx.commit();
latch.await(5, TimeUnit.SECONDS);
assertEquals(2, listener.getReceivedChanges().size());
List<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
assertEquals(1, changes.size());
DataTreeCandidate candidate = changes.get(0);
assertNotNull(candidate);
DataTreeCandidateNode candidateRoot = candidate.getRootNode();
checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
changes = listener.getReceivedChanges().get(1);
assertEquals(1, changes.size());
candidate = changes.get(0);
assertNotNull(candidate);
candidateRoot = candidate.getRootNode();
checkChange(TEST_CONTAINER, TEST_CONTAINER_2, ModificationType.SUBTREE_MODIFIED, candidateRoot);
final DataTreeCandidateNode modifiedChild = candidateRoot.getModifiedChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)).get();
checkChange(OUTER_LIST, OUTER_LIST_2, ModificationType.WRITE, modifiedChild);
listenerReg.close();
}
use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project mdsal by opendaylight.
the class AbstractDOMStoreTreeChangePublisher method processCandidateTree.
/**
* Process a candidate tree with respect to registered listeners.
*
* @param candidate candidate three which needs to be processed
* @return true if at least one listener was notified or false.
*/
protected final boolean processCandidateTree(@NonNull final DataTreeCandidate candidate) {
final DataTreeCandidateNode node = candidate.getRootNode();
if (node.getModificationType() == ModificationType.UNMODIFIED) {
LOG.debug("Skipping unmodified candidate {}", candidate);
return false;
}
try (var snapshot = takeSnapshot()) {
final List<PathArgument> toLookup = ImmutableList.copyOf(candidate.getRootPath().getPathArguments());
final ListMultimap<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate> listenerChanges = Multimaps.newListMultimap(new IdentityHashMap<>(), ArrayList::new);
lookupAndNotify(toLookup, 0, snapshot.getRootNode(), candidate, listenerChanges);
for (var entry : Multimaps.asMap(listenerChanges).entrySet()) {
notifyListener(entry.getKey(), entry.getValue());
}
return !listenerChanges.isEmpty();
}
}
Aggregations