Search in sources :

Example 1 with DistributedDataStore

use of org.opendaylight.controller.cluster.datastore.DistributedDataStore in project controller by opendaylight.

the class ConcurrentDOMDataBrokerTest method testExtensions.

@Test
public void testExtensions() {
    DistributedDataStore mockConfigStore = mock(DistributedDataStore.class);
    DistributedDataStore mockOperStore = mock(DistributedDataStore.class);
    try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, mockOperStore, LogicalDatastoreType.CONFIGURATION, mockConfigStore), futureExecutor)) {
        Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> supportedExtensions = dataBroker.getSupportedExtensions();
        assertNotNull(supportedExtensions.get(DOMDataTreeChangeService.class));
        DOMDataTreeCommitCohortRegistry cohortRegistry = (DOMDataTreeCommitCohortRegistry) supportedExtensions.get(DOMDataTreeCommitCohortRegistry.class);
        assertNotNull(cohortRegistry);
        DOMDataTreeCommitCohort mockCohort = mock(DOMDataTreeCommitCohort.class);
        DOMDataTreeIdentifier path = new DOMDataTreeIdentifier(org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY);
        cohortRegistry.registerCommitCohort(path, mockCohort);
        verify(mockConfigStore).registerCommitCohort(path, mockCohort);
    }
}
Also used : DOMDataTreeChangeService(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService) DistributedDataStore(org.opendaylight.controller.cluster.datastore.DistributedDataStore) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) DOMDataBrokerExtension(org.opendaylight.mdsal.dom.api.DOMDataBrokerExtension) DOMDataTreeCommitCohortRegistry(org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohortRegistry) DOMDataTreeCommitCohort(org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort) Test(org.junit.Test)

Example 2 with DistributedDataStore

use of org.opendaylight.controller.cluster.datastore.DistributedDataStore in project controller by opendaylight.

the class DistributedEntityOwnershipServiceTest method setUp.

@Before
public void setUp() {
    DatastoreContext datastoreContext = DatastoreContext.newBuilder().dataStoreName(dataStoreName).shardInitializationTimeout(10, TimeUnit.SECONDS).build();
    Configuration configuration = new ConfigurationImpl(new EmptyModuleShardConfigProvider()) {

        @Override
        public Collection<MemberName> getUniqueMemberNamesForAllShards() {
            return Sets.newHashSet(MemberName.forName("member-1"));
        }
    };
    DatastoreContextFactory mockContextFactory = mock(DatastoreContextFactory.class);
    Mockito.doReturn(datastoreContext).when(mockContextFactory).getBaseDatastoreContext();
    Mockito.doReturn(datastoreContext).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString());
    dataStore = new DistributedDataStore(getSystem(), new MockClusterWrapper(), configuration, mockContextFactory, null);
    dataStore.onGlobalContextUpdated(SchemaContextHelper.entityOwners());
}
Also used : EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) DistributedDataStore(org.opendaylight.controller.cluster.datastore.DistributedDataStore) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) DatastoreContextFactory(org.opendaylight.controller.cluster.datastore.DatastoreContextFactory) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) MockClusterWrapper(org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) Before(org.junit.Before)

Example 3 with DistributedDataStore

use of org.opendaylight.controller.cluster.datastore.DistributedDataStore in project controller by opendaylight.

the class DistributedShardFrontendTest method testClientTransaction.

@Test
public void testClientTransaction() throws Exception {
    final DistributedDataStore distributedDataStore = mock(DistributedDataStore.class);
    final ActorContext context = mock(ActorContext.class);
    doReturn(context).when(distributedDataStore).getActorContext();
    doReturn(SchemaContextHelper.full()).when(context).getSchemaContext();
    final DistributedShardFrontend rootShard = new DistributedShardFrontend(distributedDataStore, client, ROOT);
    try (DOMDataTreeProducer producer = shardedDOMDataTree.createProducer(Collections.singletonList(ROOT))) {
        shardedDOMDataTree.registerDataTreeShard(ROOT, rootShard, producer);
    }
    final DataStoreClient outerListClient = mock(DataStoreClient.class);
    final ClientTransaction outerListClientTransaction = mock(ClientTransaction.class);
    final ClientLocalHistory outerListClientHistory = mock(ClientLocalHistory.class);
    final DOMDataTreeWriteCursor outerListCursor = mock(DOMDataTreeWriteCursor.class);
    doNothing().when(outerListCursor).close();
    doNothing().when(outerListCursor).write(any(), any());
    doNothing().when(outerListCursor).merge(any(), any());
    doNothing().when(outerListCursor).delete(any());
    doReturn(outerListCursor).when(outerListClientTransaction).openCursor();
    doReturn(outerListClientTransaction).when(outerListClient).createTransaction();
    doReturn(outerListClientHistory).when(outerListClient).createLocalHistory();
    doReturn(outerListClientTransaction).when(outerListClientHistory).createTransaction();
    doReturn(commitCohort).when(outerListClientTransaction).ready();
    doNothing().when(outerListClientHistory).close();
    doNothing().when(outerListClient).close();
    final DistributedShardFrontend outerListShard = new DistributedShardFrontend(distributedDataStore, outerListClient, OUTER_LIST_ID);
    try (DOMDataTreeProducer producer = shardedDOMDataTree.createProducer(Collections.singletonList(OUTER_LIST_ID))) {
        shardedDOMDataTree.registerDataTreeShard(OUTER_LIST_ID, outerListShard, producer);
    }
    final DOMDataTreeProducer producer = shardedDOMDataTree.createProducer(Collections.singletonList(ROOT));
    final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(false);
    final DOMDataTreeWriteCursor txCursor = tx.createCursor(ROOT);
    assertNotNull(txCursor);
    txCursor.write(TestModel.TEST_PATH.getLastPathArgument(), createCrossShardContainer());
    // check the lower shard got the correct modification
    verify(outerListCursor, times(2)).write(pathArgumentCaptor.capture(), nodeCaptor.capture());
    final YangInstanceIdentifier.PathArgument expectedYid = new NodeIdentifier(TestModel.ID_QNAME);
    final YangInstanceIdentifier.PathArgument actualIdYid = pathArgumentCaptor.getAllValues().get(0);
    assertEquals(expectedYid, actualIdYid);
    final YangInstanceIdentifier.PathArgument expectedInnerYid = new NodeIdentifier(TestModel.INNER_LIST_QNAME);
    final YangInstanceIdentifier.PathArgument actualInnerListYid = pathArgumentCaptor.getAllValues().get(1);
    assertEquals(expectedInnerYid, actualInnerListYid);
    final LeafNode<Integer> actualIdNode = (LeafNode<Integer>) nodeCaptor.getAllValues().get(0);
    assertEquals(ImmutableNodes.leafNode(TestModel.ID_QNAME, 1), actualIdNode);
    final MapNode actualInnerListNode = (MapNode) nodeCaptor.getAllValues().get(1);
    assertEquals(createInnerMapNode(1), actualInnerListNode);
    txCursor.close();
    tx.submit().checkedGet();
    verify(commitCohort, times(2)).canCommit();
    verify(commitCohort, times(2)).preCommit();
    verify(commitCohort, times(2)).commit();
}
Also used : DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) ClientTransaction(org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataStoreClient(org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) ClientLocalHistory(org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory) DistributedDataStore(org.opendaylight.controller.cluster.datastore.DistributedDataStore) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) DOMDataTreeCursorAwareTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction) Test(org.junit.Test)

Aggregations

DistributedDataStore (org.opendaylight.controller.cluster.datastore.DistributedDataStore)3 Test (org.junit.Test)2 Before (org.junit.Before)1 MemberName (org.opendaylight.controller.cluster.access.concepts.MemberName)1 ClientLocalHistory (org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory)1 ClientTransaction (org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction)1 DataStoreClient (org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient)1 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)1 DatastoreContextFactory (org.opendaylight.controller.cluster.datastore.DatastoreContextFactory)1 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)1 ConfigurationImpl (org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)1 EmptyModuleShardConfigProvider (org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider)1 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)1 MockClusterWrapper (org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper)1 DOMDataBrokerExtension (org.opendaylight.mdsal.dom.api.DOMDataBrokerExtension)1 DOMDataTreeChangeService (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService)1 DOMDataTreeCommitCohort (org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort)1 DOMDataTreeCommitCohortRegistry (org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohortRegistry)1 DOMDataTreeCursorAwareTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction)1 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)1