use of com.hazelcast.cp.internal.raft.impl.dataservice.RaftDataService 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.cp.internal.raft.impl.dataservice.RaftDataService in project hazelcast by hazelcast.
the class MembershipChangeTest method when_newRaftNodeJoins_then_itAppendsMissingEntries.
@Test
public void when_newRaftNodeJoins_then_itAppendsMissingEntries() throws ExecutionException, InterruptedException {
group = newGroup(3);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
leader.replicate(new ApplyRaftRunnable("val")).get();
RaftNodeImpl newRaftNode = group.createNewRaftNode();
leader.replicateMembershipChange(newRaftNode.getLocalMember(), MembershipChangeMode.ADD).get();
long commitIndex = getCommitIndex(leader);
assertTrueEventually(() -> assertEquals(commitIndex, getCommitIndex(newRaftNode)));
RaftGroupMembers lastGroupMembers = RaftUtil.getLastGroupMembers(leader);
assertTrueEventually(() -> {
RaftNodeImpl[] nodes = group.getNodes();
for (RaftNodeImpl raftNode : nodes) {
assertEquals(RaftNodeStatus.ACTIVE, getStatus(raftNode));
assertEquals(lastGroupMembers.members(), getLastGroupMembers(raftNode).members());
assertEquals(lastGroupMembers.index(), getLastGroupMembers(raftNode).index());
assertEquals(lastGroupMembers.members(), getCommittedGroupMembers(raftNode).members());
assertEquals(lastGroupMembers.index(), getCommittedGroupMembers(raftNode).index());
}
});
RaftDataService service = group.getService(newRaftNode);
assertEquals(1, service.size());
assertTrue(service.values().contains("val"));
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.RaftDataService in project hazelcast by hazelcast.
the class MembershipChangeTest method when_newRaftNodeJoinsAfterAnotherNodeLeaves_then_itAppendsMissingEntries.
@Test
public void when_newRaftNodeJoinsAfterAnotherNodeLeaves_then_itAppendsMissingEntries() throws ExecutionException, InterruptedException {
group = newGroup(3);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
leader.replicate(new ApplyRaftRunnable("val")).get();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
RaftNodeImpl leavingFollower = followers[0];
RaftNodeImpl stayingFollower = followers[1];
leader.replicateMembershipChange(leavingFollower.getLocalMember(), REMOVE).get();
RaftNodeImpl newRaftNode = group.createNewRaftNode();
leader.replicateMembershipChange(newRaftNode.getLocalMember(), MembershipChangeMode.ADD).get();
long commitIndex = getCommitIndex(leader);
assertTrueEventually(() -> assertEquals(commitIndex, getCommitIndex(newRaftNode)));
RaftGroupMembers lastGroupMembers = RaftUtil.getLastGroupMembers(leader);
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : asList(leader, stayingFollower, newRaftNode)) {
assertEquals(RaftNodeStatus.ACTIVE, getStatus(raftNode));
assertEquals(lastGroupMembers.members(), getLastGroupMembers(raftNode).members());
assertEquals(lastGroupMembers.index(), getLastGroupMembers(raftNode).index());
assertEquals(lastGroupMembers.members(), getCommittedGroupMembers(raftNode).members());
assertEquals(lastGroupMembers.index(), getCommittedGroupMembers(raftNode).index());
assertFalse(getLastGroupMembers(raftNode).isKnownMember(leavingFollower.getLocalMember()));
assertFalse(getCommittedGroupMembers(raftNode).isKnownMember(leavingFollower.getLocalMember()));
}
});
RaftDataService service = group.getService(newRaftNode);
assertEquals(1, service.size());
assertTrue(service.values().contains("val"));
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.RaftDataService in project hazelcast by hazelcast.
the class MembershipChangeTest method when_newRaftNodeJoinsAfterAnotherNodeLeavesAndSnapshotIsTaken_then_itAppendsMissingEntries.
@Test
public void when_newRaftNodeJoinsAfterAnotherNodeLeavesAndSnapshotIsTaken_then_itAppendsMissingEntries() throws ExecutionException, InterruptedException {
int commitIndexAdvanceCountToSnapshot = 10;
RaftAlgorithmConfig config = new RaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(commitIndexAdvanceCountToSnapshot);
group = newGroup(3, config);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
leader.replicate(new ApplyRaftRunnable("val")).get();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
RaftNodeImpl leavingFollower = followers[0];
RaftNodeImpl stayingFollower = followers[1];
leader.replicateMembershipChange(leavingFollower.getLocalMember(), REMOVE).get();
for (int i = 0; i < commitIndexAdvanceCountToSnapshot; i++) {
leader.replicate(new ApplyRaftRunnable("val" + i)).get();
}
assertTrueEventually(() -> assertTrue(getSnapshotEntry(leader).index() > 0));
RaftNodeImpl newRaftNode = group.createNewRaftNode();
leader.replicateMembershipChange(newRaftNode.getLocalMember(), MembershipChangeMode.ADD).get();
long commitIndex = getCommitIndex(leader);
assertTrueEventually(() -> assertEquals(commitIndex, getCommitIndex(newRaftNode)));
RaftGroupMembers lastGroupMembers = RaftUtil.getLastGroupMembers(leader);
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : asList(leader, stayingFollower, newRaftNode)) {
assertEquals(RaftNodeStatus.ACTIVE, getStatus(raftNode));
assertEquals(lastGroupMembers.members(), getLastGroupMembers(raftNode).members());
assertEquals(lastGroupMembers.index(), getLastGroupMembers(raftNode).index());
assertEquals(lastGroupMembers.members(), getCommittedGroupMembers(raftNode).members());
assertEquals(lastGroupMembers.index(), getCommittedGroupMembers(raftNode).index());
assertFalse(getLastGroupMembers(raftNode).isKnownMember(leavingFollower.getLocalMember()));
assertFalse(getCommittedGroupMembers(raftNode).isKnownMember(leavingFollower.getLocalMember()));
}
});
RaftDataService service = group.getService(newRaftNode);
assertEquals(commitIndexAdvanceCountToSnapshot + 1, service.size());
assertTrue(service.values().contains("val"));
for (int i = 0; i < commitIndexAdvanceCountToSnapshot; i++) {
assertTrue(service.values().contains("val" + i));
}
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.RaftDataService in project hazelcast by hazelcast.
the class LocalRaftTest method testReplicateEntriesSequentially.
private void testReplicateEntriesSequentially(int nodeCount) throws ExecutionException, InterruptedException {
final int entryCount = 100;
group = newGroup(nodeCount, newRaftConfigWithNoSnapshotting(entryCount));
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
for (int i = 0; i < entryCount; i++) {
Object val = "val" + i;
leader.replicate(new ApplyRaftRunnable(val)).get();
}
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : group.getNodes()) {
assertEquals(entryCount, getCommitIndex(raftNode));
RaftDataService service = group.getService(raftNode);
assertEquals(100, service.size());
for (int i = 0; i < entryCount; i++) {
int commitIndex = i + 1;
Object val = "val" + i;
assertEquals(val, service.get(commitIndex));
}
}
});
}
Aggregations