Search in sources :

Example 1 with DOMStore

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

the class ConcurrentDOMDataBrokerTest method testLazySubTransactionCreationForReadOnlyTransactions.

@Test
public void testLazySubTransactionCreationForReadOnlyTransactions() {
    DOMStore configDomStore = mock(DOMStore.class);
    DOMStore operationalDomStore = mock(DOMStore.class);
    DOMStoreReadTransaction storeTxn = mock(DOMStoreReadTransaction.class);
    doReturn(storeTxn).when(operationalDomStore).newReadOnlyTransaction();
    doReturn(storeTxn).when(configDomStore).newReadOnlyTransaction();
    try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, operationalDomStore, LogicalDatastoreType.CONFIGURATION, configDomStore), futureExecutor)) {
        DOMDataTreeReadTransaction dataTxn = dataBroker.newReadOnlyTransaction();
        dataTxn.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
        dataTxn.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
        verify(configDomStore, never()).newReadOnlyTransaction();
        verify(operationalDomStore, times(1)).newReadOnlyTransaction();
        dataTxn.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
        verify(configDomStore, times(1)).newReadOnlyTransaction();
        verify(operationalDomStore, times(1)).newReadOnlyTransaction();
    }
}
Also used : DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction) Test(org.junit.Test)

Example 2 with DOMStore

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

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

the class ConcurrentDOMDataBrokerTest method testLazySubTransactionCreationForWriteOnlyTransactions.

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

Example 4 with DOMStore

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

the class ConcurrentDOMDataBrokerTest method testCreateWriteOnlyTransaction.

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

Example 5 with DOMStore

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

the class ConcurrentDOMDataBrokerTest method testCreateReadOnlyTransaction.

@Test
public void testCreateReadOnlyTransaction() {
    DOMStore domStore = mock(DOMStore.class);
    try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore), futureExecutor)) {
        dataBroker.newReadOnlyTransaction();
        verify(domStore, never()).newReadOnlyTransaction();
    }
}
Also used : DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore) 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