use of org.apache.ratis.protocol.RaftGroupMemberId in project incubator-ratis by apache.
the class MemoryRaftLogTest method testEntryPerformTruncation.
@Test
public void testEntryPerformTruncation() throws Exception {
final RaftProperties prop = new RaftProperties();
prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class);
final RaftPeerId peerId = RaftPeerId.valueOf("s0");
final RaftGroupId groupId = RaftGroupId.randomId();
final RaftGroupMemberId memberId = RaftGroupMemberId.valueOf(peerId, groupId);
MemoryRaftLog raftLog = new MemoryRaftLog(memberId, () -> -1, prop);
raftLog.open(RaftLog.INVALID_LOG_INDEX, null);
LogEntryProto[] entries1 = new LogEntryProto[2];
entries1[0] = LogEntryProto.newBuilder().setIndex(0).setTerm(0).build();
entries1[1] = LogEntryProto.newBuilder().setIndex(1).setTerm(0).build();
raftLog.append(entries1).forEach(CompletableFuture::join);
LogEntryProto[] entries2 = new LogEntryProto[1];
entries2[0] = LogEntryProto.newBuilder().setIndex(0).setTerm(2).build();
raftLog.append(entries2).forEach(CompletableFuture::join);
final LogEntryHeader[] termIndices = raftLog.getEntries(0, 10);
assertEquals(1, termIndices.length);
assertEquals(entries2[0].getIndex(), termIndices[0].getIndex());
assertEquals(entries2[0].getTerm(), termIndices[0].getTerm());
}
use of org.apache.ratis.protocol.RaftGroupMemberId in project incubator-ratis by apache.
the class TestLeaderElectionMetrics method setUp.
@BeforeClass
public static void setUp() {
RaftGroupId raftGroupId = RaftGroupId.randomId();
RaftPeerId raftPeerId = RaftPeerId.valueOf("TestId");
RaftGroupMemberId raftGroupMemberId = RaftGroupMemberId.valueOf(raftPeerId, raftGroupId);
leaderElectionMetrics = LeaderElectionMetrics.getLeaderElectionMetrics(raftGroupMemberId, () -> 1000L);
ratisMetricRegistry = leaderElectionMetrics.getRegistry();
}
use of org.apache.ratis.protocol.RaftGroupMemberId in project incubator-ratis by apache.
the class TestLogAppenderMetrics method setup.
@Before
public void setup() {
RaftGroupId raftGroupId = RaftGroupId.randomId();
raftPeerId = RaftPeerId.valueOf("TestId");
RaftGroupMemberId raftGroupMemberId = RaftGroupMemberId.valueOf(raftPeerId, raftGroupId);
followerInfo = new MyFollowerInfo(100L);
LogAppenderMetrics logAppenderMetrics = new LogAppenderMetrics(raftGroupMemberId);
ratisMetricRegistry = logAppenderMetrics.getRegistry();
logAppenderMetrics.addFollowerGauges(raftPeerId, followerInfo::getNextIndex, followerInfo::getMatchIndex, followerInfo::getLastRpcTime);
}
use of org.apache.ratis.protocol.RaftGroupMemberId in project incubator-ratis by apache.
the class TestRetryCacheMetrics method setUp.
@BeforeClass
public static void setUp() {
RaftGroupId raftGroupId = RaftGroupId.randomId();
RaftPeerId raftPeerId = RaftPeerId.valueOf("TestId");
RaftGroupMemberId raftGroupMemberId = RaftGroupMemberId.valueOf(raftPeerId, raftGroupId);
retryCache = new RetryCacheImpl(RaftServerConfigKeys.RetryCache.EXPIRY_TIME_DEFAULT, null);
final RaftServerMetricsImpl raftServerMetrics = RaftServerMetricsImpl.computeIfAbsentRaftServerMetrics(raftGroupMemberId, () -> null, retryCache::getStatistics);
ratisMetricRegistry = raftServerMetrics.getRegistry();
}
use of org.apache.ratis.protocol.RaftGroupMemberId 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;
}
Aggregations