Search in sources :

Example 11 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class ForwardingDataTreeChangeListenerTest method testOnDataChanged.

@Test
public void testOnDataChanged() throws Exception {
    final ActorRef actorRef = getSystem().actorOf(MessageCollectorActor.props());
    ForwardingDataTreeChangeListener forwardingListener = new ForwardingDataTreeChangeListener(getSystem().actorSelection(actorRef.path()));
    Collection<DataTreeCandidate> expected = Arrays.asList(Mockito.mock(DataTreeCandidate.class));
    forwardingListener.onDataTreeChanged(expected);
    DataTreeChanged actual = MessageCollectorActor.expectFirstMatching(actorRef, DataTreeChanged.class, 5000);
    Assert.assertSame(expected, actual.getChanges());
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DataTreeChanged(org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged) ActorRef(akka.actor.ActorRef) Test(org.junit.Test)

Example 12 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class DOMDataTreeListenerTest method writeContainerEmptyTreeTest.

@Test
public void writeContainerEmptyTreeTest() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
    assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
    final TestDataTreeListener listener = new TestDataTreeListener(latch);
    final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(ROOT_DATA_TREE_ID, listener);
    final DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
    writeTx.submit();
    latch.await(5, TimeUnit.SECONDS);
    assertEquals(1, listener.getReceivedChanges().size());
    final Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
    assertEquals(1, changes.size());
    DataTreeCandidate candidate = changes.iterator().next();
    assertNotNull(candidate);
    DataTreeCandidateNode candidateRoot = candidate.getRootNode();
    checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
    listenerReg.close();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) CountDownLatch(java.util.concurrent.CountDownLatch) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) Test(org.junit.Test)

Example 13 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class DOMDataTreeListenerTest method rootModificationChildListenerTest.

@Test
public void rootModificationChildListenerTest() throws InterruptedException, TransactionCommitFailedException {
    final CountDownLatch latch = new CountDownLatch(2);
    DOMDataTreeChangeService dataTreeChangeService = getDOMDataTreeChangeService();
    assertNotNull("DOMDataTreeChangeService not found, cannot continue with test!", dataTreeChangeService);
    DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER);
    writeTx.submit().checkedGet();
    final TestDataTreeListener listener = new TestDataTreeListener(latch);
    final ListenerRegistration<TestDataTreeListener> listenerReg = dataTreeChangeService.registerDataTreeChangeListener(OUTER_LIST_DATA_TREE_ID, listener);
    writeTx = domBroker.newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER_2);
    writeTx.submit().checkedGet();
    latch.await(1, TimeUnit.SECONDS);
    assertEquals(2, listener.getReceivedChanges().size());
    Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
    assertEquals(1, changes.size());
    DataTreeCandidate candidate = changes.iterator().next();
    assertNotNull(candidate);
    DataTreeCandidateNode candidateRoot = candidate.getRootNode();
    checkChange(null, OUTER_LIST, ModificationType.WRITE, candidateRoot);
    changes = listener.getReceivedChanges().get(1);
    assertEquals(1, changes.size());
    candidate = changes.iterator().next();
    assertNotNull(candidate);
    candidateRoot = candidate.getRootNode();
    checkChange(OUTER_LIST, OUTER_LIST_2, ModificationType.WRITE, candidateRoot);
    listenerReg.close();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DOMDataTreeChangeService(org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) CountDownLatch(java.util.concurrent.CountDownLatch) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) Test(org.junit.Test)

Example 14 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class InMemoryDOMStoreTreeChangePublisher method registerTreeChangeListener.

<L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerTreeChangeListener(final YangInstanceIdentifier treeId, final L listener, final DataTreeSnapshot snapshot) {
    final AbstractDOMDataTreeChangeListenerRegistration<L> reg = registerTreeChangeListener(treeId, listener);
    final Optional<NormalizedNode<?, ?>> node = snapshot.readNode(YangInstanceIdentifier.EMPTY);
    if (node.isPresent()) {
        final DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode(YangInstanceIdentifier.EMPTY, node.get());
        InMemoryDOMStoreTreeChangePublisher publisher = new InMemoryDOMStoreTreeChangePublisher(notificationManager);
        publisher.registerTreeChangeListener(treeId, listener);
        publisher.publishChange(candidate);
    }
    return reg;
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Example 15 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class InMemoryDOMStoreTreeChangePublisher method notifyListeners.

@Override
protected void notifyListeners(final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> registrations, final YangInstanceIdentifier path, final DataTreeCandidateNode node) {
    final DataTreeCandidate candidate = DataTreeCandidates.newDataTreeCandidate(path, node);
    for (AbstractDOMDataTreeChangeListenerRegistration<?> reg : registrations) {
        LOG.debug("Enqueueing candidate {} to registration {}", candidate, registrations);
        notificationManager.submitNotification(reg, candidate);
    }
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)

Aggregations

DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)41 Test (org.junit.Test)19 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)13 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)9 DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)7 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)7 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)6 ActorRef (akka.actor.ActorRef)5 DataTreeChanged (org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged)5 Props (akka.actor.Props)4 TestKit (akka.testkit.javadsl.TestKit)4 DOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)4 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)3 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)3 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)3 ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException)3 DataValidationFailedException (org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException)3 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)2