use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class LocalRaftTest method testNoCommitWhenOnlyLeaderAppends.
private void testNoCommitWhenOnlyLeaderAppends(int nodeCount) throws InterruptedException, ExecutionException {
group = newGroup(nodeCount);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
group.dropMessagesToAll(leader.getLocalMember(), AppendRequest.class);
try {
leader.replicate(new ApplyRaftRunnable("val")).get(10, TimeUnit.SECONDS);
fail();
} catch (TimeoutException ignored) {
}
for (RaftNodeImpl raftNode : group.getNodes()) {
assertEquals(0, getCommitIndex(raftNode));
RaftDataService service = group.getIntegration(raftNode.getLocalMember()).getService();
assertEquals(0, service.size());
}
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class LocalRaftTest method when_leaderTerminatesInMinority_then_clusterRemainsAvailable.
@Test
public void when_leaderTerminatesInMinority_then_clusterRemainsAvailable() throws Exception {
group = newGroup(3);
group.start();
RaftNodeImpl leaderNode = group.waitUntilLeaderElected();
RaftNodeImpl[] followers = group.getNodesExcept(leaderNode.getLocalMember());
int leaderTerm = getTerm(leaderNode);
group.terminateNode(leaderNode.getLocalMember());
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : followers) {
RaftEndpoint newLeader = getLeaderMember(raftNode);
assertNotNull(newLeader);
assertNotEquals(leaderNode.getLocalMember(), newLeader);
}
});
RaftNodeImpl newLeader = group.waitUntilLeaderElected();
assertTrue(getTerm(newLeader) > leaderTerm);
String value = "value";
Future future = newLeader.replicate(new ApplyRaftRunnable(value));
assertEquals(value, future.get());
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class LocalRaftTest method when_followerTerminatesInMinority_then_clusterRemainsAvailable.
@Test
public void when_followerTerminatesInMinority_then_clusterRemainsAvailable() throws Exception {
group = newGroup(3);
group.start();
RaftNodeImpl leaderNode = group.waitUntilLeaderElected();
int leaderIndex = group.getLeaderIndex();
for (int i = 0; i < group.size(); i++) {
if (i != leaderIndex) {
group.terminateNode(i);
break;
}
}
String value = "value";
Future future = leaderNode.replicate(new ApplyRaftRunnable(value));
assertEquals(value, future.get());
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class LocalRaftTest method when_followerBecomesLeaderWithUncommittedEntries_then_thoseEntriesAreCommittedWithANewEntryOfCurrentTerm.
@Test
public void when_followerBecomesLeaderWithUncommittedEntries_then_thoseEntriesAreCommittedWithANewEntryOfCurrentTerm() throws Exception {
group = newGroup(3);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
leader.replicate(new ApplyRaftRunnable("val1")).get();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
RaftNodeImpl nextLeader = followers[0];
long commitIndex = getCommitIndex(leader);
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : group.getNodes()) {
assertEquals(commitIndex, getCommitIndex(raftNode));
}
});
group.dropMessagesToMember(leader.getLocalMember(), followers[1].getLocalMember(), AppendRequest.class);
group.dropMessagesToMember(nextLeader.getLocalMember(), leader.getLocalMember(), AppendSuccessResponse.class);
leader.replicate(new ApplyRaftRunnable("val2"));
assertTrueEventually(() -> assertTrue(getLastLogOrSnapshotEntry(nextLeader).index() > commitIndex));
assertTrueAllTheTime(() -> {
for (RaftNodeImpl raftNode : group.getNodes()) {
assertEquals(commitIndex, getCommitIndex(raftNode));
}
}, 10);
group.terminateNode(leader.getLocalMember());
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : followers) {
assertEquals(nextLeader.getLocalMember(), getLeaderMember(raftNode));
}
});
nextLeader.replicate(new ApplyRaftRunnable("val3"));
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : followers) {
assertEquals(3, getCommitIndex(raftNode));
assertEquals(3, getLastLogOrSnapshotEntry(raftNode).index());
RaftDataService service = group.getService(raftNode);
assertEquals(3, service.size());
assertEquals("val1", service.get(1));
assertEquals("val2", service.get(2));
assertEquals("val3", service.get(3));
}
});
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class PersistenceTest method when_followerIsRestarted_then_itAppliesPreviouslyCommittedMemberList.
@Test
public void when_followerIsRestarted_then_itAppliesPreviouslyCommittedMemberList() throws ExecutionException, InterruptedException {
RaftAlgorithmConfig config = new RaftAlgorithmConfig().setLeaderHeartbeatPeriodInMillis(SECONDS.toMillis(30));
group = new LocalRaftGroupBuilder(3, config).setAppendNopEntryOnLeaderElection(true).setRaftStateStoreFactory(RAFT_STATE_STORE_FACTORY).build();
group.start();
final RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
RaftNodeImpl removedFollower = followers[0];
RaftNodeImpl terminatedFollower = followers[1];
group.terminateNode(removedFollower.getLocalMember());
leader.replicate(new ApplyRaftRunnable("val")).get();
leader.replicateMembershipChange(removedFollower.getLocalMember(), REMOVE).get();
RaftEndpoint terminatedEndpoint = terminatedFollower.getLocalMember();
InMemoryRaftStateStore stateStore = getRaftStateStore(terminatedFollower);
RestoredRaftState terminatedState = stateStore.toRestoredRaftState();
group.terminateNode(terminatedEndpoint);
final RaftNodeImpl restartedNode = group.createNewRaftNode(terminatedState, stateStore);
assertTrueEventually(() -> {
assertEquals(getCommitIndex(leader), getCommitIndex(restartedNode));
assertEquals(getLastApplied(leader), getLastApplied(restartedNode));
assertEquals(new ArrayList<>(getCommittedGroupMembers(leader).members()), new ArrayList<>(getCommittedGroupMembers(restartedNode).members()));
assertEquals(new ArrayList<>(getLastGroupMembers(leader).members()), new ArrayList<>(getLastGroupMembers(restartedNode).members()));
});
}
Aggregations