use of org.opendaylight.controller.cluster.raft.utils.ForwardMessageToBehaviorActor 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);
}
Aggregations