use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.
the class DataChangeListenerTest method testDataChangedWhenNotificationsAreEnabled.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testDataChangedWhenNotificationsAreEnabled() {
new TestKit(getSystem()) {
{
final AsyncDataChangeEvent mockChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
final AsyncDataChangeListener mockListener = Mockito.mock(AsyncDataChangeListener.class);
final Props props = DataChangeListener.props(mockListener, TEST_PATH);
final ActorRef subject = getSystem().actorOf(props, "testDataChangedNotificationsEnabled");
// Let the DataChangeListener know that notifications should be
// enabled
subject.tell(new EnableNotification(true, "test"), getRef());
subject.tell(new DataChanged(mockChangeEvent), getRef());
expectMsgClass(DataChangedReply.class);
Mockito.verify(mockListener).onDataChanged(mockChangeEvent);
}
};
}
use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.
the class DataChangeListenerTest method testDataChangedWhenNotificationsAreDisabled.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testDataChangedWhenNotificationsAreDisabled() {
new TestKit(getSystem()) {
{
final AsyncDataChangeEvent mockChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
final AsyncDataChangeListener mockListener = Mockito.mock(AsyncDataChangeListener.class);
final Props props = DataChangeListener.props(mockListener, TEST_PATH);
final ActorRef subject = getSystem().actorOf(props, "testDataChangedNotificationsDisabled");
subject.tell(new DataChanged(mockChangeEvent), getRef());
within(duration("1 seconds"), () -> {
expectNoMsg();
Mockito.verify(mockListener, Mockito.never()).onDataChanged(Mockito.any(AsyncDataChangeEvent.class));
return null;
});
}
};
}
use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.
the class DOMBrokerTest method testDataChangeListenerDoingAsyncWriteTxSubmit.
/**
* Tests a DataChangeListener that does an async submit of a write Tx in its onDataChanged method.
* This should succeed without deadlock.
*/
@Test
@SuppressWarnings("checkstyle:IllegalThrows")
public void testDataChangeListenerDoingAsyncWriteTxSubmit() throws Throwable {
final AtomicReference<Throwable> caughtCommitEx = new AtomicReference<>();
final CountDownLatch commitCompletedLatch = new CountDownLatch(1);
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));
Futures.addCallback(writeTx.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
commitCompletedLatch.countDown();
}
@Override
public void onFailure(final Throwable throwable) {
caughtCommitEx.set(throwable);
commitCompletedLatch.countDown();
}
});
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();
}
assertTrue("Commit Future was not invoked", commitCompletedLatch.await(5, TimeUnit.SECONDS));
if (caughtCommitEx.get() != null) {
throw caughtCommitEx.get();
}
}
use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.
the class WildcardedDataChangeListenerTest method testWriteByReplace.
@Test
public void testWriteByReplace() 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 cwuTx = dataBroker.newWriteOnlyTransaction();
cwuTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_CWU_PATH, CWU, true);
cwuTx.submit().get(5, TimeUnit.SECONDS);
assertFalse(eventFuture.isDone());
final WriteTransaction lvuTx = dataBroker.newWriteOnlyTransaction();
TreeComplexUsesAugment tcua = new TreeComplexUsesAugmentBuilder().setListViaUses(Collections.singletonList(LVU)).build();
lvuTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_TCU_PATH, tcua, true);
lvuTx.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
lvuTx.submit().get(5, TimeUnit.SECONDS);
validateEvent(eventFuture.get(1000, TimeUnit.MILLISECONDS));
}
use of org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent in project controller by opendaylight.
the class WildcardedDataChangeListenerTest method testNoChangeOnReplaceWithSameValue.
@Test
public void testNoChangeOnReplaceWithSameValue() throws InterruptedException, TimeoutException, ExecutionException {
DataBroker dataBroker = testContext.getDataBroker();
// We wrote initial state NODE_0_FLOW
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
transaction.submit().get(5, TimeUnit.SECONDS);
// We registered DataChangeListener
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture = SettableFuture.create();
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH, dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
assertFalse(eventFuture.isDone());
final WriteTransaction secondTx = dataBroker.newWriteOnlyTransaction();
secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
secondTx.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
secondTx.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
assertNotNull(event);
// Data change should contains NODE_1 Flow - which was added
assertTrue(event.getCreatedData().containsKey(NODE_1_LVU_PATH));
// Data change must not containe NODE_0 Flow which was replaced with same value.
assertFalse(event.getUpdatedData().containsKey(NODE_0_LVU_PATH));
}
Aggregations