use of com.hazelcast.cp.internal.raft.impl.state.RaftGroupMembers in project hazelcast by hazelcast.
the class MembershipChangeTest method when_followerAppendsMultipleMembershipChangesAtOnce_then_itCommitsThemCorrectly.
@Test
public void when_followerAppendsMultipleMembershipChangesAtOnce_then_itCommitsThemCorrectly() throws ExecutionException, InterruptedException {
RaftAlgorithmConfig config = new RaftAlgorithmConfig().setLeaderHeartbeatPeriodInMillis(1000);
group = newGroup(5, config);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
leader.replicate(new ApplyRaftRunnable("val")).get();
assertTrueEventually(() -> {
for (RaftNodeImpl follower : followers) {
assertEquals(1L, getCommitIndex(follower));
}
});
RaftNodeImpl slowFollower = followers[0];
for (RaftNodeImpl follower : followers) {
if (follower != slowFollower) {
group.dropMessagesToMember(follower.getLocalMember(), follower.getLeader(), AppendSuccessResponse.class);
group.dropMessagesToMember(follower.getLocalMember(), follower.getLeader(), AppendFailureResponse.class);
}
}
RaftNodeImpl newRaftNode1 = group.createNewRaftNode();
group.dropMessagesToMember(leader.getLocalMember(), newRaftNode1.getLocalMember(), AppendRequest.class);
Future f1 = leader.replicateMembershipChange(newRaftNode1.getLocalMember(), MembershipChangeMode.ADD);
assertTrueEventually(() -> {
for (RaftNodeImpl follower : followers) {
assertEquals(2L, getLastLogOrSnapshotEntry(follower).index());
}
});
group.dropMessagesToMember(leader.getLocalMember(), slowFollower.getLocalMember(), AppendRequest.class);
for (RaftNodeImpl follower : followers) {
if (follower != slowFollower) {
group.allowAllMessagesToMember(follower.getLocalMember(), leader.getLeader());
}
}
f1.get();
assertTrueEventually(() -> {
for (RaftNodeImpl follower : followers) {
if (follower != slowFollower) {
assertEquals(6, getCommittedGroupMembers(follower).memberCount());
} else {
assertEquals(5, getCommittedGroupMembers(follower).memberCount());
assertEquals(6, getLastGroupMembers(follower).memberCount());
}
}
});
RaftNodeImpl newRaftNode2 = group.createNewRaftNode();
leader.replicateMembershipChange(newRaftNode2.getLocalMember(), MembershipChangeMode.ADD).get();
group.allowAllMessagesToMember(leader.getLocalMember(), slowFollower.getLocalMember());
group.allowAllMessagesToMember(slowFollower.getLocalMember(), leader.getLocalMember());
group.allowAllMessagesToMember(leader.getLocalMember(), newRaftNode1.getLocalMember());
RaftGroupMembers leaderCommittedGroupMembers = getCommittedGroupMembers(leader);
assertTrueEventually(() -> {
assertEquals(leaderCommittedGroupMembers.index(), getCommittedGroupMembers(slowFollower).index());
assertEquals(leaderCommittedGroupMembers.index(), getCommittedGroupMembers(newRaftNode1).index());
assertEquals(leaderCommittedGroupMembers.index(), getCommittedGroupMembers(newRaftNode2).index());
});
}
Aggregations