use of org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction in project controller by opendaylight.
the class DOMDataTreeListenerTest method replaceChildListContainerInTreeTest.
@Test
public void replaceChildListContainerInTreeTest() 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(ROOT_DATA_TREE_ID, listener);
writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH, OUTER_LIST_2);
writeTx.submit();
latch.await(5, 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, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
changes = listener.getReceivedChanges().get(1);
assertEquals(1, changes.size());
candidate = changes.iterator().next();
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));
assertNotNull(modifiedChild);
checkChange(OUTER_LIST, OUTER_LIST_2, ModificationType.WRITE, modifiedChild);
listenerReg.close();
}
use of org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction in project controller by opendaylight.
the class DOMDataTreeListenerTest method replaceContainerContainerInTreeTest.
@Test
public void replaceContainerContainerInTreeTest() 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(ROOT_DATA_TREE_ID, listener);
writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, TEST_CONTAINER_2);
writeTx.submit();
latch.await(5, 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, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
changes = listener.getReceivedChanges().get(1);
assertEquals(1, changes.size());
candidate = changes.iterator().next();
assertNotNull(candidate);
candidateRoot = candidate.getRootNode();
checkChange(TEST_CONTAINER, TEST_CONTAINER_2, ModificationType.WRITE, candidateRoot);
listenerReg.close();
}
use of org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction in project controller by opendaylight.
the class DOMDataTreeListenerTest method listEntryChangeNonRootRegistrationTest.
@Test
public void listEntryChangeNonRootRegistrationTest() 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);
final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId1 = new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);
final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId2 = new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2);
final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId3 = new YangInstanceIdentifier.NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3);
final MapEntryNode outerListEntry1 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);
final MapEntryNode outerListEntry2 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2);
final MapEntryNode outerListEntry3 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3);
final MapNode listAfter = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(outerListEntry2).withChild(outerListEntry3).build();
writeTx = domBroker.newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH.node(outerListEntryId1));
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH.node(outerListEntryId2), outerListEntry2);
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.OUTER_LIST_PATH.node(outerListEntryId3), outerListEntry3);
writeTx.submit();
latch.await(5, 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, listAfter, ModificationType.SUBTREE_MODIFIED, candidateRoot);
final DataTreeCandidateNode entry1Canditate = candidateRoot.getModifiedChild(outerListEntryId1);
checkChange(outerListEntry1, null, ModificationType.DELETE, entry1Canditate);
final DataTreeCandidateNode entry2Canditate = candidateRoot.getModifiedChild(outerListEntryId2);
checkChange(null, outerListEntry2, ModificationType.WRITE, entry2Canditate);
final DataTreeCandidateNode entry3Canditate = candidateRoot.getModifiedChild(outerListEntryId3);
checkChange(null, outerListEntry3, ModificationType.WRITE, entry3Canditate);
listenerReg.close();
}
use of org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction in project controller by opendaylight.
the class DOMBrokerTest method testDataChangeListener.
/**
* Tests a simple DataChangeListener notification after a write.
*/
@Test
@SuppressWarnings("checkstyle:IllegalThrows")
public void testDataChangeListener() throws Throwable {
final NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
TestDOMDataChangeListener dcListener = new TestDOMDataChangeListener();
domBroker.registerDataChangeListener(OPERATIONAL, TestModel.TEST_PATH, dcListener, DataChangeScope.BASE);
final DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
assertNotNull(writeTx);
writeTx.put(OPERATIONAL, TestModel.TEST_PATH, testNode);
AtomicReference<Throwable> caughtEx = submitTxAsync(writeTx);
dcListener.waitForChange();
if (caughtEx.get() != null) {
throw caughtEx.get();
}
NormalizedNode<?, ?> actualNode = dcListener.capturedChange.getCreatedData().get(TestModel.TEST_PATH);
assertEquals("Created node", testNode, actualNode);
}
use of org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction in project controller by opendaylight.
the class DOMBrokerTest method testDataChangeListenerDoingBlockingWriteTxSubmit.
/**
* Tests a DataChangeListener that does a blocking submit of a write Tx in its onDataChanged method.
* This should throw an exception and not deadlock.
*/
@Test(expected = TransactionCommitDeadlockException.class)
@SuppressWarnings({ "checkstyle:IllegalThrows", "checkstyle:IllegalCatch" })
public void testDataChangeListenerDoingBlockingWriteTxSubmit() throws Throwable {
final AtomicReference<Throwable> caughtCommitEx = new AtomicReference<>();
TestDOMDataChangeListener dcListener = new TestDOMDataChangeListener() {
@Override
public void onDataChanged(final AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change) {
DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
writeTx.put(OPERATIONAL, TestModel.TEST2_PATH, ImmutableNodes.containerNode(TestModel.TEST2_QNAME));
try {
writeTx.submit().get();
} catch (ExecutionException e) {
caughtCommitEx.set(e.getCause());
} catch (Exception e) {
caughtCommitEx.set(e);
} finally {
super.onDataChanged(change);
}
}
};
domBroker.registerDataChangeListener(OPERATIONAL, TestModel.TEST_PATH, dcListener, DataChangeScope.BASE);
final DOMDataWriteTransaction writeTx = domBroker.newWriteOnlyTransaction();
assertNotNull(writeTx);
writeTx.put(OPERATIONAL, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
AtomicReference<Throwable> caughtEx = submitTxAsync(writeTx);
dcListener.waitForChange();
if (caughtEx.get() != null) {
throw caughtEx.get();
}
if (caughtCommitEx.get() != null) {
throw caughtCommitEx.get();
}
}
Aggregations