use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class DestroyRaftGroupTest method when_destroyOpIsAppendedButNotCommitted_then_cannotAppendNewEntry.
@Test
public void when_destroyOpIsAppendedButNotCommitted_then_cannotAppendNewEntry() throws ExecutionException, InterruptedException {
group = newGroup(2);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl follower = group.getAnyFollowerNode();
group.dropAllMessagesToMember(leader.getLocalMember(), follower.getLocalMember());
leader.replicate(new DestroyRaftGroupCmd());
try {
leader.replicate(new ApplyRaftRunnable("val")).joinInternal();
fail();
} catch (CannotReplicateException ignored) {
}
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class LinearizableQueryTest method when_newCommitIsDoneWhileThereIsWaitingQuery_then_queryRunsAfterNewCommit.
@Test(timeout = 300_000)
public void when_newCommitIsDoneWhileThereIsWaitingQuery_then_queryRunsAfterNewCommit() 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 queryFuture = leader.query(new QueryRaftRunnable(), LINEARIZABLE);
group.resetAllRulesFrom(leader.getLocalMember());
replicateFuture.get();
Object o = queryFuture.get();
assertEquals("value2", o);
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class LocalRaftTest method testReplicateEntriesInParallel.
private void testReplicateEntriesInParallel(int nodeCount) throws InterruptedException {
int threadCount = 10;
final int opsPerThread = 10;
group = newGroup(nodeCount, newRaftConfigWithNoSnapshotting(threadCount * opsPerThread));
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threadCount; i++) {
int start = i * opsPerThread;
threads[i] = new Thread(() -> {
List<Future> futures = new ArrayList<>();
for (int j = start; j < start + opsPerThread; j++) {
futures.add(leader.replicate(new ApplyRaftRunnable(j)));
}
for (Future f : futures) {
try {
f.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
});
}
for (Thread thread : threads) {
thread.start();
}
for (Thread thread : threads) {
thread.join();
}
int entryCount = threadCount * opsPerThread;
assertTrueEventually(() -> {
for (RaftNodeImpl raftNode : group.getNodes()) {
assertEquals(entryCount, getCommitIndex(raftNode));
RaftDataService service = group.getService(raftNode);
assertEquals(entryCount, service.size());
Set<Object> values = service.values();
for (int i = 0; i < entryCount; i++) {
assertTrue(values.contains(i));
}
}
});
}
use of com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable in project hazelcast by hazelcast.
the class LocalRaftTest method when_followerAttemptsToReplicate_then_itFails.
@Test
public void when_followerAttemptsToReplicate_then_itFails() throws ExecutionException, InterruptedException {
group = newGroup(3);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
try {
followers[0].replicate(new ApplyRaftRunnable("val")).joinInternal();
fail("NotLeaderException should have been thrown");
} catch (NotLeaderException e) {
ignore(e);
}
for (RaftNodeImpl raftNode : group.getNodes()) {
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_leaderAppendsToMinority_then_itCannotCommit.
@Test
public void when_leaderAppendsToMinority_then_itCannotCommit() throws ExecutionException, InterruptedException {
group = newGroup(5);
group.start();
RaftNodeImpl leader = group.waitUntilLeaderElected();
RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
for (int i = 1; i < followers.length; i++) {
group.dropMessagesToMember(leader.getLocalMember(), followers[i].getLocalMember(), AppendRequest.class);
}
Future f = leader.replicate(new ApplyRaftRunnable("val"));
assertTrueEventually(() -> {
assertEquals(1, getLastLogOrSnapshotEntry(leader).index());
assertEquals(1, getLastLogOrSnapshotEntry(followers[0]).index());
});
try {
f.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());
}
}
Aggregations