use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.
the class WildcardedDataChangeListenerTest method testSeparateWrites.
@Test
public void testSeparateWrites() throws InterruptedException, TimeoutException, ExecutionException {
DataBroker dataBroker = testContext.getDataBroker();
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture = SettableFuture.create();
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH, dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_CWU_PATH, CWU, true);
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
transaction.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
validateEvent(event);
}
use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.
the class DeleteNestedAugmentationListenParentTest method deleteChildListenParent.
@Test
public void deleteChildListenParent() throws InterruptedException, ExecutionException, TimeoutException {
DataBroker dataBroker = testContext.getDataBroker();
final WriteTransaction initTx = dataBroker.newWriteOnlyTransaction();
initTx.put(LogicalDatastoreType.OPERATIONAL, LIST11_PATH, createList11(), true);
initTx.submit().get(5, TimeUnit.SECONDS);
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, LIST11_PATH, change -> event.set(change), DataChangeScope.SUBTREE);
final WriteTransaction deleteTx = dataBroker.newWriteOnlyTransaction();
deleteTx.delete(LogicalDatastoreType.OPERATIONAL, LIST11_PATH.augmentation(List11SimpleAugment.class));
deleteTx.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get();
assertFalse(receivedEvent.getRemovedPaths().contains(TLL_COMPLEX_AUGMENT_PATH));
}
use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.
the class WriteParentListenAugmentTest method writeNodeListenAugment.
@Test
public void writeNodeListenAugment() throws Exception {
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
DataBroker dataBroker = testContext.getDataBroker();
ListenerRegistration<org.opendaylight.controller.md.sal.binding.api.DataChangeListener> dclRegistration = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, AUGMENT_WILDCARDED_PATH, change -> event.set(change), DataChangeScope.SUBTREE);
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
TopLevelList tll = new TopLevelListBuilder().setKey(TLL_KEY).addAugmentation(TreeComplexUsesAugment.class, treeComplexUsesAugment("one")).build();
transaction.put(LogicalDatastoreType.OPERATIONAL, TLL_INSTANCE_ID_BA, tll, true);
transaction.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get(1000, TimeUnit.MILLISECONDS);
assertTrue(receivedEvent.getCreatedData().containsKey(AUGMENT_TLL_PATH));
dclRegistration.close();
final WriteTransaction transaction2 = dataBroker.newWriteOnlyTransaction();
transaction2.put(LogicalDatastoreType.OPERATIONAL, AUGMENT_TLL_PATH, treeComplexUsesAugment("two"));
transaction2.submit().get(5, TimeUnit.SECONDS);
TreeComplexUsesAugment readedAug = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, AUGMENT_TLL_PATH).get(5, TimeUnit.SECONDS).get();
assertEquals("two", readedAug.getContainerWithUses().getLeafFromGrouping());
}
use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.
the class Bug4513Test method testDataChangeListener.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testDataChangeListener() throws Exception {
DataChangeListener listener = mock(DataChangeListener.class);
InstanceIdentifier<ListItem> wildCard = InstanceIdentifier.builder(ListenerTest.class).child(ListItem.class).build();
ListenerRegistration<DataChangeListener> reg = getDataBroker().registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, wildCard, listener, AsyncDataBroker.DataChangeScope.SUBTREE);
final ListItem item = writeListItem();
ArgumentCaptor<AsyncDataChangeEvent> captor = ArgumentCaptor.forClass(AsyncDataChangeEvent.class);
verify(listener, timeout(100)).onDataChanged(captor.capture());
AsyncDataChangeEvent event = captor.getValue();
assertEquals("createdData", 1, event.getCreatedData().size());
assertEquals("ListItem", item, event.getCreatedData().values().iterator().next());
}
use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent 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