use of org.opendaylight.controller.cluster.notifications.LeaderStateChanged in project controller by opendaylight.
the class RoleChangeListenerActorTest method testOnDataTreeChanged.
@Test
public void testOnDataTreeChanged() {
final LeaderLocationListener listener = mock(LeaderLocationListener.class);
doNothing().when(listener).onLeaderLocationChanged(any());
final Props props = RoleChangeListenerActor.props(getSystem().deadLetters(), listener);
final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedChanged");
subject.tell(new LeaderStateChanged("member-1", null, (short) 0), noSender());
verify(listener, timeout(5000)).onLeaderLocationChanged(eq(LeaderLocation.UNKNOWN));
subject.tell(new LeaderStateChanged("member-1", "member-1", (short) 0), noSender());
verify(listener, timeout(5000)).onLeaderLocationChanged(eq(LeaderLocation.LOCAL));
subject.tell(new LeaderStateChanged("member-1", "member-2", (short) 0), noSender());
verify(listener, timeout(5000)).onLeaderLocationChanged(eq(LeaderLocation.REMOTE));
}
use of org.opendaylight.controller.cluster.notifications.LeaderStateChanged in project controller by opendaylight.
the class NonVotingFollowerIntegrationTest method testFollowerLeaderStateChanges.
@Test
public void testFollowerLeaderStateChanges() {
testLog.info("testFollowerLeaderStateChanges");
ActorRef roleChangeNotifier = factory.createActor(MessageCollectorActor.props(), factory.generateActorId("roleChangeNotifier"));
follower1Builder.roleChangeNotifier(roleChangeNotifier);
setupLeaderAndNonVotingFollower();
((DefaultConfigParamsImpl) follower1Context.getConfigParams()).setElectionTimeoutFactor(2);
((DefaultConfigParamsImpl) follower1Context.getConfigParams()).setHeartBeatInterval(FiniteDuration.apply(100, TimeUnit.MILLISECONDS));
MessageCollectorActor.clearMessages(roleChangeNotifier);
follower1Actor.tell(ElectionTimeout.INSTANCE, ActorRef.noSender());
followerInstance.startDropMessages(AppendEntries.class);
LeaderStateChanged leaderStateChanged = MessageCollectorActor.expectFirstMatching(roleChangeNotifier, LeaderStateChanged.class);
assertEquals("getLeaderId", null, leaderStateChanged.getLeaderId());
MessageCollectorActor.clearMessages(roleChangeNotifier);
followerInstance.stopDropMessages(AppendEntries.class);
leaderStateChanged = MessageCollectorActor.expectFirstMatching(roleChangeNotifier, LeaderStateChanged.class);
assertEquals("getLeaderId", leaderId, leaderStateChanged.getLeaderId());
}
use of org.opendaylight.controller.cluster.notifications.LeaderStateChanged in project controller by opendaylight.
the class RaftActorTest method testLeaderTransitioning.
@Test
public void testLeaderTransitioning() throws Exception {
TEST_LOG.info("testLeaderTransitioning starting");
ActorRef notifierActor = factory.createActor(MessageCollectorActor.props());
DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
config.setCustomRaftPolicyImplementationClass(DisableElectionsRaftPolicy.class.getName());
String persistenceId = factory.generateActorId("test-actor-");
TestActorRef<MockRaftActor> raftActorRef = factory.createTestActor(MockRaftActor.builder().id(persistenceId).config(config).roleChangeNotifier(notifierActor).props().withDispatcher(Dispatchers.DefaultDispatcherId()), persistenceId);
MockRaftActor mockRaftActor = raftActorRef.underlyingActor();
mockRaftActor.waitForInitializeBehaviorComplete();
raftActorRef.tell(new AppendEntries(1L, "leader", 0L, 1L, Collections.<ReplicatedLogEntry>emptyList(), 0L, -1L, (short) 1), ActorRef.noSender());
LeaderStateChanged leaderStateChange = MessageCollectorActor.expectFirstMatching(notifierActor, LeaderStateChanged.class);
assertEquals("getLeaderId", "leader", leaderStateChange.getLeaderId());
MessageCollectorActor.clearMessages(notifierActor);
raftActorRef.tell(new LeaderTransitioning("leader"), ActorRef.noSender());
leaderStateChange = MessageCollectorActor.expectFirstMatching(notifierActor, LeaderStateChanged.class);
assertEquals("getMemberId", persistenceId, leaderStateChange.getMemberId());
assertEquals("getLeaderId", null, leaderStateChange.getLeaderId());
TEST_LOG.info("testLeaderTransitioning ending");
}
use of org.opendaylight.controller.cluster.notifications.LeaderStateChanged in project controller by opendaylight.
the class RaftActorTest method testRaftRoleChangeNotifierWhenRaftActorHasNoPeers.
@Test
public void testRaftRoleChangeNotifierWhenRaftActorHasNoPeers() throws Exception {
ActorRef notifierActor = factory.createActor(MessageCollectorActor.props());
MessageCollectorActor.waitUntilReady(notifierActor);
DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
long heartBeatInterval = 100;
config.setHeartBeatInterval(FiniteDuration.create(heartBeatInterval, TimeUnit.MILLISECONDS));
config.setElectionTimeoutFactor(20);
String persistenceId = factory.generateActorId("notifier-");
final TestActorRef<MockRaftActor> raftActorRef = factory.createTestActor(MockRaftActor.builder().id(persistenceId).config(config).roleChangeNotifier(notifierActor).dataPersistenceProvider(createProvider()).props().withDispatcher(Dispatchers.DefaultDispatcherId()), persistenceId);
List<RoleChanged> matches = MessageCollectorActor.expectMatching(notifierActor, RoleChanged.class, 3);
// check if the notifier got a role change from null to Follower
RoleChanged raftRoleChanged = matches.get(0);
assertEquals(persistenceId, raftRoleChanged.getMemberId());
assertNull(raftRoleChanged.getOldRole());
assertEquals(RaftState.Follower.name(), raftRoleChanged.getNewRole());
// check if the notifier got a role change from Follower to Candidate
raftRoleChanged = matches.get(1);
assertEquals(persistenceId, raftRoleChanged.getMemberId());
assertEquals(RaftState.Follower.name(), raftRoleChanged.getOldRole());
assertEquals(RaftState.Candidate.name(), raftRoleChanged.getNewRole());
// check if the notifier got a role change from Candidate to Leader
raftRoleChanged = matches.get(2);
assertEquals(persistenceId, raftRoleChanged.getMemberId());
assertEquals(RaftState.Candidate.name(), raftRoleChanged.getOldRole());
assertEquals(RaftState.Leader.name(), raftRoleChanged.getNewRole());
LeaderStateChanged leaderStateChange = MessageCollectorActor.expectFirstMatching(notifierActor, LeaderStateChanged.class);
assertEquals(raftRoleChanged.getMemberId(), leaderStateChange.getLeaderId());
assertEquals(MockRaftActor.PAYLOAD_VERSION, leaderStateChange.getLeaderPayloadVersion());
MessageCollectorActor.clearMessages(notifierActor);
MockRaftActor raftActor = raftActorRef.underlyingActor();
final String newLeaderId = "new-leader";
final short newLeaderVersion = 6;
Follower follower = new Follower(raftActor.getRaftActorContext()) {
@Override
public RaftActorBehavior handleMessage(final ActorRef sender, final Object message) {
setLeaderId(newLeaderId);
setLeaderPayloadVersion(newLeaderVersion);
return this;
}
};
raftActor.newBehavior(follower);
leaderStateChange = MessageCollectorActor.expectFirstMatching(notifierActor, LeaderStateChanged.class);
assertEquals(persistenceId, leaderStateChange.getMemberId());
assertEquals(null, leaderStateChange.getLeaderId());
raftRoleChanged = MessageCollectorActor.expectFirstMatching(notifierActor, RoleChanged.class);
assertEquals(RaftState.Leader.name(), raftRoleChanged.getOldRole());
assertEquals(RaftState.Follower.name(), raftRoleChanged.getNewRole());
MessageCollectorActor.clearMessages(notifierActor);
raftActor.handleCommand("any");
leaderStateChange = MessageCollectorActor.expectFirstMatching(notifierActor, LeaderStateChanged.class);
assertEquals(persistenceId, leaderStateChange.getMemberId());
assertEquals(newLeaderId, leaderStateChange.getLeaderId());
assertEquals(newLeaderVersion, leaderStateChange.getLeaderPayloadVersion());
MessageCollectorActor.clearMessages(notifierActor);
raftActor.handleCommand("any");
Uninterruptibles.sleepUninterruptibly(505, TimeUnit.MILLISECONDS);
leaderStateChange = MessageCollectorActor.getFirstMatching(notifierActor, LeaderStateChanged.class);
assertNull(leaderStateChange);
}
use of org.opendaylight.controller.cluster.notifications.LeaderStateChanged in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindPrimaryForNonLocalLeaderShardBeforeMemberUp.
@Test
public void testOnReceiveFindPrimaryForNonLocalLeaderShardBeforeMemberUp() throws Exception {
LOG.info("testOnReceiveFindPrimaryForNonLocalLeaderShardBeforeMemberUp 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;
String memberId1 = "member-1-shard-default-" + shardMrgIDSuffix;
shardManager.tell(new RoleChangeNotification(memberId1, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor);
shardManager.tell(new LeaderStateChanged(memberId1, memberId2, DataStoreVersions.CURRENT_VERSION), mockShardActor);
shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, false), getRef());
expectMsgClass(duration("5 seconds"), NoShardLeaderException.class);
}
};
LOG.info("testOnReceiveFindPrimaryForNonLocalLeaderShardBeforeMemberUp ending");
}
Aggregations