use of org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl in project controller by opendaylight.
the class FollowerTest method testFollowerSchedulesElectionIfAutomaticElectionsAreDisabled.
@Test
public void testFollowerSchedulesElectionIfAutomaticElectionsAreDisabled() {
MockRaftActorContext context = createActorContext();
context.setConfigParams(new DefaultConfigParamsImpl() {
@Override
public FiniteDuration getElectionTimeOutInterval() {
return FiniteDuration.apply(100, TimeUnit.MILLISECONDS);
}
});
context.setRaftPolicy(createRaftPolicy(false, false));
follower = createBehavior(context);
TimeoutNow timeoutNow = MessageCollectorActor.expectFirstMatching(followerActor, TimeoutNow.class);
RaftActorBehavior newBehavior = follower.handleMessage(ActorRef.noSender(), timeoutNow);
assertSame("handleMessage result", follower, newBehavior);
}
use of org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl in project controller by opendaylight.
the class FollowerTest method testHandleElectionTimeoutWhenLeaderMessageReceived.
@Test
public void testHandleElectionTimeoutWhenLeaderMessageReceived() {
logStart("testHandleElectionTimeoutWhenLeaderMessageReceived");
MockRaftActorContext context = createActorContext();
((DefaultConfigParamsImpl) context.getConfigParams()).setHeartBeatInterval(new FiniteDuration(100, TimeUnit.MILLISECONDS));
((DefaultConfigParamsImpl) context.getConfigParams()).setElectionTimeoutFactor(4);
follower = new Follower(context);
context.setCurrentBehavior(follower);
Uninterruptibles.sleepUninterruptibly(context.getConfigParams().getElectionTimeOutInterval().toMillis() - 100, TimeUnit.MILLISECONDS);
follower.handleMessage(leaderActor, new AppendEntries(1, "leader", -1, -1, Collections.emptyList(), -1, -1, (short) 1));
Uninterruptibles.sleepUninterruptibly(130, TimeUnit.MILLISECONDS);
RaftActorBehavior raftBehavior = follower.handleMessage(leaderActor, ElectionTimeout.INSTANCE);
assertTrue(raftBehavior instanceof Follower);
Uninterruptibles.sleepUninterruptibly(context.getConfigParams().getElectionTimeOutInterval().toMillis() - 150, TimeUnit.MILLISECONDS);
follower.handleMessage(leaderActor, new AppendEntries(1, "leader", -1, -1, Collections.emptyList(), -1, -1, (short) 1));
Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
raftBehavior = follower.handleMessage(leaderActor, ElectionTimeout.INSTANCE);
assertTrue(raftBehavior instanceof Follower);
}
use of org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl in project controller by opendaylight.
the class IsolatedLeaderTest method createActorContext.
@Override
protected MockRaftActorContext createActorContext(final ActorRef actor) {
DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl();
configParams.setElectionTimeoutFactor(100000);
MockRaftActorContext context = new MockRaftActorContext("isolated-leader", getSystem(), actor);
context.setConfigParams(configParams);
return context;
}
use of org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl 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.DefaultConfigParamsImpl in project controller by opendaylight.
the class LeaderTest method testDuplicateAppendEntriesWillBeSentOnHeartBeat.
@Test
public void testDuplicateAppendEntriesWillBeSentOnHeartBeat() throws Exception {
logStart("testDuplicateAppendEntriesWillBeSentOnHeartBeat");
MockRaftActorContext actorContext = createActorContextWithFollower();
actorContext.setConfigParams(new DefaultConfigParamsImpl() {
@Override
public FiniteDuration getHeartBeatInterval() {
return FiniteDuration.apply(500, TimeUnit.MILLISECONDS);
}
});
long term = 1;
actorContext.getTermInformation().update(term, "");
leader = new Leader(actorContext);
// Leader will send an immediate heartbeat - ignore it.
MessageCollectorActor.expectFirstMatching(followerActor, AppendEntries.class);
// The follower would normally reply - simulate that explicitly here.
long lastIndex = actorContext.getReplicatedLog().lastIndex();
leader.handleMessage(followerActor, new AppendEntriesReply(FOLLOWER_ID, term, true, lastIndex, term, (short) 0));
assertEquals("isFollowerActive", true, leader.getFollower(FOLLOWER_ID).isFollowerActive());
followerActor.underlyingActor().clear();
sendReplicate(actorContext, lastIndex + 1);
// Wait slightly longer than heartbeat duration
Uninterruptibles.sleepUninterruptibly(750, TimeUnit.MILLISECONDS);
leader.handleMessage(leaderActor, SendHeartBeat.INSTANCE);
List<AppendEntries> allMessages = MessageCollectorActor.getAllMatching(followerActor, AppendEntries.class);
assertEquals("The number of append entries collected should be 2", 2, allMessages.size());
assertEquals(1, allMessages.get(0).getEntries().size());
assertEquals(lastIndex + 1, allMessages.get(0).getEntries().get(0).getIndex());
assertEquals(1, allMessages.get(1).getEntries().size());
assertEquals(lastIndex + 1, allMessages.get(0).getEntries().get(0).getIndex());
}
Aggregations