use of org.opendaylight.controller.cluster.datastore.Shard in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testAddShardReplica.
@Test
public void testAddShardReplica() throws Exception {
String name = "testAddShardReplica";
String moduleShardsConfig = "module-shards-cars-member-1.conf";
MemberNode leaderNode1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).waitForShardLeader("cars").build();
MemberNode newReplicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
leaderNode1.waitForMembersUp("member-2");
doAddShardReplica(newReplicaNode2, "cars", "member-1");
MemberNode newReplicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).build();
leaderNode1.waitForMembersUp("member-3");
newReplicaNode2.waitForMembersUp("member-3");
doAddShardReplica(newReplicaNode3, "cars", "member-1", "member-2");
verifyRaftPeersPresent(newReplicaNode2.configDataStore(), "cars", "member-1", "member-3");
verifyRaftPeersPresent(newReplicaNode2.operDataStore(), "cars", "member-1", "member-3");
// Write data to member-2's config datastore and read/verify via member-3
final NormalizedNode<?, ?> configCarsNode = writeCarsNodeAndVerify(newReplicaNode2.configDataStore(), newReplicaNode3.configDataStore());
// Write data to member-3's oper datastore and read/verify via member-2
writeCarsNodeAndVerify(newReplicaNode3.operDataStore(), newReplicaNode2.operDataStore());
// Verify all data has been replicated. We expect 4 log entries and thus last applied index of 3 -
// 2 ServerConfigurationPayload entries, the transaction payload entry plus a purge payload.
RaftStateVerifier verifier = raftState -> {
assertEquals("Commit index", 3, raftState.getCommitIndex());
assertEquals("Last applied index", 3, raftState.getLastApplied());
};
verifyRaftState(leaderNode1.configDataStore(), "cars", verifier);
verifyRaftState(leaderNode1.operDataStore(), "cars", verifier);
verifyRaftState(newReplicaNode2.configDataStore(), "cars", verifier);
verifyRaftState(newReplicaNode2.operDataStore(), "cars", verifier);
verifyRaftState(newReplicaNode3.configDataStore(), "cars", verifier);
verifyRaftState(newReplicaNode3.operDataStore(), "cars", verifier);
// Restart member-3 and verify the cars config shard is re-instated.
Cluster.get(leaderNode1.kit().getSystem()).down(Cluster.get(newReplicaNode3.kit().getSystem()).selfAddress());
newReplicaNode3.cleanup();
newReplicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).createOperDatastore(false).build();
verifyRaftState(newReplicaNode3.configDataStore(), "cars", verifier);
readCarsNodeAndVerify(newReplicaNode3.configDataStore(), configCarsNode);
}
use of org.opendaylight.controller.cluster.datastore.Shard in project controller by opendaylight.
the class PruningDataTreeModificationTest method testWriteRootNodeWithInvalidChild.
@Test
public void testWriteRootNodeWithInvalidChild() throws Exception {
final Shard mockShard = Mockito.mock(Shard.class);
ShardDataTree shardDataTree = new ShardDataTree(mockShard, SCHEMA_CONTEXT, TreeType.CONFIGURATION);
NormalizedNode<?, ?> root = shardDataTree.readNode(YangInstanceIdentifier.EMPTY).get();
NormalizedNode<?, ?> normalizedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(root.getNodeType())).withChild(ImmutableNodes.containerNode(AUG_CONTAINER)).build();
pruningDataTreeModification.write(YangInstanceIdentifier.EMPTY, normalizedNode);
dataTree.commit(getCandidate());
Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY);
assertEquals("Root present", true, actual.isPresent());
assertEquals("Root node", root, actual.get());
}
use of org.opendaylight.controller.cluster.datastore.Shard in project controller by opendaylight.
the class DistributedEntityOwnershipServiceTest method testGetOwnershipState.
@Test
public void testGetOwnershipState() throws Exception {
DistributedEntityOwnershipService service = spy(DistributedEntityOwnershipService.start(dataStore.getActorContext(), EntityOwnerSelectionStrategyConfig.newBuilder().build()));
final Shard mockShard = Mockito.mock(Shard.class);
ShardDataTree shardDataTree = new ShardDataTree(mockShard, SchemaContextHelper.entityOwners(), TreeType.OPERATIONAL);
when(service.getLocalEntityOwnershipShardDataTree()).thenReturn(shardDataTree.getDataTree());
DOMEntity entity1 = new DOMEntity(ENTITY_TYPE, "one");
writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, entity1.getIdentifier(), "member-1"), shardDataTree);
writeNode(ENTITY_OWNERS_PATH, entityOwnersWithEntityTypeEntry(entityTypeEntryWithEntityEntry(entity1.getType(), entityEntryWithOwner(entity1.getIdentifier(), "member-1"))), shardDataTree);
verifyGetOwnershipState(service, entity1, EntityOwnershipState.IS_OWNER);
writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, entity1.getIdentifier(), "member-2"), shardDataTree);
writeNode(entityPath(entity1.getType(), entity1.getIdentifier()), entityEntryWithOwner(entity1.getIdentifier(), "member-2"), shardDataTree);
verifyGetOwnershipState(service, entity1, EntityOwnershipState.OWNED_BY_OTHER);
writeNode(entityPath(entity1.getType(), entity1.getIdentifier()), entityEntryWithOwner(entity1.getIdentifier(), ""), shardDataTree);
verifyGetOwnershipState(service, entity1, EntityOwnershipState.NO_OWNER);
DOMEntity entity2 = new DOMEntity(ENTITY_TYPE, "two");
Optional<EntityOwnershipState> state = service.getOwnershipState(entity2);
assertEquals("getOwnershipState present", false, state.isPresent());
writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, entity2.getIdentifier(), "member-1"), shardDataTree);
writeNode(entityPath(entity2.getType(), entity2.getIdentifier()), ImmutableNodes.mapEntry(ENTITY_QNAME, ENTITY_ID_QNAME, entity2.getIdentifier()), shardDataTree);
verifyGetOwnershipState(service, entity2, EntityOwnershipState.NO_OWNER);
deleteNode(candidatePath(entityPath(entity2.getType(), entity2.getIdentifier()), "member-1"), shardDataTree);
Optional<EntityOwnershipState> state2 = service.getOwnershipState(entity2);
assertEquals("getOwnershipState present", false, state2.isPresent());
service.close();
}
Aggregations