use of com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent in project titus-control-plane by Netflix.
the class KubeClusterMembershipConnectorTest method electSiblingAsLeader.
private ClusterMemberLeadership electSiblingAsLeader() throws InterruptedException {
ClusterMemberLeadership sibling = ClusterMemberLeadership.newBuilder().withMemberId("sibling1").withLeadershipState(ClusterMemberLeadershipState.Leader).build();
kubeExecutors.emitLeadershipEvent(ClusterMembershipEvent.leaderElected(ClusterMembershipRevision.<ClusterMemberLeadership>newBuilder().withCurrent(sibling).build()));
LeaderElectionChangeEvent electionEvent = takeLeaderElectionEvent(LeaderElectionChangeEvent.ChangeType.LeaderElected);
assertThat(electionEvent.getLeadershipRevision().getCurrent().getLeadershipState()).isEqualTo(ClusterMemberLeadershipState.Leader);
return sibling;
}
use of com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent in project titus-control-plane by Netflix.
the class KubeClusterState method setLeaveLeaderElection.
public KubeClusterState setLeaveLeaderElection() {
ClusterMembershipRevision<ClusterMemberLeadership> revision = ClusterMembershipRevision.<ClusterMemberLeadership>newBuilder().withCurrent(ClusterMemberLeadership.newBuilder().withMemberId(localMemberId).withLeadershipState(ClusterMemberLeadershipState.Disabled).build()).build();
LeaderElectionChangeEvent event = localLeader ? LeaderElectionChangeEvent.leaderLost(revision) : LeaderElectionChangeEvent.localLeftElection(revision);
return toBuilder().withInLeaderElectionProcess(false).withLocalMemberLeadershipRevision(revision).withEvent(event).build();
}
use of com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent in project titus-control-plane by Netflix.
the class DefaultClusterMembershipServiceTest method expectLocalLeadershipTransition.
private void expectLocalLeadershipTransition(ClusterMemberLeadershipState state) throws InterruptedException {
LeaderElectionChangeEvent leadershipEvent = (LeaderElectionChangeEvent) eventSubscriber.takeNext(TIMEOUT);
assertThat(leadershipEvent).isNotNull();
assertThat(leadershipEvent.getLeadershipRevision().getCurrent().getLeadershipState()).isEqualTo(state);
assertThat(service.getLocalLeadership().getCurrent().getLeadershipState()).isEqualTo(state);
}
use of com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent in project titus-control-plane by Netflix.
the class AbstractKubeLeaderElectionExecutorTest method testLeaderElection.
@Test
public void testLeaderElection() {
// Join first member
MemberHolder member1 = new MemberHolder();
joinLeaderElectionProcess(member1);
awaitBeingLeader(member1);
LeaderElectionChangeEvent leaderSelectedEvent = member1.takeNextEvent();
assertThat(leaderSelectedEvent.getLeadershipRevision().getCurrent().getMemberId()).isEqualTo(member1.getMemberId());
assertThat(leaderSelectedEvent.getChangeType()).isEqualTo(LeaderElectionChangeEvent.ChangeType.LeaderElected);
// Join second member
MemberHolder member2 = new MemberHolder();
joinLeaderElectionProcess(member2);
// Leave leader election process.
member1.getExecutor().leaveLeaderElectionProcess();
await().until(() -> {
LeaderElectionChangeEvent event = member1.takeNextEvent();
return event != null && event.getChangeType() == LeaderElectionChangeEvent.ChangeType.LeaderLost;
});
// Check that second member takes over leadership
awaitBeingLeader(member2);
}
use of com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent in project titus-control-plane by Netflix.
the class KubeClusterMembershipConnectorTest method stopBeingLeader.
private void stopBeingLeader() throws InterruptedException {
connector.leaveLeadershipGroup(false).block();
LeaderElectionChangeEvent electionEvent = takeLeaderElectionEvent(LeaderElectionChangeEvent.ChangeType.LeaderLost);
assertThat(electionEvent.getLeadershipRevision().getCurrent().getLeadershipState()).isEqualTo(ClusterMemberLeadershipState.Disabled);
assertThat(connector.getLocalLeadershipRevision().getCurrent().getLeadershipState()).isEqualTo(ClusterMemberLeadershipState.Disabled);
}
Aggregations