Search in sources :

Example 1 with ForwardMessageToBehaviorActor

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);
}
Also used : HashMap(java.util.HashMap) TestActorRef(akka.testkit.TestActorRef) ActorRef(akka.actor.ActorRef) MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) FiniteDuration(scala.concurrent.duration.FiniteDuration) DefaultConfigParamsImpl(org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl) SendHeartBeat(org.opendaylight.controller.cluster.raft.base.messages.SendHeartBeat) ForwardMessageToBehaviorActor(org.opendaylight.controller.cluster.raft.utils.ForwardMessageToBehaviorActor) Test(org.junit.Test)

Aggregations

ActorRef (akka.actor.ActorRef)1 TestActorRef (akka.testkit.TestActorRef)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 DefaultConfigParamsImpl (org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl)1 MockRaftActorContext (org.opendaylight.controller.cluster.raft.MockRaftActorContext)1 SendHeartBeat (org.opendaylight.controller.cluster.raft.base.messages.SendHeartBeat)1 ForwardMessageToBehaviorActor (org.opendaylight.controller.cluster.raft.utils.ForwardMessageToBehaviorActor)1 FiniteDuration (scala.concurrent.duration.FiniteDuration)1