Search in sources :

Example 6 with DOMStore

use of org.opendaylight.mdsal.dom.spi.store.DOMStore in project controller by opendaylight.

the class AbstractDOMBroker method getDOMStore.

private DOMStore getDOMStore(final LogicalDatastoreType type) {
    DOMStore store = getTxFactories().get(type);
    checkState(store != null, "Requested logical data store is not available.");
    return store;
}
Also used : DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore)

Example 7 with DOMStore

use of org.opendaylight.mdsal.dom.spi.store.DOMStore 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 8 with DOMStore

use of org.opendaylight.mdsal.dom.spi.store.DOMStore in project controller by opendaylight.

the class ConcurrentDOMDataBrokerTest method testEmptyTransactionSubmitSucceeds.

@Test
public void testEmptyTransactionSubmitSucceeds() throws ExecutionException, InterruptedException {
    DOMStore domStore = mock(DOMStore.class);
    try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore), futureExecutor)) {
        CheckedFuture<Void, TransactionCommitFailedException> submit1 = dataBroker.newWriteOnlyTransaction().submit();
        assertNotNull(submit1);
        submit1.get();
        CheckedFuture<Void, TransactionCommitFailedException> submit2 = dataBroker.newReadWriteTransaction().submit();
        assertNotNull(submit2);
        submit2.get();
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore) Test(org.junit.Test)

Example 9 with DOMStore

use of org.opendaylight.mdsal.dom.spi.store.DOMStore in project controller by opendaylight.

the class ConcurrentDOMDataBrokerTest method testCreateReadWriteTransaction.

@Test
public void testCreateReadWriteTransaction() {
    DOMStore domStore = mock(DOMStore.class);
    try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore), futureExecutor)) {
        dataBroker.newReadWriteTransaction();
        verify(domStore, never()).newReadWriteTransaction();
    }
}
Also used : DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore) Test(org.junit.Test)

Example 10 with DOMStore

use of org.opendaylight.mdsal.dom.spi.store.DOMStore 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)

Aggregations

DOMStore (org.opendaylight.mdsal.dom.spi.store.DOMStore)13 Test (org.junit.Test)11 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)4 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)4 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)3 DOMDataTreeReadWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TransactionChainListener (org.opendaylight.mdsal.common.api.TransactionChainListener)2 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)2 Before (org.junit.Before)1 DOMDataTreeReadTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction)1 DOMTransactionChain (org.opendaylight.mdsal.dom.api.DOMTransactionChain)1 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)1 DOMStoreTransactionChain (org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain)1 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)1 InMemoryDOMDataStore (org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStore)1