use of org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction in project controller by opendaylight.
the class ShardedDOMDataBrokerDelegatingTransactionChainTest method testNewWriteTransaction.
@Test
public void testNewWriteTransaction() {
DOMDataTreeWriteTransaction delegateWriteTx = mock(DOMDataTreeWriteTransaction.class);
doReturn(delegateWriteTx).when(delegateTxChain).newWriteOnlyTransaction();
doReturn("TEST-WRITE-TX-DELEGATE").when(delegateWriteTx).getIdentifier();
txChain.newWriteOnlyTransaction();
verify(delegateTxChain).newWriteOnlyTransaction();
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction in project controller by opendaylight.
the class ShardedDOMDataBrokerDelegatingTransactionChain method newWriteOnlyTransaction.
@Override
public DOMDataWriteTransaction newWriteOnlyTransaction() {
final DOMDataTreeWriteTransaction writeTxDelegate = txChainDelegate.newWriteOnlyTransaction();
final DOMDataWriteTransaction writeTx = new ShardedDOMDataBrokerDelegatingWriteTransaction(newTransactionIdentifier(), writeTxDelegate);
transactionMap.put(writeTxDelegate.getIdentifier(), writeTx);
return writeTx;
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction in project controller by opendaylight.
the class ConcurrentDOMDataBrokerTest method testCreateTransactionOnChain.
@Test
public void testCreateTransactionOnChain() {
DOMStore domStore = mock(DOMStore.class);
try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore), futureExecutor)) {
DOMStoreReadWriteTransaction operationalTransaction = mock(DOMStoreReadWriteTransaction.class);
DOMStoreTransactionChain mockChain = mock(DOMStoreTransactionChain.class);
doReturn(mockChain).when(domStore).createTransactionChain();
doReturn(operationalTransaction).when(mockChain).newWriteOnlyTransaction();
DOMTransactionChain transactionChain = dataBroker.createTransactionChain(mock(TransactionChainListener.class));
DOMDataTreeWriteTransaction domDataWriteTransaction = transactionChain.newWriteOnlyTransaction();
verify(mockChain, never()).newWriteOnlyTransaction();
domDataWriteTransaction.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY, mock(NormalizedNode.class));
}
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction in project controller by opendaylight.
the class ConcurrentDOMDataBrokerTest method testSubmitWithOnlyTwoSubTransactions.
@Test
public void testSubmitWithOnlyTwoSubTransactions() throws InterruptedException {
DOMStore configDomStore = mock(DOMStore.class);
DOMStore operationalDomStore = mock(DOMStore.class);
DOMStoreReadWriteTransaction operationalTransaction = mock(DOMStoreReadWriteTransaction.class);
DOMStoreReadWriteTransaction configTransaction = mock(DOMStoreReadWriteTransaction.class);
DOMStoreThreePhaseCommitCohort mockCohortOperational = mock(DOMStoreThreePhaseCommitCohort.class);
DOMStoreThreePhaseCommitCohort mockCohortConfig = mock(DOMStoreThreePhaseCommitCohort.class);
doReturn(operationalTransaction).when(operationalDomStore).newReadWriteTransaction();
doReturn(configTransaction).when(configDomStore).newReadWriteTransaction();
doReturn(mockCohortOperational).when(operationalTransaction).ready();
doReturn(Futures.immediateFuture(false)).when(mockCohortOperational).canCommit();
doReturn(Futures.immediateFuture(null)).when(mockCohortOperational).abort();
doReturn(mockCohortConfig).when(configTransaction).ready();
doReturn(Futures.immediateFuture(false)).when(mockCohortConfig).canCommit();
doReturn(Futures.immediateFuture(null)).when(mockCohortConfig).abort();
final CountDownLatch latch = new CountDownLatch(1);
final List<DOMStoreThreePhaseCommitCohort> commitCohorts = new ArrayList<>();
try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, operationalDomStore, LogicalDatastoreType.CONFIGURATION, configDomStore), futureExecutor) {
@Override
@SuppressWarnings("checkstyle:hiddenField")
public CheckedFuture<Void, TransactionCommitFailedException> submit(DOMDataTreeWriteTransaction writeTx, Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
commitCohorts.addAll(cohorts);
latch.countDown();
return super.submit(writeTx, cohorts);
}
}) {
DOMDataTreeReadWriteTransaction domDataReadWriteTransaction = dataBroker.newReadWriteTransaction();
domDataReadWriteTransaction.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY, mock(NormalizedNode.class));
domDataReadWriteTransaction.merge(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY, mock(NormalizedNode.class));
domDataReadWriteTransaction.submit();
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertTrue(commitCohorts.size() == 2);
}
}
use of org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction in project controller by opendaylight.
the class ShardedDOMDataBrokerDelegatingTransactionChainTest method testTransactionChainFailed.
@Test
public void testTransactionChainFailed() {
final DOMDataTreeWriteTransaction writeTxDelegate = mock(DOMDataTreeWriteTransaction.class);
doReturn("DELEGATE-WRITE-TX-1").when(writeTxDelegate).getIdentifier();
doReturn(writeTxDelegate).when(delegateTxChain).newWriteOnlyTransaction();
doNothing().when(txChainlistener).onTransactionChainFailed(any(), any(), any());
// verify writetx fail
txChain.newWriteOnlyTransaction();
txChain.onTransactionChainFailed(delegateTxChain, writeTxDelegate, new Throwable("Fail"));
final ArgumentCaptor<AsyncTransaction> txCaptor = ArgumentCaptor.forClass(AsyncTransaction.class);
final ArgumentCaptor<Throwable> throwableCaptor = ArgumentCaptor.forClass(Throwable.class);
verify(txChainlistener).onTransactionChainFailed(eq(txChain), txCaptor.capture(), throwableCaptor.capture());
assertEquals("DOM-CHAIN-1-0", txCaptor.getValue().getIdentifier());
assertEquals("Fail", throwableCaptor.getValue().getMessage());
// verify readtx fail
final DOMDataTreeReadTransaction readTxDelegate = mock(DOMDataTreeReadTransaction.class);
doReturn("DELEGATE-READ-TX-1").when(readTxDelegate).getIdentifier();
doReturn(readTxDelegate).when(delegateTxChain).newReadOnlyTransaction();
doNothing().when(txChainlistener).onTransactionChainFailed(any(), any(), any());
txChain.newReadOnlyTransaction();
txChain.onTransactionChainFailed(delegateTxChain, readTxDelegate, new Throwable("Fail"));
verify(txChainlistener, times(2)).onTransactionChainFailed(eq(txChain), txCaptor.capture(), throwableCaptor.capture());
assertEquals("DOM-CHAIN-1-1", txCaptor.getValue().getIdentifier());
assertEquals("Fail", throwableCaptor.getValue().getMessage());
// verify readwritetx fail, we must check both read and write failure
// translates to returned readwritetx
// we can reuse write and read tx delegates, just return different
// identifiers to avoid conflicts in keys in tx dictionary
doReturn("DELEGATE-WRITE-RWTX-1").when(writeTxDelegate).getIdentifier();
doReturn("DELEGATE-READ-RWTX-1").when(readTxDelegate).getIdentifier();
txChain.newReadWriteTransaction();
txChain.onTransactionChainFailed(delegateTxChain, writeTxDelegate, new Throwable("Fail"));
verify(txChainlistener, times(3)).onTransactionChainFailed(eq(txChain), txCaptor.capture(), throwableCaptor.capture());
assertEquals("DOM-CHAIN-1-2", txCaptor.getValue().getIdentifier());
assertEquals("Fail", throwableCaptor.getValue().getMessage());
txChain.onTransactionChainFailed(delegateTxChain, readTxDelegate, new Throwable("Fail"));
verify(txChainlistener, times(4)).onTransactionChainFailed(eq(txChain), txCaptor.capture(), throwableCaptor.capture());
assertEquals("DOM-CHAIN-1-2", txCaptor.getValue().getIdentifier());
assertEquals("Fail", throwableCaptor.getValue().getMessage());
}
Aggregations