Search in sources :

Example 36 with DefaultConfigParamsImpl

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;
}
Also used : FiniteDuration(scala.concurrent.duration.FiniteDuration) DefaultConfigParamsImpl(org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl)

Example 37 with DefaultConfigParamsImpl

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);
}
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)

Example 38 with DefaultConfigParamsImpl

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");
}
Also used : DefaultConfigParamsImpl(org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl)

Example 39 with DefaultConfigParamsImpl

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());
}
Also used : ServerConfigurationPayload(org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload) ServerInfo(org.opendaylight.controller.cluster.raft.persisted.ServerInfo) ElectionTimeout(org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout) MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) DefaultConfigParamsImpl(org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl) Test(org.junit.Test)

Aggregations

DefaultConfigParamsImpl (org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl)39 Test (org.junit.Test)31 MockRaftActorContext (org.opendaylight.controller.cluster.raft.MockRaftActorContext)31 FiniteDuration (scala.concurrent.duration.FiniteDuration)26 AppendEntriesReply (org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply)22 AppendEntries (org.opendaylight.controller.cluster.raft.messages.AppendEntries)17 SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)10 ByteString (com.google.protobuf.ByteString)8 ReplicatedLogEntry (org.opendaylight.controller.cluster.raft.ReplicatedLogEntry)7 InstallSnapshot (org.opendaylight.controller.cluster.raft.messages.InstallSnapshot)6 Snapshot (org.opendaylight.controller.cluster.raft.persisted.Snapshot)6 HashMap (java.util.HashMap)5 FollowerLogInformation (org.opendaylight.controller.cluster.raft.FollowerLogInformation)4 RaftActorLeadershipTransferCohort (org.opendaylight.controller.cluster.raft.RaftActorLeadershipTransferCohort)4 ActorRef (akka.actor.ActorRef)3 TestActorRef (akka.testkit.TestActorRef)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 MockRaftActor (org.opendaylight.controller.cluster.raft.MockRaftActor)3 Builder (org.opendaylight.controller.cluster.raft.MockRaftActor.Builder)3 RaftActorSnapshotCohort (org.opendaylight.controller.cluster.raft.RaftActorSnapshotCohort)3