use of org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged in project controller by opendaylight.
the class ShardManagerTest method testChangeServersVotingStatus.
@Test
public void testChangeServersVotingStatus() throws Exception {
new TestKit(getSystem()) {
{
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
ActorRef respondActor = actorFactory.createActor(Props.create(MockRespondActor.class, ChangeServersVotingStatus.class, new ServerChangeReply(ServerChangeStatus.OK, null)), memberId);
ActorRef shardManager = getSystem().actorOf(newPropsShardMgrWithMockShardActor(respondActor));
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), respondActor);
shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), getRef());
shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), respondActor);
shardManager.tell(new ChangeShardMembersVotingStatus("default", ImmutableMap.of("member-2", Boolean.TRUE)), getRef());
ChangeServersVotingStatus actualChangeStatusMsg = MessageCollectorActor.expectFirstMatching(respondActor, ChangeServersVotingStatus.class);
assertEquals("ChangeServersVotingStatus map", actualChangeStatusMsg.getServerVotingStatusMap(), ImmutableMap.of(ShardIdentifier.create("default", MemberName.forName("member-2"), shardMrgIDSuffix).toString(), Boolean.TRUE));
expectMsgClass(duration("5 seconds"), Success.class);
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged in project controller by opendaylight.
the class ShardManagerTest method testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable.
@Test
public void testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable() throws Exception {
LOG.info("testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable starting");
String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-256", "member-2")).build());
// Create an ActorSystem, ShardManager and actor for member-256.
final ActorSystem system256 = newActorSystem("Member256");
// 2562 is the tcp port of Member256 in src/test/resources/application.conf.
Cluster.get(system256).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2562"));
final ActorRef mockShardActor256 = newMockShardActor(system256, Shard.DEFAULT_NAME, "member-256");
final PrimaryShardInfoFutureCache primaryShardInfoCache = new PrimaryShardInfoFutureCache();
// ShardManager must be created with shard configuration to let its localShards has shards.
final TestActorRef<TestShardManager> shardManager256 = TestActorRef.create(system256, newTestShardMgrBuilder(mockConfig).shardActor(mockShardActor256).cluster(new ClusterWrapperImpl(system256)).primaryShardInfoCache(primaryShardInfoCache).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
// Create an ActorSystem, ShardManager and actor for member-2 whose name is contained in member-256.
final ActorSystem system2 = newActorSystem("Member2");
// Join member-2 into the cluster of member-256.
Cluster.get(system2).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2562"));
final ActorRef mockShardActor2 = newMockShardActor(system2, Shard.DEFAULT_NAME, "member-2");
final TestActorRef<TestShardManager> shardManager2 = TestActorRef.create(system2, newTestShardMgrBuilder(mockConfig).shardActor(mockShardActor2).cluster(new ClusterWrapperImpl(system2)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
new TestKit(system256) {
{
shardManager256.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager2.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager256.tell(new ActorInitialized(), mockShardActor256);
shardManager2.tell(new ActorInitialized(), mockShardActor2);
String memberId256 = "member-256-shard-default-" + shardMrgIDSuffix;
String memberId2 = "member-2-shard-default-" + shardMrgIDSuffix;
shardManager256.tell(new ShardLeaderStateChanged(memberId256, memberId256, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), mockShardActor256);
shardManager256.tell(new RoleChangeNotification(memberId256, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor256);
shardManager2.tell(new ShardLeaderStateChanged(memberId2, memberId256, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), mockShardActor2);
shardManager2.tell(new RoleChangeNotification(memberId2, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor2);
shardManager256.underlyingActor().waitForMemberUp();
shardManager256.tell(new FindPrimary("default", true), getRef());
LocalPrimaryShardFound found = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
String path = found.getPrimaryPath();
assertTrue("Unexpected primary path " + path + " which must on member-256", path.contains("member-256-shard-default-config"));
PrimaryShardInfo primaryShardInfo = new PrimaryShardInfo(system256.actorSelection(mockShardActor256.path()), DataStoreVersions.CURRENT_VERSION);
primaryShardInfoCache.putSuccessful("default", primaryShardInfo);
// Simulate member-2 become unreachable.
shardManager256.tell(MockClusterWrapper.createUnreachableMember("member-2", "akka://cluster-test@127.0.0.1:2558"), getRef());
shardManager256.underlyingActor().waitForUnreachableMember();
// Make sure leader shard on member-256 is still leader and still in the cache.
shardManager256.tell(new FindPrimary("default", true), getRef());
found = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
path = found.getPrimaryPath();
assertTrue("Unexpected primary path " + path + " which must still not on member-256", path.contains("member-256-shard-default-config"));
Future<PrimaryShardInfo> futurePrimaryShard = primaryShardInfoCache.getIfPresent("default");
futurePrimaryShard.onComplete(new OnComplete<PrimaryShardInfo>() {
@Override
public void onComplete(final Throwable failure, final PrimaryShardInfo futurePrimaryShardInfo) {
if (failure != null) {
assertTrue("Primary shard info is unexpectedly removed from primaryShardInfoCache", false);
} else {
assertEquals("Expected primaryShardInfoCache entry", primaryShardInfo, futurePrimaryShardInfo);
}
}
}, system256.dispatchers().defaultGlobalDispatcher());
}
};
LOG.info("testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable ending");
}
use of org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged in project controller by opendaylight.
the class ShardManagerTest method testRemoveShardReplicaLocal.
@Test
public /**
* Primary is Local.
*/
void testRemoveShardReplicaLocal() throws Exception {
new TestKit(getSystem()) {
{
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
final ActorRef respondActor = actorFactory.createActor(Props.create(MockRespondActor.class, RemoveServer.class, new RemoveServerReply(ServerChangeStatus.OK, null)), memberId);
ActorRef shardManager = getSystem().actorOf(newPropsShardMgrWithMockShardActor(respondActor));
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), respondActor);
shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), getRef());
shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), respondActor);
shardManager.tell(new RemoveShardReplica(Shard.DEFAULT_NAME, MEMBER_1), getRef());
final RemoveServer removeServer = MessageCollectorActor.expectFirstMatching(respondActor, RemoveServer.class);
assertEquals(ShardIdentifier.create("default", MEMBER_1, shardMrgIDSuffix).toString(), removeServer.getServerId());
expectMsgClass(duration("5 seconds"), Success.class);
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindPrimaryForLocalLeaderShard.
@Test
public void testOnReceiveFindPrimaryForLocalLeaderShard() throws Exception {
LOG.info("testOnReceiveFindPrimaryForLocalLeaderShard starting");
new TestKit(getSystem()) {
{
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), mockShardActor);
DataTree mockDataTree = mock(DataTree.class);
shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mockDataTree, DataStoreVersions.CURRENT_VERSION), getRef());
MessageCollectorActor.expectFirstMatching(mockShardActor, RegisterRoleChangeListener.class);
shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor);
shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, false), getRef());
LocalPrimaryShardFound primaryFound = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
assertTrue("Unexpected primary path " + primaryFound.getPrimaryPath(), primaryFound.getPrimaryPath().contains("member-1-shard-default"));
assertSame("getLocalShardDataTree", mockDataTree, primaryFound.getLocalShardDataTree());
}
};
LOG.info("testOnReceiveFindPrimaryForLocalLeaderShard ending");
}
use of org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindPrimaryForNonLocalLeaderShard.
@Test
public void testOnReceiveFindPrimaryForNonLocalLeaderShard() throws Exception {
LOG.info("testOnReceiveFindPrimaryForNonLocalLeaderShard starting");
new TestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), mockShardActor);
String memberId2 = "member-2-shard-default-" + shardMrgIDSuffix;
MockClusterWrapper.sendMemberUp(shardManager, "member-2", getRef().path().toString());
String memberId1 = "member-1-shard-default-" + shardMrgIDSuffix;
shardManager.tell(new RoleChangeNotification(memberId1, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor);
short leaderVersion = DataStoreVersions.CURRENT_VERSION - 1;
shardManager.tell(new ShardLeaderStateChanged(memberId1, memberId2, leaderVersion), mockShardActor);
shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, false), getRef());
RemotePrimaryShardFound primaryFound = expectMsgClass(duration("5 seconds"), RemotePrimaryShardFound.class);
assertTrue("Unexpected primary path " + primaryFound.getPrimaryPath(), primaryFound.getPrimaryPath().contains("member-2-shard-default"));
assertEquals("getPrimaryVersion", leaderVersion, primaryFound.getPrimaryVersion());
}
};
LOG.info("testOnReceiveFindPrimaryForNonLocalLeaderShard ending");
}
Aggregations