Search in sources :

Example 31 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier 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 32 with YangInstanceIdentifier

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

the class DistributedDataStoreRemotingIntegrationTest method testWriteTransactionWithMultipleShards.

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

Example 33 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier 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 34 with YangInstanceIdentifier

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

the class DataChangeListenerRegistrationProxyTest method testSuccessfulRegistrationForClusteredListener.

@Test(timeout = 10000)
public void testSuccessfulRegistrationForClusteredListener() {
    new TestKit(getSystem()) {

        {
            ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
            AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> mockClusteredListener = Mockito.mock(ClusteredDOMDataChangeListener.class);
            final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy("shard-1", actorContext, mockClusteredListener);
            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
            final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
            new Thread(() -> proxy.init(path, scope)).start();
            FiniteDuration timeout = duration("5 seconds");
            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
            reply(new LocalShardFound(getRef()));
            RegisterChangeListener registerMsg = expectMsgClass(timeout, RegisterChangeListener.class);
            Assert.assertEquals("getPath", path, registerMsg.getPath());
            Assert.assertEquals("getScope", scope, registerMsg.getScope());
            Assert.assertEquals("isRegisterOnAllInstances", true, registerMsg.isRegisterOnAllInstances());
            reply(new RegisterDataTreeNotificationListenerReply(getRef()));
            for (int i = 0; i < 20 * 5 && proxy.getListenerRegistrationActor() == null; i++) {
                Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
            }
            Assert.assertEquals("getListenerRegistrationActor", getSystem().actorSelection(getRef().path()), proxy.getListenerRegistrationActor());
            watch(proxy.getDataChangeListenerActor());
            proxy.close();
            // The listener registration actor should get a Close message
            expectMsgClass(timeout, CloseDataTreeNotificationListenerRegistration.class);
            // The DataChangeListener actor should be terminated
            expectMsgClass(timeout, Terminated.class);
            proxy.close();
            expectNoMsg();
        }
    };
}
Also used : DataChangeScope(org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope) RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) LocalShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardFound) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) RegisterChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener) FiniteDuration(scala.concurrent.duration.FiniteDuration) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 35 with YangInstanceIdentifier

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

the class DataChangeListenerRegistrationProxyTest method testLocalShardNotInitialized.

@Test(timeout = 10000)
public void testLocalShardNotInitialized() {
    new TestKit(getSystem()) {

        {
            ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
            final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy("shard-1", actorContext, mockListener);
            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
            final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
            new Thread(() -> proxy.init(path, scope)).start();
            FiniteDuration timeout = duration("5 seconds");
            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
            reply(new NotInitializedException("not initialized"));
            expectNoMsg(duration("1 seconds"));
            proxy.close();
        }
    };
}
Also used : DataChangeScope(org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) FiniteDuration(scala.concurrent.duration.FiniteDuration) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) Test(org.junit.Test)

Aggregations

YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)187 Test (org.junit.Test)111 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)34 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)21 ActorRef (akka.actor.ActorRef)19 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)19 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)15 TestActorRef (akka.testkit.TestActorRef)14 TestKit (akka.testkit.javadsl.TestKit)13 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)12 ArrayList (java.util.ArrayList)11 RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)10 DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)10 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)10 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)10 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)9 RegisterChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener)9 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)9 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)9 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9