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());
}
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();
}
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();
}
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;
}
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);
}
}
Aggregations