use of org.opendaylight.controller.cluster.raft.RaftActorLeadershipTransferCohort in project controller by opendaylight.
the class LeaderTest method testTransferLeadershipWithEmptyLog.
@Test
public void testTransferLeadershipWithEmptyLog() {
logStart("testTransferLeadershipWithEmptyLog");
MockRaftActorContext leaderActorContext = createActorContextWithFollower();
((DefaultConfigParamsImpl) leaderActorContext.getConfigParams()).setHeartBeatInterval(new FiniteDuration(1000, TimeUnit.SECONDS));
leaderActorContext.setReplicatedLog(new MockRaftActorContext.MockReplicatedLogBuilder().build());
leader = new Leader(leaderActorContext);
leaderActorContext.setCurrentBehavior(leader);
// Initial heartbeat
MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
leader.handleMessage(leaderActor, new AppendEntriesReply(FOLLOWER_ID, 1, true, -1, -1, (short) 0));
MessageCollectorActor.clearMessages(followerActor);
RaftActorLeadershipTransferCohort mockTransferCohort = mock(RaftActorLeadershipTransferCohort.class);
doReturn(Optional.absent()).when(mockTransferCohort).getRequestedFollowerId();
leader.transferLeadership(mockTransferCohort);
verify(mockTransferCohort, never()).transferComplete();
MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
leader.handleMessage(leaderActor, new AppendEntriesReply(FOLLOWER_ID, 1, true, -1, -1, (short) 0));
// Expect a final AppendEntries to ensure the follower's lastApplied index is up-to-date
MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
// Leader should force an election timeout
MessageCollectorActor.expectFirstMatching(followerActor, TimeoutNow.class);
verify(mockTransferCohort).transferComplete();
}
use of org.opendaylight.controller.cluster.raft.RaftActorLeadershipTransferCohort in project controller by opendaylight.
the class LeaderTest method testTransferLeadershipWithFollowerInSync.
@Test
public void testTransferLeadershipWithFollowerInSync() {
logStart("testTransferLeadershipWithFollowerInSync");
MockRaftActorContext leaderActorContext = createActorContextWithFollower();
leaderActorContext.setLastApplied(-1);
((DefaultConfigParamsImpl) leaderActorContext.getConfigParams()).setHeartBeatInterval(new FiniteDuration(1000, TimeUnit.SECONDS));
leaderActorContext.setReplicatedLog(new MockRaftActorContext.MockReplicatedLogBuilder().build());
leader = new Leader(leaderActorContext);
leaderActorContext.setCurrentBehavior(leader);
// Initial heartbeat
MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
leader.handleMessage(leaderActor, new AppendEntriesReply(FOLLOWER_ID, 1, true, -1, -1, (short) 0));
MessageCollectorActor.clearMessages(followerActor);
sendReplicate(leaderActorContext, 0);
MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
leader.handleMessage(leaderActor, new AppendEntriesReply(FOLLOWER_ID, 1, true, 0, 1, (short) 0));
MessageCollectorActor.expectFirstMatching(leaderActor, ApplyState.class);
MessageCollectorActor.clearMessages(followerActor);
RaftActorLeadershipTransferCohort mockTransferCohort = mock(RaftActorLeadershipTransferCohort.class);
leader.transferLeadership(mockTransferCohort);
verify(mockTransferCohort, never()).transferComplete();
doReturn(Optional.absent()).when(mockTransferCohort).getRequestedFollowerId();
MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
leader.handleMessage(leaderActor, new AppendEntriesReply(FOLLOWER_ID, 1, true, 0, 1, (short) 0));
// Expect a final AppendEntries to ensure the follower's lastApplied index is up-to-date
MessageCollectorActor.expectMatching(followerActor, AppendEntries.class, 2);
// Leader should force an election timeout
MessageCollectorActor.expectFirstMatching(followerActor, TimeoutNow.class);
verify(mockTransferCohort).transferComplete();
}
use of org.opendaylight.controller.cluster.raft.RaftActorLeadershipTransferCohort in project controller by opendaylight.
the class LeaderTest method testTransferLeadershipWithFollowerInitiallyOutOfSync.
@Test
public void testTransferLeadershipWithFollowerInitiallyOutOfSync() {
logStart("testTransferLeadershipWithFollowerInitiallyOutOfSync");
MockRaftActorContext leaderActorContext = createActorContextWithFollower();
((DefaultConfigParamsImpl) leaderActorContext.getConfigParams()).setHeartBeatInterval(new FiniteDuration(200, TimeUnit.MILLISECONDS));
leader = new Leader(leaderActorContext);
leaderActorContext.setCurrentBehavior(leader);
// Initial heartbeat
MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
MessageCollectorActor.clearMessages(followerActor);
RaftActorLeadershipTransferCohort mockTransferCohort = mock(RaftActorLeadershipTransferCohort.class);
doReturn(Optional.absent()).when(mockTransferCohort).getRequestedFollowerId();
leader.transferLeadership(mockTransferCohort);
verify(mockTransferCohort, never()).transferComplete();
// Sync up the follower.
MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
leader.handleMessage(leaderActor, new AppendEntriesReply(FOLLOWER_ID, 1, true, -1, -1, (short) 0));
MessageCollectorActor.clearMessages(followerActor);
Uninterruptibles.sleepUninterruptibly(leaderActorContext.getConfigParams().getHeartBeatInterval().toMillis() + 1, TimeUnit.MILLISECONDS);
leader.handleMessage(leaderActor, SendHeartBeat.INSTANCE);
MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
leader.handleMessage(leaderActor, new AppendEntriesReply(FOLLOWER_ID, 1, true, 1, 1, (short) 0));
// Leader should force an election timeout
MessageCollectorActor.expectFirstMatching(followerActor, TimeoutNow.class);
verify(mockTransferCohort).transferComplete();
}
use of org.opendaylight.controller.cluster.raft.RaftActorLeadershipTransferCohort in project controller by opendaylight.
the class LeaderTest method testTransferLeadershipWithFollowerSyncTimeout.
@Test
public void testTransferLeadershipWithFollowerSyncTimeout() {
logStart("testTransferLeadershipWithFollowerSyncTimeout");
MockRaftActorContext leaderActorContext = createActorContextWithFollower();
((DefaultConfigParamsImpl) leaderActorContext.getConfigParams()).setHeartBeatInterval(new FiniteDuration(200, TimeUnit.MILLISECONDS));
((DefaultConfigParamsImpl) leaderActorContext.getConfigParams()).setElectionTimeoutFactor(2);
leaderActorContext.setReplicatedLog(new MockRaftActorContext.MockReplicatedLogBuilder().build());
leader = new Leader(leaderActorContext);
leaderActorContext.setCurrentBehavior(leader);
// Initial heartbeat
MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
leader.handleMessage(leaderActor, new AppendEntriesReply(FOLLOWER_ID, 1, true, -1, -1, (short) 0));
MessageCollectorActor.clearMessages(followerActor);
sendReplicate(leaderActorContext, 0);
MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
MessageCollectorActor.clearMessages(followerActor);
RaftActorLeadershipTransferCohort mockTransferCohort = mock(RaftActorLeadershipTransferCohort.class);
leader.transferLeadership(mockTransferCohort);
verify(mockTransferCohort, never()).transferComplete();
// Send heartbeats to time out the transfer.
for (int i = 0; i < leaderActorContext.getConfigParams().getElectionTimeoutFactor(); i++) {
Uninterruptibles.sleepUninterruptibly(leaderActorContext.getConfigParams().getHeartBeatInterval().toMillis() + 1, TimeUnit.MILLISECONDS);
leader.handleMessage(leaderActor, SendHeartBeat.INSTANCE);
}
verify(mockTransferCohort).abortTransfer();
verify(mockTransferCohort, never()).transferComplete();
MessageCollectorActor.assertNoneMatching(followerActor, ElectionTimeout.class, 100);
}
Aggregations