use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class LinearizableQueryTest method when_newCommitIsDoneWhileThereAreMultipleQueries_then_allQueriesRunAfterCommit.
@Test(timeout = 300_000)
public void when_newCommitIsDoneWhileThereAreMultipleQueries_then_allQueriesRunAfterCommit() throws Exception {
group = newGroup();
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
leader.replicate(new ApplyRaftRunnable("value1")).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);
group.dropMessagesToMember(leader.getLocalMember(), followers[2].getLocalMember(), AppendRequest.class);
InternalCompletableFuture replicateFuture = leader.replicate(new ApplyRaftRunnable("value2"));
InternalCompletableFuture queryFuture1 = leader.query(new QueryRaftRunnable(), LINEARIZABLE);
InternalCompletableFuture queryFuture2 = leader.query(new QueryRaftRunnable(), LINEARIZABLE);
group.resetAllRulesFrom(leader.getLocalMember());
replicateFuture.get();
assertEquals("value2", queryFuture1.get());
assertEquals("value2", queryFuture2.get());
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class LinearizableQueryTest method when_leaderDemotesToFollowerWhileThereIsOngoingQuery_then_queryFails.
@Test(timeout = 300_000)
public void when_leaderDemotesToFollowerWhileThereIsOngoingQuery_then_queryFails() throws Exception {
group = newGroup();
group.start();
RaftNodeImpl oldLeader = group.waitUntilLeaderElected();
final int[] split = group.createMajoritySplitIndexes(false);
group.split(split);
InternalCompletableFuture queryFuture = oldLeader.query(new QueryRaftRunnable(), LINEARIZABLE);
assertTrueEventually(() -> {
for (int ix : split) {
RaftEndpoint newLeader = getLeaderMember(group.getNode(ix));
assertNotNull(newLeader);
assertNotEquals(oldLeader.getLocalMember(), newLeader);
}
});
RaftNodeImpl newLeader = group.getNode(getLeaderMember(group.getNode(split[0])));
newLeader.replicate(new ApplyRaftRunnable("value1")).get();
group.merge();
group.waitUntilLeaderElected();
assertEquals(oldLeader.getLeader(), newLeader.getLocalMember());
try {
queryFuture.joinInternal();
fail();
} catch (LeaderDemotedException ignored) {
}
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class LocalRaftTest method testSingleCommitEntry.
private void testSingleCommitEntry(final int nodeCount) throws Exception {
group = newGroup(nodeCount);
group.start();
group.waitUntilLeaderElected();
Object val = "val";
Object result = group.getLeaderNode().replicate(new ApplyRaftRunnable(val)).get();
assertEquals(result, val);
int commitIndex = 1;
assertTrueEventually(() -> {
for (int i = 0; i < nodeCount; i++) {
RaftNodeImpl node = group.getNode(i);
long index = getCommitIndex(node);
assertEquals(commitIndex, index);
RaftDataService service = group.getIntegration(i).getService();
Object actual = service.get(commitIndex);
assertEquals(val, actual);
}
});
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable 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.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class LocalRaftTest method testReplicateEntriesConcurrently.
private void testReplicateEntriesConcurrently(int nodeCount) throws ExecutionException, InterruptedException {
final int entryCount = 100;
group = newGroup(nodeCount, newRaftConfigWithNoSnapshotting(entryCount));
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
List<Future> futures = new ArrayList<>(entryCount);
for (int i = 0; i < entryCount; i++) {
Object val = "val" + i;
futures.add(leader.replicate(new ApplyRaftRunnable(val)));
}
for (Future f : futures) {
f.get();
}
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : group.getNodes()) {
assertEquals(entryCount, getCommitIndex(raftNode));
RaftDataService service = group.getService(raftNode);
assertEquals(100, service.size());
Set<Object> values = service.values();
for (int i = 0; i < entryCount; i++) {
Object val = "val" + i;
assertTrue(values.contains(val));
}
}
});
}
Aggregations