Search in sources :

Example 6 with MapEntryNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.

the class DistributedDataStoreIntegrationTest method testWriteTransactionWithMultipleShards.

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

        {
            try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
                DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
                assertNotNull("newWriteOnlyTransaction returned null", writeTx);
                writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
                writeTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
                doCommit(writeTx.ready());
                writeTx = dataStore.newWriteOnlyTransaction();
                writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
                writeTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
                doCommit(writeTx.ready());
                writeTx = dataStore.newWriteOnlyTransaction();
                final MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
                final YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
                writeTx.write(carPath, car);
                final MapEntryNode person = PeopleModel.newPersonEntry("jack");
                final YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
                writeTx.write(personPath, person);
                doCommit(writeTx.ready());
                // Verify the data in the store
                final DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
                Optional<NormalizedNode<?, ?>> 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 : DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) 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 MapEntryNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode 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 8 with MapEntryNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode in project controller by opendaylight.

the class DistributedDataStoreRemotingIntegrationTest method testForwardedReadyTransactionForwardedToLeader.

@SuppressWarnings("unchecked")
@Test
public void testForwardedReadyTransactionForwardedToLeader() throws Exception {
    initDatastoresWithCars("testForwardedReadyTransactionForwardedToLeader");
    followerTestKit.waitUntilLeader(followerDistributedDataStore.getActorContext(), "cars");
    final Optional<ActorRef> carsFollowerShard = followerDistributedDataStore.getActorContext().findLocalShard("cars");
    assertEquals("Cars follower shard found", true, carsFollowerShard.isPresent());
    carsFollowerShard.get().tell(GetShardDataTree.INSTANCE, followerTestKit.getRef());
    final DataTree dataTree = followerTestKit.expectMsgClass(DataTree.class);
    // Send a tx with immediate commit.
    DataTreeModification modification = dataTree.takeSnapshot().newModification();
    new WriteModification(CarsModel.BASE_PATH, CarsModel.emptyContainer()).apply(modification);
    new MergeModification(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()).apply(modification);
    final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
    new WriteModification(CarsModel.newCarPath("optima"), car1).apply(modification);
    ForwardedReadyTransaction forwardedReady = new ForwardedReadyTransaction(tx1, DataStoreVersions.CURRENT_VERSION, new ReadWriteShardDataTreeTransaction(Mockito.mock(ShardDataTreeTransactionParent.class), tx1, modification), true);
    carsFollowerShard.get().tell(forwardedReady, followerTestKit.getRef());
    Object resp = followerTestKit.expectMsgClass(Object.class);
    if (resp instanceof akka.actor.Status.Failure) {
        throw new AssertionError("Unexpected failure response", ((akka.actor.Status.Failure) resp).cause());
    }
    assertEquals("Response type", CommitTransactionReply.class, resp.getClass());
    verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car1);
    // Send another tx without immediate commit.
    modification = dataTree.takeSnapshot().newModification();
    MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000));
    new WriteModification(CarsModel.newCarPath("sportage"), car2).apply(modification);
    forwardedReady = new ForwardedReadyTransaction(tx2, DataStoreVersions.CURRENT_VERSION, new ReadWriteShardDataTreeTransaction(Mockito.mock(ShardDataTreeTransactionParent.class), tx2, modification), false);
    carsFollowerShard.get().tell(forwardedReady, followerTestKit.getRef());
    resp = followerTestKit.expectMsgClass(Object.class);
    if (resp instanceof akka.actor.Status.Failure) {
        throw new AssertionError("Unexpected failure response", ((akka.actor.Status.Failure) resp).cause());
    }
    assertEquals("Response type", ReadyTransactionReply.class, resp.getClass());
    ActorSelection txActor = leaderDistributedDataStore.getActorContext().actorSelection(((ReadyTransactionReply) resp).getCohortPath());
    final Supplier<Short> versionSupplier = Mockito.mock(Supplier.class);
    Mockito.doReturn(DataStoreVersions.CURRENT_VERSION).when(versionSupplier).get();
    final ThreePhaseCommitCohortProxy cohort = new ThreePhaseCommitCohortProxy(leaderDistributedDataStore.getActorContext(), Arrays.asList(new ThreePhaseCommitCohortProxy.CohortInfo(Futures.successful(txActor), versionSupplier)), tx2);
    cohort.canCommit().get(5, TimeUnit.SECONDS);
    cohort.preCommit().get(5, TimeUnit.SECONDS);
    cohort.commit().get(5, TimeUnit.SECONDS);
    verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car1, car2);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) ActorRef(akka.actor.ActorRef) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) ActorSelection(akka.actor.ActorSelection) GetShardDataTree(org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ForwardedReadyTransaction(org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction) Test(org.junit.Test)

Example 9 with MapEntryNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode 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 10 with MapEntryNode

use of org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode 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

MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)95 Test (org.junit.Test)55 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)50 ArrayList (java.util.ArrayList)39 Flowspec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.Flowspec)34 FlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.FlowspecBuilder)34 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)29 NumericOperand (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.NumericOperand)20 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)17 DestinationFlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.ipv4.DestinationFlowspecBuilder)12 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)11 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)10 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)9 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)7 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)6 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)6 BitmaskOperand (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.BitmaskOperand)6 BigInteger (java.math.BigInteger)5 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)5