Search in sources :

Example 11 with DOMDataTreeProducer

use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducer in project controller by opendaylight.

the class DistributedShardedDOMDataTreeTest method testSingleNodeWritesAndRead.

@Test
public void testSingleNodeWritesAndRead() throws Exception {
    initEmptyDatastores();
    final DistributedShardRegistration shardRegistration = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
    final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
    final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(true);
    final DOMDataTreeWriteCursor cursor = tx.createCursor(TEST_ID);
    Assert.assertNotNull(cursor);
    final YangInstanceIdentifier nameId = YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(TestModel.NAME_QNAME).build();
    final LeafNode<String> valueToCheck = ImmutableLeafNodeBuilder.<String>create().withNodeIdentifier(new NodeIdentifier(TestModel.NAME_QNAME)).withValue("Test Value").build();
    LOG.debug("Writing data {} at {}, cursor {}", nameId.getLastPathArgument(), valueToCheck, cursor);
    cursor.write(nameId.getLastPathArgument(), valueToCheck);
    cursor.close();
    LOG.debug("Got to pre submit");
    tx.submit().checkedGet();
    final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
    doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
    leaderShardFactory.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID), true, Collections.emptyList());
    verify(mockedDataTreeListener, timeout(1000).times(1)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture());
    final List<Collection<DataTreeCandidate>> capturedValue = captorForChanges.getAllValues();
    final java.util.Optional<NormalizedNode<?, ?>> dataAfter = capturedValue.get(0).iterator().next().getRootNode().getDataAfter();
    final NormalizedNode<?, ?> expected = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(valueToCheck).build();
    assertEquals(expected, dataAfter.get());
    verifyNoMoreInteractions(mockedDataTreeListener);
    final String shardName = ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier());
    LOG.debug("Creating distributed datastore client for shard {}", shardName);
    final ActorContext actorContext = leaderDistributedDataStore.getActorContext();
    final Props distributedDataStoreClientProps = SimpleDataStoreClientActor.props(actorContext.getCurrentMemberName(), "Shard-" + shardName, actorContext, shardName);
    final ActorRef clientActor = leaderSystem.actorOf(distributedDataStoreClientProps);
    final DataStoreClient distributedDataStoreClient = SimpleDataStoreClientActor.getDistributedDataStoreClient(clientActor, 30, TimeUnit.SECONDS);
    final ClientLocalHistory localHistory = distributedDataStoreClient.createLocalHistory();
    final ClientTransaction tx2 = localHistory.createTransaction();
    final CheckedFuture<Optional<NormalizedNode<?, ?>>, org.opendaylight.mdsal.common.api.ReadFailedException> read = tx2.read(YangInstanceIdentifier.EMPTY);
    final Optional<NormalizedNode<?, ?>> optional = read.checkedGet();
    tx2.abort();
    localHistory.close();
    shardRegistration.close().toCompletableFuture().get();
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) ActorRef(akka.actor.ActorRef) AddressFromURIString(akka.actor.AddressFromURIString) Props(akka.actor.Props) DataStoreClient(org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Optional(com.google.common.base.Optional) ClientTransaction(org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction) DOMDataTreeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeListener) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) ClientLocalHistory(org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Collection(java.util.Collection) Matchers.anyCollection(org.mockito.Matchers.anyCollection) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 12 with DOMDataTreeProducer

use of org.opendaylight.mdsal.dom.api.DOMDataTreeProducer in project controller by opendaylight.

the class DistributedShardedDOMDataTreeTest method testCDSDataTreeProducer.

@Test
public void testCDSDataTreeProducer() throws Exception {
    initEmptyDatastores();
    final DistributedShardRegistration reg1 = waitOnAsyncTask(leaderShardFactory.createDistributedShard(TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME)), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
    leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH));
    assertNotNull(findLocalShard(leaderDistributedDataStore.getActorContext(), ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
    final DOMDataTreeIdentifier configRoot = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
    final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(configRoot));
    assertTrue(producer instanceof CDSDataTreeProducer);
    final CDSDataTreeProducer cdsProducer = (CDSDataTreeProducer) producer;
    CDSShardAccess shardAccess = cdsProducer.getShardAccess(TEST_ID);
    assertEquals(shardAccess.getShardIdentifier(), TEST_ID);
    shardAccess = cdsProducer.getShardAccess(INNER_LIST_ID);
    assertEquals(TEST_ID, shardAccess.getShardIdentifier());
    shardAccess = cdsProducer.getShardAccess(configRoot);
    assertEquals(configRoot, shardAccess.getShardIdentifier());
    waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
}
Also used : DistributedShardRegistration(org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) CDSShardAccess(org.opendaylight.controller.cluster.dom.api.CDSShardAccess) CDSDataTreeProducer(org.opendaylight.controller.cluster.dom.api.CDSDataTreeProducer) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Aggregations

DOMDataTreeProducer (org.opendaylight.mdsal.dom.api.DOMDataTreeProducer)12 Test (org.junit.Test)8 DOMDataTreeCursorAwareTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction)8 DOMDataTreeWriteCursor (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor)8 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)7 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 DistributedShardRegistration (org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration)6 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)6 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)6 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)5 ActorRef (akka.actor.ActorRef)4 AddressFromURIString (akka.actor.AddressFromURIString)3 DataStoreClient (org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient)3 DOMDataTreeListener (org.opendaylight.mdsal.dom.api.DOMDataTreeListener)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Matchers.anyCollection (org.mockito.Matchers.anyCollection)2 ClientLocalHistory (org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory)2