use of org.apache.ratis.proto.RaftProtos.CommitInfoProto in project incubator-ratis by apache.
the class GroupInfoBaseTest method runTest.
private void runTest(CLUSTER cluster) throws Exception {
// all the peers in the cluster are in the same group, get it.
RaftGroup group = cluster.getGroup();
List<RaftPeer> peers = cluster.getPeers();
// Multi-raft with the second group
RaftGroup group2 = RaftGroup.valueOf(RaftGroupId.randomId(), peers);
for (RaftPeer peer : peers) {
try (final RaftClient client = cluster.createClient(peer.getId())) {
client.getGroupManagementApi(peer.getId()).add(group2);
}
}
// for each of them.
for (RaftPeer peer : peers) {
try (final RaftClient client = cluster.createClient(peer.getId())) {
final GroupManagementApi api = client.getGroupManagementApi(peer.getId());
final GroupListReply info = api.list();
List<RaftGroupId> groupList = info.getGroupIds().stream().filter(id -> group.getGroupId().equals(id)).collect(Collectors.toList());
assert (groupList.size() == 1);
final GroupInfoReply gi = api.info(groupList.get(0));
assert (sameGroup(group, gi.getGroup()));
groupList = info.getGroupIds().stream().filter(id -> group2.getGroupId().equals(id)).collect(Collectors.toList());
assert (groupList.size() == 1);
final GroupInfoReply gi2 = api.info(groupList.get(0));
assert (sameGroup(group2, gi2.getGroup()));
}
}
final int numMessages = 5;
final long maxCommit;
{
// send some messages and get max commit from the last reply
final RaftClientReply reply = sendMessages(numMessages, cluster);
maxCommit = reply.getCommitInfos().stream().mapToLong(CommitInfoProto::getCommitIndex).max().getAsLong();
}
// kill a follower
final RaftPeerId killedFollower = cluster.getFollowers().iterator().next().getId();
cluster.killServer(killedFollower);
{
// send more messages and check last reply
final RaftClientReply reply = sendMessages(numMessages, cluster);
for (CommitInfoProto i : reply.getCommitInfos()) {
if (!RaftPeerId.valueOf(i.getServer().getId()).equals(killedFollower)) {
Assert.assertTrue(i.getCommitIndex() > maxCommit);
}
}
}
// check getGroupList
for (RaftPeer peer : peers) {
if (peer.getId().equals(killedFollower)) {
continue;
}
try (final RaftClient client = cluster.createClient(peer.getId())) {
final GroupListReply info = client.getGroupManagementApi(peer.getId()).list();
Assert.assertEquals(1, info.getGroupIds().stream().filter(id -> group.getGroupId().equals(id)).count());
for (CommitInfoProto i : info.getCommitInfos()) {
if (RaftPeerId.valueOf(i.getServer().getId()).equals(killedFollower)) {
Assert.assertTrue(i.getCommitIndex() <= maxCommit);
} else {
Assert.assertTrue(i.getCommitIndex() > maxCommit);
}
}
}
}
}
Aggregations