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);
}
}
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());
}
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();
}
Aggregations