Search in sources :

Example 6 with DOMDataTreeWriteTransaction

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();
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) Test(org.junit.Test)

Example 7 with DOMDataTreeWriteTransaction

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;
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 8 with DOMDataTreeWriteTransaction

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));
    }
}
Also used : TransactionChainListener(org.opendaylight.mdsal.common.api.TransactionChainListener) DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore) DOMStoreTransactionChain(org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 9 with DOMDataTreeWriteTransaction

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);
    }
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore) Collection(java.util.Collection) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 10 with DOMDataTreeWriteTransaction

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());
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) AsyncTransaction(org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction) Test(org.junit.Test)

Aggregations

DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)13 Test (org.junit.Test)11 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)6 TransactionChainListener (org.opendaylight.mdsal.common.api.TransactionChainListener)5 DOMTransactionChain (org.opendaylight.mdsal.dom.api.DOMTransactionChain)5 ConcurrentDOMDataBroker (org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker)4 DOMStore (org.opendaylight.mdsal.dom.spi.store.DOMStore)4 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 ArrayList (java.util.ArrayList)3 DOMDataTreeReadTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction)3 DOMDataTreeReadWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction)3 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 Collection (java.util.Collection)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)2 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)1 AsyncTransaction (org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction)1