Search in sources :

Example 11 with DOMStoreTransactionChain

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

the class DistributedDataStoreIntegrationTest method testChainWithReadOnlyTxAfterPreviousReady.

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

        {
            try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testChainWithReadOnlyTxAfterPreviousReady", "test-1")) {
                final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
                // Create a write tx and submit.
                final DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
                writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
                final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
                // Create read-only tx's and issue a read.
                CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture1 = txChain.newReadOnlyTransaction().read(TestModel.TEST_PATH);
                CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture2 = txChain.newReadOnlyTransaction().read(TestModel.TEST_PATH);
                // Create another write tx and issue the write.
                DOMStoreWriteTransaction writeTx2 = txChain.newWriteOnlyTransaction();
                writeTx2.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
                // Ensure the reads succeed.
                assertEquals("isPresent", true, readFuture1.checkedGet(5, TimeUnit.SECONDS).isPresent());
                assertEquals("isPresent", true, readFuture2.checkedGet(5, TimeUnit.SECONDS).isPresent());
                // Ensure the writes succeed.
                DOMStoreThreePhaseCommitCohort cohort2 = writeTx2.ready();
                doCommit(cohort1);
                doCommit(cohort2);
                assertEquals("isPresent", true, txChain.newReadOnlyTransaction().read(TestModel.OUTER_LIST_PATH).checkedGet(5, TimeUnit.SECONDS).isPresent());
            }
        }
    };
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) Optional(com.google.common.base.Optional) DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) DOMStoreTransactionChain(org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 12 with DOMStoreTransactionChain

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

the class DistributedDataStoreIntegrationTest method testTransactionChainWithMultipleShards.

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

        {
            try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testTransactionChainWithMultipleShards", "cars-1", "people-1")) {
                final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
                DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
                assertNotNull("newWriteOnlyTransaction returned null", writeTx);
                writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
                writeTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
                writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
                writeTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
                final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
                final DOMStoreReadWriteTransaction readWriteTx = txChain.newReadWriteTransaction();
                final MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
                final YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
                readWriteTx.write(carPath, car);
                final MapEntryNode person = PeopleModel.newPersonEntry("jack");
                final YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
                readWriteTx.merge(personPath, person);
                Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(carPath).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", true, optional.isPresent());
                assertEquals("Data node", car, optional.get());
                optional = readWriteTx.read(personPath).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", true, optional.isPresent());
                assertEquals("Data node", person, optional.get());
                final DOMStoreThreePhaseCommitCohort cohort2 = readWriteTx.ready();
                writeTx = txChain.newWriteOnlyTransaction();
                writeTx.delete(carPath);
                final DOMStoreThreePhaseCommitCohort cohort3 = writeTx.ready();
                final ListenableFuture<Boolean> canCommit1 = cohort1.canCommit();
                final ListenableFuture<Boolean> canCommit2 = cohort2.canCommit();
                doCommit(canCommit1, cohort1);
                doCommit(canCommit2, cohort2);
                doCommit(cohort3);
                txChain.close();
                final DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
                optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", false, optional.isPresent());
                optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", true, optional.isPresent());
                assertEquals("Data node", person, optional.get());
            }
        }
    };
}
Also used : DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) DOMStoreTransactionChain(org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 13 with DOMStoreTransactionChain

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

the class LegacyDOMDataBrokerAdapterTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    ConcurrentDOMDataBroker backendBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL, mockOperStore, org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION, mockConfigStore), MoreExecutors.newDirectExecutorService());
    adapter = new LegacyDOMDataBrokerAdapter(backendBroker);
    doReturn(Futures.immediateFuture(Boolean.TRUE)).when(mockCommitCohort).canCommit();
    doReturn(Futures.immediateFuture(null)).when(mockCommitCohort).preCommit();
    doReturn(Futures.immediateFuture(null)).when(mockCommitCohort).commit();
    doReturn(Futures.immediateFuture(null)).when(mockCommitCohort).abort();
    dataNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    doReturn(mockWriteTx).when(mockConfigStore).newWriteOnlyTransaction();
    doNothing().when(mockWriteTx).write(TestModel.TEST_PATH, dataNode);
    doNothing().when(mockWriteTx).merge(TestModel.TEST_PATH, dataNode);
    doNothing().when(mockWriteTx).delete(TestModel.TEST_PATH);
    doNothing().when(mockWriteTx).close();
    doReturn(mockCommitCohort).when(mockWriteTx).ready();
    doReturn(mockReadTx).when(mockConfigStore).newReadOnlyTransaction();
    doReturn(Futures.immediateCheckedFuture(Optional.of(dataNode))).when(mockReadTx).read(TestModel.TEST_PATH);
    doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(mockReadTx).exists(TestModel.TEST_PATH);
    doReturn(mockReadWriteTx).when(mockConfigStore).newReadWriteTransaction();
    doNothing().when(mockReadWriteTx).write(TestModel.TEST_PATH, dataNode);
    doReturn(mockCommitCohort).when(mockReadWriteTx).ready();
    doReturn(Futures.immediateCheckedFuture(Optional.of(dataNode))).when(mockReadWriteTx).read(TestModel.TEST_PATH);
    DOMStoreTransactionChain mockTxChain = mock(DOMStoreTransactionChain.class);
    doReturn(mockReadTx).when(mockTxChain).newReadOnlyTransaction();
    doReturn(mockWriteTx).when(mockTxChain).newWriteOnlyTransaction();
    doReturn(mockReadWriteTx).when(mockTxChain).newReadWriteTransaction();
    doReturn(mockTxChain).when(mockConfigStore).createTransactionChain();
    doReturn(mock(DOMStoreTransactionChain.class)).when(mockOperStore).createTransactionChain();
}
Also used : ConcurrentDOMDataBroker(org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker) DOMStoreTransactionChain(org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain) Before(org.junit.Before)

Aggregations

DOMStoreTransactionChain (org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain)13 Test (org.junit.Test)11 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)7 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)6 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)6 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)5 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)3 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)2 Optional (com.google.common.base.Optional)1 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Before (org.junit.Before)1 RequestTimeoutException (org.opendaylight.controller.cluster.access.client.RequestTimeoutException)1 ConcurrentDOMDataBroker (org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker)1 NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)1 NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)1