use of org.opendaylight.controller.cluster.notifications.RoleChangeNotification in project controller by opendaylight.
the class ShardManagerTest method testChangeServersVotingStatusWithNoLeader.
@Test
public void testChangeServersVotingStatusWithNoLeader() 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.NO_LEADER, null)), memberId);
ActorRef shardManager = getSystem().actorOf(newPropsShardMgrWithMockShardActor(respondActor));
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), respondActor);
shardManager.tell(new RoleChangeNotification(memberId, null, RaftState.Follower.name()), respondActor);
shardManager.tell(new ChangeShardMembersVotingStatus("default", ImmutableMap.of("member-2", Boolean.TRUE)), getRef());
MessageCollectorActor.expectFirstMatching(respondActor, ChangeServersVotingStatus.class);
Status.Failure resp = expectMsgClass(duration("5 seconds"), Status.Failure.class);
assertEquals("Failure resposnse", true, resp.cause() instanceof NoShardLeaderException);
}
};
}
use of org.opendaylight.controller.cluster.notifications.RoleChangeNotification in project controller by opendaylight.
the class ShardManagerTest method testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards.
@Test
public void testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards() throws Exception {
LOG.info("testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards starting");
TestShardManager shardManager = newTestShardManager(newShardMgrProps(new MockConfiguration() {
@Override
public List<String> getMemberShardNames(final MemberName memberName) {
return Arrays.asList("default", "astronauts");
}
}));
// Initially will be false
assertEquals(false, shardManager.getMBean().getSyncStatus());
// Make default shard leader
String defaultShardId = "member-1-shard-default-" + shardMrgIDSuffix;
shardManager.onReceiveCommand(new RoleChangeNotification(defaultShardId, RaftState.Follower.name(), RaftState.Leader.name()));
// default = Leader, astronauts is unknown so sync status remains false
assertEquals(false, shardManager.getMBean().getSyncStatus());
// Make astronauts shard leader as well
String astronautsShardId = "member-1-shard-astronauts-" + shardMrgIDSuffix;
shardManager.onReceiveCommand(new RoleChangeNotification(astronautsShardId, RaftState.Follower.name(), RaftState.Leader.name()));
// Now sync status should be true
assertEquals(true, shardManager.getMBean().getSyncStatus());
// Make astronauts a Follower
shardManager.onReceiveCommand(new RoleChangeNotification(astronautsShardId, RaftState.Leader.name(), RaftState.Follower.name()));
// Sync status is not true
assertEquals(false, shardManager.getMBean().getSyncStatus());
// Make the astronauts follower sync status true
shardManager.onReceiveCommand(new FollowerInitialSyncUpStatus(true, astronautsShardId));
// Sync status is now true
assertEquals(true, shardManager.getMBean().getSyncStatus());
LOG.info("testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards ending");
}
use of org.opendaylight.controller.cluster.notifications.RoleChangeNotification in project controller by opendaylight.
the class RoleChangeNotifierTest method testHandleRaftRoleChanged.
@Test
public void testHandleRaftRoleChanged() throws Exception {
new TestKit(getSystem()) {
{
String memberId = "testHandleRegisterRoleChangeListenerWithNotificationSet";
ActorRef listenerActor = getSystem().actorOf(MessageCollectorActor.props());
ActorRef shardActor = getTestActor();
TestActorRef<RoleChangeNotifier> notifierTestActorRef = TestActorRef.create(getSystem(), RoleChangeNotifier.getProps(memberId), memberId);
notifierTestActorRef.tell(new RoleChanged(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), shardActor);
// no notification should be sent as listener has not yet
// registered
assertNull(MessageCollectorActor.getFirstMatching(listenerActor, RoleChangeNotification.class));
// listener registers after role has been changed, ensure we
// sent the latest role change after a reply
notifierTestActorRef.tell(new RegisterRoleChangeListener(), listenerActor);
RegisterRoleChangeListenerReply reply = MessageCollectorActor.getFirstMatching(listenerActor, RegisterRoleChangeListenerReply.class);
assertNotNull(reply);
RoleChangeNotification notification = MessageCollectorActor.getFirstMatching(listenerActor, RoleChangeNotification.class);
assertNotNull(notification);
assertEquals(RaftState.Candidate.name(), notification.getOldRole());
assertEquals(RaftState.Leader.name(), notification.getNewRole());
}
};
}
use of org.opendaylight.controller.cluster.notifications.RoleChangeNotification in project controller by opendaylight.
the class RoleChangeNotifierTest method testHandleRegisterRoleChangeListener.
@Test
public void testHandleRegisterRoleChangeListener() throws Exception {
new TestKit(getSystem()) {
{
String memberId = "testHandleRegisterRoleChangeListener";
ActorRef listenerActor = getSystem().actorOf(MessageCollectorActor.props());
TestActorRef<RoleChangeNotifier> notifierTestActorRef = TestActorRef.create(getSystem(), RoleChangeNotifier.getProps(memberId), memberId);
notifierTestActorRef.tell(new RegisterRoleChangeListener(), listenerActor);
RegisterRoleChangeListenerReply reply = MessageCollectorActor.getFirstMatching(listenerActor, RegisterRoleChangeListenerReply.class);
assertNotNull(reply);
RoleChangeNotification notification = MessageCollectorActor.getFirstMatching(listenerActor, RoleChangeNotification.class);
assertNull(notification);
}
};
}
Aggregations