Search in sources :

Example 6 with DOMStoreTransactionChain

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

the class DistributedDataStoreRemotingIntegrationTest method testTransactionChainWithSingleShard.

@Test
public void testTransactionChainWithSingleShard() throws Exception {
    initDatastoresWithCars("testTransactionChainWithSingleShard");
    final DOMStoreTransactionChain txChain = followerDistributedDataStore.createTransactionChain();
    // Add the top-level cars container with write-only.
    final DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
    assertNotNull("newWriteOnlyTransaction returned null", writeTx);
    writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
    final DOMStoreThreePhaseCommitCohort writeTxReady = writeTx.ready();
    // Verify the top-level cars container with read-only.
    verifyNode(txChain.newReadOnlyTransaction(), CarsModel.BASE_PATH, CarsModel.emptyContainer());
    // Perform car operations with read-write.
    final DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
    verifyNode(rwTx, CarsModel.BASE_PATH, CarsModel.emptyContainer());
    rwTx.merge(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
    final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
    final YangInstanceIdentifier car1Path = CarsModel.newCarPath("optima");
    rwTx.write(car1Path, car1);
    verifyExists(rwTx, car1Path);
    verifyCars(rwTx, car1);
    final MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(25000));
    rwTx.merge(CarsModel.newCarPath("sportage"), car2);
    rwTx.delete(car1Path);
    followerTestKit.doCommit(writeTxReady);
    followerTestKit.doCommit(rwTx.ready());
    txChain.close();
    verifyCars(followerDistributedDataStore.newReadOnlyTransaction(), car2);
}
Also used : DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) 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) Test(org.junit.Test)

Example 7 with DOMStoreTransactionChain

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

the class DOMBrokerTransactionChain method close.

@Override
public void close() {
    final boolean success = STATE_UPDATER.compareAndSet(this, State.RUNNING, State.CLOSING);
    if (!success) {
        LOG.debug("Chain {} is no longer running", this);
        return;
    }
    super.close();
    for (DOMStoreTransactionChain subChain : getTxFactories().values()) {
        subChain.close();
    }
    if (counter == 0) {
        finishClose();
    }
}
Also used : DOMStoreTransactionChain(org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain)

Example 8 with DOMStoreTransactionChain

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

the class ClientBackedDataStoreTest method testCreateTransactionChain.

@Test
public void testCreateTransactionChain() throws Exception {
    try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(actorContext, UNKNOWN_ID, clientActor)) {
        final DOMStoreTransactionChain txChain = clientBackedDataStore.createTransactionChain();
        Assert.assertNotNull(txChain);
        Mockito.verify(clientActor, Mockito.times(1)).createLocalHistory();
    }
}
Also used : DOMStoreTransactionChain(org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain) Test(org.junit.Test)

Example 9 with DOMStoreTransactionChain

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

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

the class DistributedDataStoreIntegrationTest method testCreateChainedTransactionAfterEmptyTxReadied.

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

        {
            try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testCreateChainedTransactionAfterEmptyTxReadied", "test-1")) {
                final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
                final DOMStoreReadWriteTransaction rwTx1 = txChain.newReadWriteTransaction();
                rwTx1.ready();
                final DOMStoreReadWriteTransaction rwTx2 = txChain.newReadWriteTransaction();
                final Optional<NormalizedNode<?, ?>> optional = rwTx2.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", false, optional.isPresent());
                txChain.close();
            }
        }
    };
}
Also used : DOMStoreTransactionChain(org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

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