Search in sources :

Example 1 with LeaderElectionMetrics

use of org.apache.ratis.server.metrics.LeaderElectionMetrics in project incubator-ratis by apache.

the class LeaderElectionTests method createMockServer.

private static RaftServerImpl createMockServer(boolean alive) {
    final DivisionInfo info = mock(DivisionInfo.class);
    when(info.isAlive()).thenReturn(alive);
    when(info.isCandidate()).thenReturn(false);
    RaftServerImpl server = mock(RaftServerImpl.class);
    when(server.getInfo()).thenReturn(info);
    final RaftGroupMemberId memberId = RaftGroupMemberId.valueOf(RaftPeerId.valueOf("any"), RaftGroupId.randomId());
    when(server.getMemberId()).thenReturn(memberId);
    LeaderElectionMetrics leaderElectionMetrics = LeaderElectionMetrics.getLeaderElectionMetrics(memberId, () -> 0);
    when(server.getLeaderElectionMetrics()).thenReturn(leaderElectionMetrics);
    RaftServerProxy proxy = mock(RaftServerProxy.class);
    RaftProperties properties = new RaftProperties();
    RaftServerConfigKeys.LeaderElection.setPreVote(properties, true);
    when(proxy.getProperties()).thenReturn(properties);
    when(server.getRaftServer()).thenReturn(proxy);
    return server;
}
Also used : DivisionInfo(org.apache.ratis.server.DivisionInfo) RaftProperties(org.apache.ratis.conf.RaftProperties) RaftGroupMemberId(org.apache.ratis.protocol.RaftGroupMemberId) LeaderElectionMetrics(org.apache.ratis.server.metrics.LeaderElectionMetrics)

Aggregations

RaftProperties (org.apache.ratis.conf.RaftProperties)1 RaftGroupMemberId (org.apache.ratis.protocol.RaftGroupMemberId)1 DivisionInfo (org.apache.ratis.server.DivisionInfo)1 LeaderElectionMetrics (org.apache.ratis.server.metrics.LeaderElectionMetrics)1