use of org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl in project controller by opendaylight.
the class AbstractLeaderElectionScenarioTest method newConfigParams.
DefaultConfigParamsImpl newConfigParams() {
DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl();
configParams.setHeartBeatInterval(new FiniteDuration(HEARTBEAT_INTERVAL, TimeUnit.MILLISECONDS));
configParams.setElectionTimeoutFactor(100000);
configParams.setIsolatedLeaderCheckInterval(new FiniteDuration(1, TimeUnit.DAYS));
return configParams;
}
use of org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl in project controller by opendaylight.
the class AbstractLeaderTest method testLeaderSchedulesHeartbeatsEvenWhenNoFollowersRespondToInitialAppendEntries.
/**
* When we removed scheduling of heartbeat in the AbstractLeader constructor we ended up with a situation where
* if no follower responded to an initial AppendEntries heartbeats would not be sent to it. This test verifies
* that regardless of whether followers respond or not we schedule heartbeats.
*/
@Test
public void testLeaderSchedulesHeartbeatsEvenWhenNoFollowersRespondToInitialAppendEntries() throws Exception {
logStart("testLeaderSchedulesHeartbeatsEvenWhenNoFollowersRespondToInitialAppendEntries");
String leaderActorId = actorFactory.generateActorId("leader");
String follower1ActorId = actorFactory.generateActorId("follower");
String follower2ActorId = actorFactory.generateActorId("follower");
TestActorRef<ForwardMessageToBehaviorActor> leaderActor = actorFactory.createTestActor(ForwardMessageToBehaviorActor.props(), leaderActorId);
final ActorRef follower1Actor = actorFactory.createActor(MessageCollectorActor.props(), follower1ActorId);
final ActorRef follower2Actor = actorFactory.createActor(MessageCollectorActor.props(), follower2ActorId);
MockRaftActorContext leaderActorContext = new MockRaftActorContext(leaderActorId, getSystem(), leaderActor);
DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl();
configParams.setHeartBeatInterval(new FiniteDuration(200, TimeUnit.MILLISECONDS));
configParams.setIsolatedLeaderCheckInterval(new FiniteDuration(10, TimeUnit.SECONDS));
leaderActorContext.setConfigParams(configParams);
leaderActorContext.setReplicatedLog(new MockRaftActorContext.MockReplicatedLogBuilder().createEntries(1, 5, 1).build());
Map<String, String> peerAddresses = new HashMap<>();
peerAddresses.put(follower1ActorId, follower1Actor.path().toString());
peerAddresses.put(follower2ActorId, follower2Actor.path().toString());
leaderActorContext.setPeerAddresses(peerAddresses);
RaftActorBehavior leader = createBehavior(leaderActorContext);
leaderActor.underlyingActor().setBehavior(leader);
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
List<SendHeartBeat> allMessages = MessageCollectorActor.getAllMatching(leaderActor, SendHeartBeat.class);
// Need more than 1 heartbeat to be delivered because we waited for 1 second with heartbeat interval 200ms
assertTrue(String.format("%s messages is less than expected", allMessages.size()), allMessages.size() > 1);
}
use of org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl in project controller by opendaylight.
the class DelayedMessagesElectionScenarioTest method setupInitialMemberBehaviors.
private void setupInitialMemberBehaviors() {
testLog.info("setupInitialMemberBehaviors starting");
// Create member 2's behavior initially as Follower
member2Context = newRaftActorContext("member2", member2ActorRef, ImmutableMap.<String, String>builder().put("member1", member1ActorRef.path().toString()).put("member3", member3ActorRef.path().toString()).build());
DefaultConfigParamsImpl member2ConfigParams = newConfigParams();
member2Context.setConfigParams(member2ConfigParams);
member2Actor.self().tell(new SetBehavior(new Follower(member2Context), member2Context), ActorRef.noSender());
// Create member 3's behavior initially as Follower
member3Context = newRaftActorContext("member3", member3ActorRef, ImmutableMap.<String, String>builder().put("member1", member1ActorRef.path().toString()).put("member2", member2ActorRef.path().toString()).build());
DefaultConfigParamsImpl member3ConfigParams = newConfigParams();
member3Context.setConfigParams(member3ConfigParams);
member3Actor.self().tell(new SetBehavior(new Follower(member3Context), member3Context), ActorRef.noSender());
// Create member 1's behavior initially as Leader
member1Context = newRaftActorContext("member1", member1ActorRef, ImmutableMap.<String, String>builder().put("member2", member2ActorRef.path().toString()).put("member3", member3ActorRef.path().toString()).build());
DefaultConfigParamsImpl member1ConfigParams = newConfigParams();
member1Context.setConfigParams(member1ConfigParams);
initializeLeaderBehavior(member1Actor, member1Context, 2);
member2Actor.clear();
member3Actor.clear();
testLog.info("setupInitialMemberBehaviors ending");
}
use of org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl in project controller by opendaylight.
the class FollowerTest method testFollowerSchedulesElectionIfNonVoting.
@Test
public void testFollowerSchedulesElectionIfNonVoting() {
MockRaftActorContext context = createActorContext();
context.updatePeerIds(new ServerConfigurationPayload(Arrays.asList(new ServerInfo(context.getId(), false))));
((DefaultConfigParamsImpl) context.getConfigParams()).setHeartBeatInterval(FiniteDuration.apply(100, TimeUnit.MILLISECONDS));
((DefaultConfigParamsImpl) context.getConfigParams()).setElectionTimeoutFactor(1);
follower = new Follower(context, "leader", (short) 1);
ElectionTimeout electionTimeout = MessageCollectorActor.expectFirstMatching(followerActor, ElectionTimeout.class);
RaftActorBehavior newBehavior = follower.handleMessage(ActorRef.noSender(), electionTimeout);
assertSame("handleMessage result", follower, newBehavior);
assertNull("Expected null leaderId", follower.getLeaderId());
}
Aggregations