Search in sources :

Example 1 with StateMachineAdapter

use of org.apache.ignite.raft.jraft.core.StateMachineAdapter in project ignite-3 by apache.

the class ItJraftCounterServerTest method hasLeader.

/**
 * Returns {@code true} if a raft group has elected a leader for a some term.
 *
 * @param grpId Group id.
 * @return {@code True} if a leader is elected.
 */
private boolean hasLeader(String grpId) {
    return servers.stream().anyMatch(s -> {
        NodeImpl node = (NodeImpl) s.raftGroupService(grpId).getRaftNode();
        StateMachineAdapter fsm = (StateMachineAdapter) node.getOptions().getFsm();
        return node.isLeader() && fsm.getLeaderTerm() == node.getCurrentTerm();
    });
}
Also used : StateMachineAdapter(org.apache.ignite.raft.jraft.core.StateMachineAdapter) NodeImpl(org.apache.ignite.raft.jraft.core.NodeImpl)

Aggregations

NodeImpl (org.apache.ignite.raft.jraft.core.NodeImpl)1 StateMachineAdapter (org.apache.ignite.raft.jraft.core.StateMachineAdapter)1