use of org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener in project controller by opendaylight.
the class CrossBrokerMountPointTest method testMountPoint.
@Test
public void testMountPoint() throws ReadFailedException, TimeoutException {
final Integer attrIntValue = 500;
domMountPointService.createMountPoint(TLL_INSTANCE_ID_BI).addService(DOMDataBroker.class, new DOMDataBroker() {
@Override
public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store, final YangInstanceIdentifier path, final DOMDataChangeListener listener, final DataChangeScope triggeringScope) {
throw new UnsupportedOperationException();
}
@Override
public DOMDataWriteTransaction newWriteOnlyTransaction() {
throw new UnsupportedOperationException();
}
@Override
public DOMDataReadWriteTransaction newReadWriteTransaction() {
return new DOMDataReadWriteTransaction() {
@Override
public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
if (store == LogicalDatastoreType.OPERATIONAL && path.getLastPathArgument().equals(GROUP_STATISTICS_ID_BI.getLastPathArgument())) {
final ContainerNode data = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(AUG_CONT)).withChild(ImmutableNodes.leafNode(QName.create(AUG_CONT, "attr-int"), attrIntValue)).build();
return Futures.immediateCheckedFuture(Optional.<NormalizedNode<?, ?>>of(data));
}
return Futures.immediateFailedCheckedFuture(new ReadFailedException(TLL_NAME, new Exception()));
}
@Override
public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
throw new UnsupportedOperationException();
}
@Override
public Object getIdentifier() {
return this;
}
@Override
public boolean cancel() {
return false;
}
@Override
public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
throw new UnsupportedOperationException();
}
@Override
public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
throw new UnsupportedOperationException();
}
@Override
public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
throw new UnsupportedOperationException();
}
@Override
public CheckedFuture<Void, TransactionCommitFailedException> submit() {
throw new UnsupportedOperationException();
}
};
}
@Override
public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
throw new UnsupportedOperationException();
}
@Override
public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
throw new UnsupportedOperationException();
}
@Override
public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
return Collections.emptyMap();
}
}).register();
final Optional<MountPoint> bindingMountPoint = bindingMountPointService.getMountPoint(TLL_INSTANCE_ID_BA);
assertTrue(bindingMountPoint.isPresent());
final Optional<DataBroker> dataBroker = bindingMountPoint.get().getService(DataBroker.class);
assertTrue(dataBroker.isPresent());
final Optional<Cont> data = dataBroker.get().newReadWriteTransaction().read(LogicalDatastoreType.OPERATIONAL, AUG_CONT_ID_BA).checkedGet(5, TimeUnit.SECONDS);
assertTrue(data.isPresent());
assertEquals(attrIntValue, data.get().getAttrInt());
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener in project controller by opendaylight.
the class LegacyDOMDataBrokerAdapter method createTransactionChain.
@Override
public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
AtomicReference<DOMTransactionChain> legacyChain = new AtomicReference<>();
org.opendaylight.mdsal.common.api.TransactionChainListener delegateListener = new org.opendaylight.mdsal.common.api.TransactionChainListener() {
@SuppressWarnings("rawtypes")
@Override
public void onTransactionChainFailed(final org.opendaylight.mdsal.common.api.TransactionChain<?, ?> chain, final org.opendaylight.mdsal.common.api.AsyncTransaction<?, ?> transaction, final Throwable cause) {
listener.onTransactionChainFailed(legacyChain.get(), (AsyncTransaction) () -> transaction.getIdentifier(), cause instanceof Exception ? SUBMIT_EX_MAPPER.apply((Exception) cause) : cause);
}
@Override
public void onTransactionChainSuccessful(org.opendaylight.mdsal.common.api.TransactionChain<?, ?> chain) {
listener.onTransactionChainSuccessful(legacyChain.get());
}
};
final org.opendaylight.mdsal.dom.api.DOMTransactionChain delegateChain = delegate().createTransactionChain(delegateListener);
legacyChain.set(new DOMTransactionChain() {
@Override
public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
return new DOMDataReadOnlyTransactionAdapter(delegateChain.newReadOnlyTransaction());
}
@Override
public DOMDataReadWriteTransaction newReadWriteTransaction() {
return new DOMDataTransactionAdapter(delegateChain.newReadWriteTransaction());
}
@Override
public DOMDataWriteTransaction newWriteOnlyTransaction() {
return new DOMDataTransactionAdapter(delegateChain.newWriteOnlyTransaction());
}
@Override
public void close() {
delegateChain.close();
}
});
return legacyChain.get();
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener in project controller by opendaylight.
the class LegacyDOMDataBrokerAdapterTest method testTransactionChain.
@SuppressWarnings("rawtypes")
@Test
public void testTransactionChain() throws Exception {
TransactionChainListener mockListener = mock(TransactionChainListener.class);
doNothing().when(mockListener).onTransactionChainSuccessful(anyObject());
doNothing().when(mockListener).onTransactionChainFailed(anyObject(), anyObject(), anyObject());
DOMTransactionChain chain = adapter.createTransactionChain(mockListener);
// Test read-only tx
DOMDataReadOnlyTransaction readTx = chain.newReadOnlyTransaction();
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture = readTx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
Optional<NormalizedNode<?, ?>> readOptional = readFuture.get();
assertEquals("isPresent", true, readOptional.isPresent());
assertEquals("NormalizedNode", dataNode, readOptional.get());
// Test write-only tx
DOMDataWriteTransaction writeTx = chain.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
verify(mockWriteTx).write(TestModel.TEST_PATH, dataNode);
CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTx.submit();
submitFuture.get(5, TimeUnit.SECONDS);
InOrder inOrder = inOrder(mockCommitCohort);
inOrder.verify(mockCommitCohort).canCommit();
inOrder.verify(mockCommitCohort).preCommit();
inOrder.verify(mockCommitCohort).commit();
// Test read-write tx
DOMDataReadWriteTransaction readWriteTx = chain.newReadWriteTransaction();
readFuture = readWriteTx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
readOptional = readFuture.get();
assertEquals("isPresent", true, readOptional.isPresent());
assertEquals("NormalizedNode", dataNode, readOptional.get());
chain.close();
verify(mockListener).onTransactionChainSuccessful(chain);
// Test failed chain
doReturn(Futures.immediateFailedFuture(new org.opendaylight.mdsal.common.api.TransactionCommitFailedException("mock", (Throwable) null))).when(mockCommitCohort).canCommit();
chain = adapter.createTransactionChain(mockListener);
writeTx = chain.newWriteOnlyTransaction();
try {
writeTx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
} catch (TransactionCommitFailedException e) {
// expected
}
ArgumentCaptor<AsyncTransaction> failedTx = ArgumentCaptor.forClass(AsyncTransaction.class);
verify(mockListener).onTransactionChainFailed(eq(chain), failedTx.capture(), any(TransactionCommitFailedException.class));
}
use of org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener in project bgpcep by opendaylight.
the class AbstractConfig method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
doReturn(InstanceIdentifier.create(BgpRib.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.Rib.class, new RibKey(RIB_ID))).when(this.rib).getInstanceIdentifier();
doReturn(this.domTx).when(this.rib).createPeerDOMChain(any(TransactionChainListener.class));
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
return getDataBroker().createTransactionChain((TransactionChainListener) args[0]);
}).when(this.rib).createPeerChain(any(TransactionChainListener.class));
doReturn(getDataBroker()).when(this.rib).getDataBroker();
doReturn(AS).when(this.rib).getLocalAs();
doReturn(mock(RIBSupportContextRegistry.class)).when(this.rib).getRibSupportContext();
doReturn(Collections.emptySet()).when(this.rib).getLocalTablesKeys();
doNothing().when(this.domTx).close();
doReturn(this.domDW).when(this.domTx).newWriteOnlyTransaction();
doNothing().when(this.domDW).put(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(MapEntryNode.class));
doNothing().when(this.domDW).delete(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class));
doNothing().when(this.domDW).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
final CheckedFuture<?, ?> checkedFuture = mock(CheckedFuture.class);
doAnswer(invocation -> {
final Runnable callback = (Runnable) invocation.getArguments()[0];
callback.run();
return null;
}).when(checkedFuture).addListener(Mockito.any(Runnable.class), Mockito.any(Executor.class));
doReturn(checkedFuture).when(this.domDW).submit();
doReturn(null).when(checkedFuture).checkedGet();
doReturn(null).when(checkedFuture).get();
doReturn(true).when(checkedFuture).isDone();
doReturn("checkedFuture").when(checkedFuture).toString();
doReturn(YangInstanceIdentifier.of(Rib.QNAME)).when(this.rib).getYangRibId();
doReturn(this.dataTreeChangeService).when(this.rib).getService();
doReturn(this.listener).when(this.dataTreeChangeService).registerDataTreeChangeListener(any(), any());
doReturn(new BgpId("127.0.0.1")).when(this.rib).getBgpIdentifier();
doReturn(true).when(this.future).cancel(true);
doReturn(this.future).when(this.dispatcher).createReconnectingClient(any(InetSocketAddress.class), anyInt(), any(KeyMapping.class));
doReturn(this.dispatcher).when(this.rib).getDispatcher();
doReturn(java.util.Optional.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class))).when(this.tableTypeRegistry).getTableType(any());
doReturn(java.util.Optional.of(TABLES_KEY)).when(this.tableTypeRegistry).getTableKey(any());
doReturn(Collections.singleton(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class))).when(this.rib).getLocalTables();
doNothing().when(this.bgpPeerRegistry).addPeer(any(IpAddress.class), any(BGPSessionListener.class), any(BGPSessionPreferences.class));
doNothing().when(this.bgpPeerRegistry).removePeer(any(IpAddress.class));
doReturn("registry").when(this.bgpPeerRegistry).toString();
doNothing().when(this.listener).close();
doReturn(this.bgpPeerRegistry).when(this.dispatcher).getBGPPeerRegistry();
doReturn(this.peerTracker).when(this.rib).getPeerTracker();
doReturn(this.policies).when(this.rib).getRibPolicies();
doReturn(null).when(this.peerGroupLoader).getPeerGroup(any(InstanceIdentifier.class), any(String.class));
}
Aggregations