Search in sources :

Example 1 with DOMDataTreeReadWriteTransaction

use of org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction in project controller by opendaylight.

the class ConcurrentDOMDataBrokerTest method testSubmitWithOnlyOneSubTransaction.

@Test
public void testSubmitWithOnlyOneSubTransaction() throws InterruptedException {
    DOMStore configDomStore = mock(DOMStore.class);
    DOMStore operationalDomStore = mock(DOMStore.class);
    DOMStoreReadWriteTransaction mockStoreReadWriteTransaction = mock(DOMStoreReadWriteTransaction.class);
    DOMStoreThreePhaseCommitCohort mockCohort = mock(DOMStoreThreePhaseCommitCohort.class);
    doReturn(mockStoreReadWriteTransaction).when(operationalDomStore).newReadWriteTransaction();
    doReturn(mockCohort).when(mockStoreReadWriteTransaction).ready();
    doReturn(Futures.immediateFuture(false)).when(mockCohort).canCommit();
    doReturn(Futures.immediateFuture(null)).when(mockCohort).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
        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.delete(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
        domDataReadWriteTransaction.submit();
        assertTrue(latch.await(10, TimeUnit.SECONDS));
        assertTrue(commitCohorts.size() == 1);
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) ArrayList(java.util.ArrayList) Collection(java.util.Collection) CountDownLatch(java.util.concurrent.CountDownLatch) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 2 with DOMDataTreeReadWriteTransaction

use of org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction in project controller by opendaylight.

the class DistributedDataStoreIntegrationTest method testCreateChainedTransactionsInQuickSuccession.

@Test
public void testCreateChainedTransactionsInQuickSuccession() throws Exception {
    new IntegrationTestKit(getSystem(), datastoreContextBuilder) {

        {
            try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testCreateChainedTransactionsInQuickSuccession", "cars-1")) {
                final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(LogicalDatastoreType.CONFIGURATION, dataStore).build(), MoreExecutors.directExecutor());
                final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
                DOMTransactionChain txChain = broker.createTransactionChain(listener);
                final List<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();
                final DOMDataTreeWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
                writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, CarsModel.emptyContainer());
                writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
                futures.add(writeTx.submit());
                int numCars = 100;
                for (int i = 0; i < numCars; i++) {
                    final DOMDataTreeReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
                    rwTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.newCarPath("car" + i), CarsModel.newCarEntry("car" + i, BigInteger.valueOf(20000)));
                    futures.add(rwTx.submit());
                }
                for (final CheckedFuture<Void, TransactionCommitFailedException> f : futures) {
                    f.checkedGet();
                }
                final Optional<NormalizedNode<?, ?>> optional = txChain.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", true, optional.isPresent());
                assertEquals("# cars", numCars, ((Collection<?>) optional.get().getValue()).size());
                txChain.close();
                broker.close();
            }
        }
    };
}
Also used : ConcurrentDOMDataBroker(org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) ArrayList(java.util.ArrayList) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) TransactionChainListener(org.opendaylight.mdsal.common.api.TransactionChainListener) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 3 with DOMDataTreeReadWriteTransaction

use of org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction 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 4 with DOMDataTreeReadWriteTransaction

use of org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction in project controller by opendaylight.

the class ConcurrentDOMDataBrokerTest method testLazySubTransactionCreationForReadWriteTransactions.

@Test
public void testLazySubTransactionCreationForReadWriteTransactions() {
    DOMStore configDomStore = mock(DOMStore.class);
    DOMStore operationalDomStore = mock(DOMStore.class);
    DOMStoreReadWriteTransaction storeTxn = mock(DOMStoreReadWriteTransaction.class);
    doReturn(storeTxn).when(operationalDomStore).newReadWriteTransaction();
    doReturn(storeTxn).when(configDomStore).newReadWriteTransaction();
    try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, operationalDomStore, LogicalDatastoreType.CONFIGURATION, configDomStore), futureExecutor)) {
        DOMDataTreeReadWriteTransaction dataTxn = dataBroker.newReadWriteTransaction();
        dataTxn.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY, mock(NormalizedNode.class));
        dataTxn.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY, mock(NormalizedNode.class));
        dataTxn.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
        verify(configDomStore, never()).newReadWriteTransaction();
        verify(operationalDomStore, times(1)).newReadWriteTransaction();
        dataTxn.put(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY, mock(NormalizedNode.class));
        verify(configDomStore, times(1)).newReadWriteTransaction();
        verify(operationalDomStore, times(1)).newReadWriteTransaction();
    }
}
Also used : DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 5 with DOMDataTreeReadWriteTransaction

use of org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction in project controller by opendaylight.

the class DistributedDataStoreIntegrationTest method testChainedTransactionFailureWithSingleShard.

@Test
public void testChainedTransactionFailureWithSingleShard() throws Exception {
    new IntegrationTestKit(getSystem(), datastoreContextBuilder) {

        {
            try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testChainedTransactionFailureWithSingleShard", "cars-1")) {
                final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(LogicalDatastoreType.CONFIGURATION, dataStore).build(), MoreExecutors.directExecutor());
                final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
                final DOMTransactionChain txChain = broker.createTransactionChain(listener);
                final DOMDataTreeReadWriteTransaction writeTx = txChain.newReadWriteTransaction();
                writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
                final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
                writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
                try {
                    writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
                    fail("Expected TransactionCommitFailedException");
                } catch (final TransactionCommitFailedException e) {
                // Expected
                }
                verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
                txChain.close();
                broker.close();
            }
        }
    };
}
Also used : DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) ConcurrentDOMDataBroker(org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker) TransactionChainListener(org.opendaylight.mdsal.common.api.TransactionChainListener) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

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