use of com.hazelcast.config.cp.RaftAlgorithmConfig in project hazelcast by hazelcast.
the class LocalRaftTest method when_thereAreTooManyInflightAppendedEntries_then_newAppendsAreRejected.
@Test
public void when_thereAreTooManyInflightAppendedEntries_then_newAppendsAreRejected() {
int uncommittedEntryCount = 10;
RaftAlgorithmConfig config = new RaftAlgorithmConfig().setUncommittedEntryCountToRejectNewAppends(uncommittedEntryCount);
group = newGroup(2, config);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl follower = group.getAnyFollowerNode();
group.terminateNode(follower.getLocalMember());
for (int i = 0; i < uncommittedEntryCount; i++) {
leader.replicate(new ApplyRaftRunnable("val" + i));
}
try {
leader.replicate(new ApplyRaftRunnable("valFinal")).joinInternal();
fail();
} catch (CannotReplicateException ignored) {
}
}
use of com.hazelcast.config.cp.RaftAlgorithmConfig in project hazelcast by hazelcast.
the class SnapshotTest method when_followersMatchIndexIsUnknown_then_itInstallsSnapshot.
@Test
public void when_followersMatchIndexIsUnknown_then_itInstallsSnapshot() throws ExecutionException, InterruptedException {
final int entryCount = 50;
RaftAlgorithmConfig config = new RaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(entryCount);
group = newGroup(3, config);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
RaftNodeImpl slowFollower = followers[1];
group.dropMessagesToMember(leader.getLocalMember(), slowFollower.getLocalMember(), AppendRequest.class);
group.dropMessagesToMember(leader.getLocalMember(), slowFollower.getLocalMember(), InstallSnapshot.class);
for (int i = 0; i < entryCount; i++) {
leader.replicate(new ApplyRaftRunnable("val" + i)).get();
}
assertTrueEventually(() -> assertEquals(entryCount, getSnapshotEntry(leader).index()));
leader.replicate(new ApplyRaftRunnable("valFinal")).get();
group.allowMessagesToMember(leader.getLocalMember(), slowFollower.getLocalMember(), InstallSnapshot.class);
assertTrueEventually(() -> assertEquals(entryCount, getCommitIndex(slowFollower)));
group.resetAllRulesFrom(leader.getLocalMember());
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : group.getNodes()) {
assertEquals(entryCount + 1, getCommitIndex(raftNode));
RaftDataService service = group.getService(raftNode);
assertEquals(entryCount + 1, service.size());
for (int i = 0; i < entryCount; i++) {
assertEquals(("val" + i), service.get(i + 1));
}
assertEquals("valFinal", service.get(51));
}
});
}
use of com.hazelcast.config.cp.RaftAlgorithmConfig in project hazelcast by hazelcast.
the class SnapshotTest method when_snapshotIsTaken_then_nextEntryIsCommitted.
@Test
public void when_snapshotIsTaken_then_nextEntryIsCommitted() throws ExecutionException, InterruptedException {
final int entryCount = 50;
RaftAlgorithmConfig config = new RaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(entryCount);
group = newGroup(3, config);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
for (int i = 0; i < entryCount; i++) {
leader.replicate(new ApplyRaftRunnable("val" + i)).get();
}
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : group.getNodes()) {
assertEquals(entryCount, getCommitIndex(raftNode));
assertEquals(entryCount, getSnapshotEntry(raftNode).index());
}
});
leader.replicate(new ApplyRaftRunnable("valFinal")).get();
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : group.getNodes()) {
assertEquals(entryCount + 1, getCommitIndex(raftNode));
RaftDataService service = group.getService(raftNode);
assertEquals(entryCount + 1, service.size());
for (int i = 0; i < entryCount; i++) {
assertEquals(("val" + i), service.get(i + 1));
}
assertEquals("valFinal", service.get(51));
}
});
}
use of com.hazelcast.config.cp.RaftAlgorithmConfig in project hazelcast by hazelcast.
the class SnapshotTest method when_followersLastAppendIsMembershipChange_then_itUpdatesRaftNodeStateWithInstalledSnapshot.
@Test
public void when_followersLastAppendIsMembershipChange_then_itUpdatesRaftNodeStateWithInstalledSnapshot() throws ExecutionException, InterruptedException {
final int entryCount = 50;
final RaftAlgorithmConfig config = new RaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(entryCount);
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();
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);
group.dropMessagesToMember(leader.getLocalMember(), slowFollower.getLocalMember(), InstallSnapshot.class);
for (RaftNodeImpl follower : followers) {
if (follower != slowFollower) {
group.allowAllMessagesToMember(follower.getLocalMember(), leader.getLeader());
}
}
f1.get();
for (int i = 0; i < entryCount; i++) {
leader.replicate(new ApplyRaftRunnable("val" + i)).get();
}
assertTrueEventually(() -> assertThat(getSnapshotEntry(leader).index(), greaterThanOrEqualTo((long) entryCount)));
group.allowAllMessagesToMember(leader.getLeader(), slowFollower.getLocalMember());
assertTrueEventually(() -> assertThat(getSnapshotEntry(slowFollower).index(), greaterThanOrEqualTo((long) entryCount)));
assertTrueEventually(() -> {
assertEquals(getCommittedGroupMembers(leader).index(), getCommittedGroupMembers(slowFollower).index());
assertEquals(ACTIVE, getStatus(slowFollower));
});
}
use of com.hazelcast.config.cp.RaftAlgorithmConfig in project hazelcast by hazelcast.
the class LeadershipTransferTest method testCannotTransferLeadershipWhileChangingMemberList.
@Test
public void testCannotTransferLeadershipWhileChangingMemberList() throws Exception {
RaftAlgorithmConfig config = new RaftAlgorithmConfig().setLeaderHeartbeatPeriodInMillis(SECONDS.toMillis(30));
group = new LocalRaftGroupBuilder(3, config).build();
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
leader.replicate(new NopEntry()).get();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
group.dropMessagesToMember(leader.getLocalMember(), followers[0].getLocalMember(), AppendRequest.class);
group.dropMessagesToMember(leader.getLocalMember(), followers[1].getLocalMember(), AppendRequest.class);
leader.replicateMembershipChange(followers[0].getLocalMember(), MembershipChangeMode.REMOVE);
InternalCompletableFuture f = leader.transferLeadership(followers[0].getLocalMember());
exceptionRule.expect(IllegalStateException.class);
f.joinInternal();
}
Aggregations