use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.
the class ShardedDOMDataBrokerDelegatingTransactionChain method newReadWriteTransaction.
@Override
public DOMDataReadWriteTransaction newReadWriteTransaction() {
final Object readWriteTxId = newTransactionIdentifier();
final DOMDataTreeReadTransaction readTxDelegate = txChainDelegate.newReadOnlyTransaction();
final DOMDataReadOnlyTransaction readTx = new ShardedDOMDataBrokerDelegatingReadTransaction(readWriteTxId, readTxDelegate);
final DOMDataTreeWriteTransaction writeTxDelegate = txChainDelegate.newWriteOnlyTransaction();
final DOMDataWriteTransaction writeTx = new ShardedDOMDataBrokerDelegatingWriteTransaction(readWriteTxId, writeTxDelegate);
final DOMDataReadWriteTransaction readWriteTx = new ShardedDOMDataBrokerDelegatingReadWriteTransaction(readWriteTxId, schemaContext, readTx, writeTx);
transactionMap.put(readTxDelegate.getIdentifier(), readWriteTx);
transactionMap.put(writeTxDelegate.getIdentifier(), readWriteTx);
return readWriteTx;
}
use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction in project controller by opendaylight.
the class TracingBrokerTest method testPrintOpenTransactions.
@Test
// Finding resource leaks is the point of this test
@SuppressWarnings({ "resource", "unused" })
public void testPrintOpenTransactions() {
DOMDataBroker domDataBroker = mock(DOMDataBroker.class, RETURNS_DEEP_STUBS);
Config config = new ConfigBuilder().setTransactionDebugContextEnabled(true).build();
BindingNormalizedNodeSerializer codec = mock(BindingNormalizedNodeSerializer.class);
TracingBroker tracingBroker = new TracingBroker(domDataBroker, config, codec);
DOMDataReadWriteTransaction tx = tracingBroker.newReadWriteTransaction();
DOMTransactionChain txChain = tracingBroker.createTransactionChain(null);
DOMDataReadWriteTransaction txFromChain = txChain.newReadWriteTransaction();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
boolean printReturnValue = tracingBroker.printOpenTransactions(ps);
String output = new String(baos.toByteArray(), UTF_8);
assertThat(printReturnValue).isTrue();
// Assert expections about stack trace
assertThat(output).contains("testPrintOpenTransactions(TracingBrokerTest.java");
assertThat(output).doesNotContain(TracingBroker.class.getName());
String previousLine = "";
for (String line : output.split("\n")) {
if (line.contains("(...")) {
assertThat(previousLine.contains("(...)")).isFalse();
}
previousLine = line;
}
// We don't do any verify/times on the mocks,
// because the main point of the test is just to verify that
// printOpenTransactions runs through without any exceptions
// (e.g. it used to have a ClassCastException).
}
use of org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction 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.DOMDataReadWriteTransaction in project controller by opendaylight.
the class LegacyDOMDataBrokerAdapterTest method testReadWriteTransaction.
@Test
public void testReadWriteTransaction() throws Exception {
DOMDataReadWriteTransaction tx = adapter.newReadWriteTransaction();
CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture = tx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
Optional<NormalizedNode<?, ?>> readOptional = readFuture.get();
assertEquals("isPresent", true, readOptional.isPresent());
assertEquals("NormalizedNode", dataNode, readOptional.get());
tx.put(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH, dataNode);
verify(mockReadWriteTx).write(TestModel.TEST_PATH, dataNode);
CheckedFuture<Void, TransactionCommitFailedException> submitFuture = tx.submit();
submitFuture.get(5, TimeUnit.SECONDS);
InOrder inOrder = inOrder(mockCommitCohort);
inOrder.verify(mockCommitCohort).canCommit();
inOrder.verify(mockCommitCohort).preCommit();
inOrder.verify(mockCommitCohort).commit();
}
Aggregations