use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction in project controller by opendaylight.
the class ShardedDOMDataBrokerDelegatingTransactionChain method newReadOnlyTransaction.
@Override
public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
final DOMDataTreeReadTransaction readTxDelegate = txChainDelegate.newReadOnlyTransaction();
final DOMDataReadOnlyTransaction readTx = new ShardedDOMDataBrokerDelegatingReadTransaction(newTransactionIdentifier(), readTxDelegate);
transactionMap.put(readTxDelegate.getIdentifier(), readTx);
return readTx;
}
use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction 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.dom.api.DOMDataReadOnlyTransaction in project controller by opendaylight.
the class MdsalLowLevelTestProvider method unsubscribeDtcl.
@Override
public Future<RpcResult<UnsubscribeDtclOutput>> unsubscribeDtcl() {
LOG.debug("Received unsubscribe-dtcl");
if (idIntsListener == null || dtclReg == null) {
final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "Dtcl missing.", "No DataTreeChangeListener registered.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
}
try {
idIntsListener.tryFinishProcessing().get(120, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "resource-denied-transport", "Unable to finish notification processing in 120 seconds.", "clustering-it", "clustering-it", e);
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
}
dtclReg.close();
dtclReg = null;
if (!idIntsListener.hasTriggered()) {
final RpcError error = RpcResultBuilder.newError(ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" + "any notifications.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
}
final DOMDataReadOnlyTransaction rTx = domDataBroker.newReadOnlyTransaction();
try {
final Optional<NormalizedNode<?, ?>> readResult = rTx.read(CONTROLLER_CONFIG, WriteTransactionsHandler.ID_INT_YID).checkedGet();
if (!readResult.isPresent()) {
final RpcError error = RpcResultBuilder.newError(ErrorType.APPLICATION, "Final read empty.", "No data read from id-ints list.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
}
return Futures.immediateFuture(RpcResultBuilder.success(new UnsubscribeDtclOutputBuilder().setCopyMatches(idIntsListener.checkEqual(readResult.get()))).build());
} catch (final ReadFailedException e) {
final RpcError error = RpcResultBuilder.newError(ErrorType.APPLICATION, "Read failed.", "Final read from id-ints failed.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
}
}
Aggregations