use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class MembershipChangeTest method when_leaderLeaves_then_itCannotVoteForCommitOfMemberChange.
@Test
public void when_leaderLeaves_then_itCannotVoteForCommitOfMemberChange() throws ExecutionException, InterruptedException {
RaftAlgorithmConfig config = new RaftAlgorithmConfig().setLeaderHeartbeatPeriodInMillis(1000);
group = newGroup(3, config);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
group.dropMessagesToMember(followers[0].getLocalMember(), leader.getLocalMember(), AppendSuccessResponse.class);
leader.replicate(new ApplyRaftRunnable("val")).get();
leader.replicateMembershipChange(leader.getLocalMember(), MembershipChangeMode.REMOVE);
assertTrueAllTheTime(() -> assertEquals(1, getCommitIndex(leader)), 10);
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class MembershipChangeTest method when_newJoiningNodeFirstReceivesSnapshot_then_itInstallsSnapshot.
@Test
public void when_newJoiningNodeFirstReceivesSnapshot_then_itInstallsSnapshot() throws ExecutionException, InterruptedException {
RaftAlgorithmConfig config = new RaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(5);
group = newGroup(3, config);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
for (int i = 0; i < 4; i++) {
leader.replicate(new ApplyRaftRunnable("val" + i)).get();
}
RaftNodeImpl newRaftNode = group.createNewRaftNode();
group.dropMessagesToMember(leader.getLocalMember(), newRaftNode.getLocalMember(), AppendRequest.class);
leader.replicateMembershipChange(newRaftNode.getLocalMember(), MembershipChangeMode.ADD).get();
assertTrueEventually(() -> assertTrue(getSnapshotEntry(leader).index() > 0));
group.resetAllRulesFrom(leader.getLocalMember());
assertTrueEventually(() -> {
assertEquals(getCommitIndex(leader), getCommitIndex(newRaftNode));
assertEquals(getLastGroupMembers(leader).members(), getLastGroupMembers(newRaftNode).members());
assertEquals(getLastGroupMembers(leader).members(), getCommittedGroupMembers(newRaftNode).members());
RaftDataService service = group.getService(newRaftNode);
assertEquals(4, service.size());
});
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class MembershipChangeTest method when_leaderFailsWhileLeavingRaftGroup_othersCommitTheMemberChange.
@Test
public void when_leaderFailsWhileLeavingRaftGroup_othersCommitTheMemberChange() throws ExecutionException, InterruptedException {
group = newGroup(3);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
leader.replicate(new ApplyRaftRunnable("val")).get();
for (RaftNodeImpl follower : followers) {
group.dropMessagesToMember(follower.getLocalMember(), leader.getLocalMember(), AppendSuccessResponse.class);
group.dropMessagesToMember(follower.getLocalMember(), leader.getLocalMember(), AppendFailureResponse.class);
}
leader.replicateMembershipChange(leader.getLocalMember(), MembershipChangeMode.REMOVE);
assertTrueEventually(() -> {
for (RaftNodeImpl follower : followers) {
assertEquals(2, getLastLogOrSnapshotEntry(follower).index());
}
});
group.terminateNode(leader.getLocalMember());
assertTrueEventually(() -> {
for (RaftNodeImpl follower : followers) {
RaftEndpoint newLeaderEndpoint = getLeaderMember(follower);
assertNotNull(newLeaderEndpoint);
assertNotEquals(leader.getLocalMember(), newLeaderEndpoint);
}
});
RaftNodeImpl newLeader = group.getNode(getLeaderMember(followers[0]));
newLeader.replicate(new ApplyRaftRunnable("val2"));
assertTrueEventually(() -> {
for (RaftNodeImpl follower : followers) {
assertFalse(getCommittedGroupMembers(follower).isKnownMember(leader.getLocalMember()));
}
});
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable 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());
});
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class DestroyRaftGroupTest method when_destroyOpIsTruncated_then_statusIsActive.
@Test
public void when_destroyOpIsTruncated_then_statusIsActive() throws ExecutionException, InterruptedException {
group = newGroup(3);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
group.dropMessagesToAll(leader.getLocalMember(), AppendRequest.class);
leader.replicate(new DestroyRaftGroupCmd());
group.split(leader.getLocalMember());
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : followers) {
RaftEndpoint leaderEndpoint = getLeaderMember(raftNode);
assertNotNull(leaderEndpoint);
assertNotEquals(leader.getLocalMember(), leaderEndpoint);
}
});
RaftNodeImpl newLeader = group.getNode(getLeaderMember(followers[0]));
for (int i = 0; i < 10; i++) {
newLeader.replicate(new ApplyRaftRunnable("val" + i)).get();
}
group.merge();
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : group.getNodes()) {
assertEquals(RaftNodeStatus.ACTIVE, getStatus(raftNode));
}
});
}
Aggregations