Search in sources :

Example 61 with DataTreeCandidateNode

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();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 62 with DataTreeCandidateNode

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();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 63 with DataTreeCandidateNode

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();
    }
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) AbstractDOMDataTreeChangeListenerRegistration(org.opendaylight.mdsal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration) ArrayList(java.util.ArrayList) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Aggregations

DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode)63 Test (org.junit.Test)48 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)36 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)23 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)15 DataTreeModificationCursor (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor)13 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)9 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)7 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 DOMDataTreeChangeService (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService)6 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)6 ArrayList (java.util.ArrayList)5 NonNull (org.eclipse.jdt.annotation.NonNull)3 ModificationType (org.opendaylight.yangtools.yang.data.tree.api.ModificationType)3 Objects.requireNonNull (java.util.Objects.requireNonNull)2 List (java.util.List)1 BindingCodecTreeNode (org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode)1 BindingDataObjectCodecTreeNode (org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode)1 DOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)1