use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.
the class ShardDataTreeTest method doTransaction.
private static DataTreeCandidate doTransaction(final ShardDataTree shardDataTree, final DataTreeOperation operation) throws ExecutionException, InterruptedException {
final ReadWriteShardDataTreeTransaction transaction = shardDataTree.newReadWriteTransaction(nextTransactionId());
final DataTreeModification snapshot = transaction.getSnapshot();
operation.execute(snapshot);
final ShardDataTreeCohort cohort = shardDataTree.finishTransaction(transaction);
immediateCanCommit(cohort);
immediatePreCommit(cohort);
final DataTreeCandidate candidate = cohort.getCandidate();
immediateCommit(cohort);
return candidate;
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.
the class SimpleShardDataTreeCohortTest method testPreCommitWithIllegalArgumentEx.
@Test
public void testPreCommitWithIllegalArgumentEx() throws Exception {
canCommitSuccess();
final Exception cause = new IllegalArgumentException("mock");
doAnswer(invocation -> {
invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).failedPreCommit(cause);
return null;
}).when(mockShardDataTree).startPreCommit(cohort);
@SuppressWarnings("unchecked") final FutureCallback<DataTreeCandidate> callback = mock(FutureCallback.class);
cohort.preCommit(callback);
verify(callback).onFailure(cause);
verifyNoMoreInteractions(callback);
verify(mockUserCohorts).abort();
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.
the class DataTreeChangeListenerActorTest method testDataChangedWhenNotificationsAreEnabled.
@Test
public void testDataChangedWhenNotificationsAreEnabled() {
new TestKit(getSystem()) {
{
final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class);
final ImmutableList<DataTreeCandidate> mockCandidates = ImmutableList.of(mockTreeCandidate);
final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class);
final Props props = DataTreeChangeListenerActor.props(mockListener, TEST_PATH);
final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedNotificationsEnabled");
// Let the DataChangeListener know that notifications should be
// enabled
subject.tell(new EnableNotification(true, "test"), getRef());
subject.tell(new DataTreeChanged(mockCandidates), getRef());
expectMsgClass(DataTreeChangedReply.class);
Mockito.verify(mockListener).onDataTreeChanged(mockCandidates);
}
};
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.
the class AbstractEntityOwnershipTest method commit.
static void commit(final ShardDataTree shardDataTree, final DataTreeModification modification) throws DataValidationFailedException {
modification.ready();
shardDataTree.getDataTree().validate(modification);
final DataTreeCandidate candidate = shardDataTree.getDataTree().prepare(modification);
shardDataTree.getDataTree().commit(candidate);
shardDataTree.notifyListeners(candidate);
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.
the class LegacyDOMDataBrokerAdapterTest method testDataTreeChangeListener.
@SuppressWarnings("unchecked")
@Test
public void testDataTreeChangeListener() {
DOMDataTreeChangeService domDTCLService = (DOMDataTreeChangeService) adapter.getSupportedExtensions().get(DOMDataTreeChangeService.class);
assertNotNull("DOMDataTreeChangeService not found", domDTCLService);
ArgumentCaptor<org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> storeDTCL = ArgumentCaptor.forClass(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener.class);
ListenerRegistration<org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> mockReg = mock(ListenerRegistration.class);
doNothing().when(mockReg).close();
doAnswer(invocation -> storeDTCL.getValue()).when(mockReg).getInstance();
doReturn(mockReg).when(mockConfigStore).registerTreeChangeListener(eq(TestModel.TEST_PATH), storeDTCL.capture());
DOMDataTreeChangeListener brokerDTCL = mock(DOMDataTreeChangeListener.class);
ListenerRegistration<DOMDataTreeChangeListener> reg = domDTCLService.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH), brokerDTCL);
assertEquals("getInstance", brokerDTCL, reg.getInstance());
Collection<DataTreeCandidate> changes = Arrays.asList(mock(DataTreeCandidate.class));
storeDTCL.getValue().onDataTreeChanged(changes);
verify(brokerDTCL).onDataTreeChanged(changes);
reg.close();
verify(mockReg).close();
// Test ClusteredDOMDataTreeChangeListener
ArgumentCaptor<org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> storeClusteredDTCL = ArgumentCaptor.forClass(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener.class);
mockReg = mock(ListenerRegistration.class);
doReturn(mockReg).when(mockConfigStore).registerTreeChangeListener(eq(TestModel.TEST_PATH), storeClusteredDTCL.capture());
final ClusteredDOMDataTreeChangeListener brokerClusteredDTCL = mock(ClusteredDOMDataTreeChangeListener.class);
domDTCLService.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH), brokerClusteredDTCL);
assertTrue("Expected ClusteredDOMDataTreeChangeListener: " + storeClusteredDTCL.getValue(), storeClusteredDTCL.getValue() instanceof org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener);
storeClusteredDTCL.getValue().onDataTreeChanged(changes);
verify(brokerClusteredDTCL).onDataTreeChanged(changes);
}
Aggregations