Search in sources :

Example 6 with DOMStoreReadWriteTransaction

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

the class DistributedDataStoreIntegrationTest method testReadWriteTransactionWithMultipleShards.

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

        {
            try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testReadWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
                DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
                assertNotNull("newReadWriteTransaction returned null", readWriteTx);
                readWriteTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
                readWriteTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
                doCommit(readWriteTx.ready());
                readWriteTx = dataStore.newReadWriteTransaction();
                readWriteTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
                readWriteTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
                doCommit(readWriteTx.ready());
                readWriteTx = dataStore.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.write(personPath, person);
                final Boolean exists = readWriteTx.exists(carPath).checkedGet(5, TimeUnit.SECONDS);
                assertEquals("exists", true, exists);
                Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(carPath).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", true, optional.isPresent());
                assertEquals("Data node", car, optional.get());
                doCommit(readWriteTx.ready());
                // Verify the data in the store
                DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
                optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", true, optional.isPresent());
                assertEquals("Data node", car, optional.get());
                optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", true, optional.isPresent());
                assertEquals("Data node", person, optional.get());
            }
        }
    };
}
Also used : DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 7 with DOMStoreReadWriteTransaction

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

the class DistributedDataStoreRemotingIntegrationTest method testTransactionChainWithMultipleShards.

@Test
public void testTransactionChainWithMultipleShards() throws Exception {
    initDatastoresWithCarsAndPeople("testTransactionChainWithMultipleShards");
    final DOMStoreTransactionChain txChain = followerDistributedDataStore.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());
    followerTestKit.doCommit(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(personPath);
    final DOMStoreThreePhaseCommitCohort cohort3 = writeTx.ready();
    followerTestKit.doCommit(cohort2);
    followerTestKit.doCommit(cohort3);
    txChain.close();
    final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
    verifyCars(readTx, car);
    optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
    assertEquals("isPresent", false, optional.isPresent());
}
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) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 8 with DOMStoreReadWriteTransaction

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

the class DistributedDataStoreRemotingIntegrationTest method testReadWriteMessageSlicing.

@Test
public void testReadWriteMessageSlicing() throws Exception {
    // The slicing is only implemented for tell-based protocol
    Assume.assumeTrue(testParameter.equals(ClientBackedDataStore.class));
    leaderDatastoreContextBuilder.maximumMessageSliceSize(100);
    followerDatastoreContextBuilder.maximumMessageSliceSize(100);
    initDatastoresWithCars("testLargeReadReplySlicing");
    final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
    final NormalizedNode<?, ?> carsNode = CarsModel.create();
    rwTx.write(CarsModel.BASE_PATH, carsNode);
    verifyNode(rwTx, CarsModel.BASE_PATH, carsNode);
}
Also used : ClientBackedDataStore(org.opendaylight.controller.cluster.databroker.ClientBackedDataStore) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) Test(org.junit.Test)

Example 9 with DOMStoreReadWriteTransaction

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

the class DistributedDataStoreRemotingIntegrationTest method testReadWriteTransactionWithMultipleShards.

@Test
public void testReadWriteTransactionWithMultipleShards() throws Exception {
    initDatastoresWithCarsAndPeople("testReadWriteTransactionWithMultipleShards");
    final DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction();
    assertNotNull("newReadWriteTransaction returned null", rwTx);
    final YangInstanceIdentifier carsPath = CarsModel.BASE_PATH;
    final NormalizedNode<?, ?> carsNode = CarsModel.emptyContainer();
    rwTx.write(carsPath, carsNode);
    final YangInstanceIdentifier peoplePath = PeopleModel.BASE_PATH;
    final NormalizedNode<?, ?> peopleNode = PeopleModel.emptyContainer();
    rwTx.write(peoplePath, peopleNode);
    followerTestKit.doCommit(rwTx.ready());
    final DOMStoreReadTransaction readTx = followerDistributedDataStore.newReadOnlyTransaction();
    verifyNode(readTx, carsPath, carsNode);
    verifyNode(readTx, peoplePath, peopleNode);
}
Also used : DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 10 with DOMStoreReadWriteTransaction

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

Aggregations

Test (org.junit.Test)22 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)22 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)11 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)10 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 DOMStoreTransactionChain (org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain)6 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)6 AddressFromURIString (akka.actor.AddressFromURIString)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ExecutionException (java.util.concurrent.ExecutionException)5 RequestTimeoutException (org.opendaylight.controller.cluster.access.client.RequestTimeoutException)5 NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)5 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)5 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)5 DOMStore (org.opendaylight.mdsal.dom.spi.store.DOMStore)4 IOException (java.io.IOException)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)3 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)3