use of org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl 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.DefaultConfigParamsImpl in project controller by opendaylight.
the class LeaderTest method testLargePayloadSlicingExpiration.
@Test
public void testLargePayloadSlicingExpiration() {
logStart("testLargePayloadSlicingExpiration");
MockRaftActorContext leaderActorContext = createActorContextWithFollower();
((DefaultConfigParamsImpl) leaderActorContext.getConfigParams()).setHeartBeatInterval(new FiniteDuration(100, TimeUnit.MILLISECONDS));
((DefaultConfigParamsImpl) leaderActorContext.getConfigParams()).setElectionTimeoutFactor(1);
((DefaultConfigParamsImpl) leaderActorContext.getConfigParams()).setSnapshotChunkSize(10);
leaderActorContext.setReplicatedLog(new MockRaftActorContext.MockReplicatedLogBuilder().build());
leaderActorContext.setCommitIndex(-1);
leaderActorContext.setLastApplied(-1);
final long term = leaderActorContext.getTermInformation().getCurrentTerm();
leader = new Leader(leaderActorContext);
leaderActorContext.setCurrentBehavior(leader);
// Send initial heartbeat reply so follower is marked active
MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
leader.handleMessage(followerActor, new AppendEntriesReply(FOLLOWER_ID, -1, true, -1, -1, (short) 0));
MessageCollectorActor.clearMessages(followerActor);
sendReplicate(leaderActorContext, term, 0, new MockRaftActorContext.MockPayload("large", leaderActorContext.getConfigParams().getSnapshotChunkSize() + 1));
MessageCollectorActor.expectFirstMatching(followerActor, MessageSlice.class);
// Sleep for at least 3 * election timeout so the slicing state expires.
Uninterruptibles.sleepUninterruptibly(leaderActorContext.getConfigParams().getElectionTimeOutInterval().toMillis() * 3 + 50, TimeUnit.MILLISECONDS);
MessageCollectorActor.clearMessages(followerActor);
leader.handleMessage(leaderActor, SendHeartBeat.INSTANCE);
AppendEntries appendEntries = MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
assertEquals("getLeaderCommit", -1, appendEntries.getLeaderCommit());
assertEquals("Entries size", 0, appendEntries.getEntries().size());
MessageCollectorActor.assertNoneMatching(followerActor, MessageSlice.class, 300);
MessageCollectorActor.clearMessages(followerActor);
// Send an AppendEntriesReply - this should restart the slicing.
Uninterruptibles.sleepUninterruptibly(leaderActorContext.getConfigParams().getHeartBeatInterval().toMillis() + 50, TimeUnit.MILLISECONDS);
leader.handleMessage(followerActor, new AppendEntriesReply(FOLLOWER_ID, term, true, -1, term, (short) 0));
MessageCollectorActor.expectFirstMatching(followerActor, MessageSlice.class);
}
use of org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl in project controller by opendaylight.
the class LeaderTest method createActorContext.
private MockRaftActorContext createActorContext(final String id, final ActorRef actorRef) {
DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl();
configParams.setHeartBeatInterval(new FiniteDuration(50, TimeUnit.MILLISECONDS));
configParams.setElectionTimeoutFactor(100000);
MockRaftActorContext context = new MockRaftActorContext(id, getSystem(), actorRef);
context.setConfigParams(configParams);
context.setPayloadVersion(payloadVersion);
return context;
}
use of org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl in project controller by opendaylight.
the class LeaderTest method testHandleAppendEntriesReplyWithNewerTermWhenElectionsAreDisabled.
@Test
public void testHandleAppendEntriesReplyWithNewerTermWhenElectionsAreDisabled() {
logStart("testHandleAppendEntriesReplyWithNewerTermWhenElectionsAreDisabled");
MockRaftActorContext leaderActorContext = createActorContext();
((DefaultConfigParamsImpl) leaderActorContext.getConfigParams()).setHeartBeatInterval(new FiniteDuration(10000, TimeUnit.SECONDS));
leaderActorContext.setReplicatedLog(new MockRaftActorContext.MockReplicatedLogBuilder().createEntries(0, 2, 2).build());
leaderActorContext.setRaftPolicy(createRaftPolicy(false, false));
leader = new Leader(leaderActorContext);
leaderActor.underlyingActor().setBehavior(leader);
leaderActor.tell(new AppendEntriesReply("foo", 20, false, 1000, 10, (short) 1), ActorRef.noSender());
AppendEntriesReply appendEntriesReply = MessageCollectorActor.expectFirstMatching(leaderActor, AppendEntriesReply.class);
assertEquals(false, appendEntriesReply.isSuccess());
assertEquals(RaftState.Leader, leaderActor.underlyingActor().getFirstBehaviorChange().state());
MessageCollectorActor.clearMessages(leaderActor);
}
use of org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl in project controller by opendaylight.
the class LeaderTest method testIsolatedLeaderCheckNoVotingFollowers.
@Test
public void testIsolatedLeaderCheckNoVotingFollowers() {
logStart("testIsolatedLeaderCheckNoVotingFollowers");
MockRaftActorContext followerActorContext = createFollowerActorContextWithLeader();
Follower follower = new Follower(followerActorContext);
followerActor.underlyingActor().setBehavior(follower);
MockRaftActorContext leaderActorContext = createActorContextWithFollower();
((DefaultConfigParamsImpl) leaderActorContext.getConfigParams()).setHeartBeatInterval(new FiniteDuration(1000, TimeUnit.SECONDS));
leaderActorContext.getPeerInfo(FOLLOWER_ID).setVotingState(VotingState.NON_VOTING);
leader = new Leader(leaderActorContext);
leader.getFollower(FOLLOWER_ID).markFollowerActive();
RaftActorBehavior newBehavior = leader.handleMessage(leaderActor, Leader.ISOLATED_LEADER_CHECK);
assertTrue("Expected Leader", newBehavior instanceof Leader);
}
Aggregations