Search in sources :

Example 71 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class LocalRaftTest method when_leaderStaysInMinorityDuringSplit_then_itCannotCommitNewEntries.

@Test
public void when_leaderStaysInMinorityDuringSplit_then_itCannotCommitNewEntries() throws ExecutionException, InterruptedException {
    group = newGroup(3, newRaftConfigWithNoSnapshotting(100));
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    leader.replicate(new ApplyRaftRunnable("val1")).get();
    assertTrueEventually(() -> {
        for (RaftNodeImpl raftNode : group.getNodes()) {
            assertEquals(1, getCommitIndex(raftNode));
        }
    });
    RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
    group.split(leader.getLocalMember());
    assertTrueEventually(() -> {
        for (RaftNodeImpl raftNode : followers) {
            RaftEndpoint leaderEndpoint = getLeaderMember(raftNode);
            assertNotNull(leaderEndpoint);
            assertNotEquals(leader.getLocalMember(), leaderEndpoint);
        }
    });
    List<InternalCompletableFuture> isolatedFutures = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        isolatedFutures.add(leader.replicate(new ApplyRaftRunnable("isolated" + i)));
    }
    RaftNodeImpl newLeader = group.getNode(getLeaderMember(followers[0]));
    for (int i = 0; i < 10; i++) {
        newLeader.replicate(new ApplyRaftRunnable("valNew" + i)).get();
    }
    assertTrueEventually(() -> {
        for (RaftNodeImpl raftNode : followers) {
            assertEquals(11, getCommitIndex(raftNode));
        }
    });
    group.merge();
    RaftNodeImpl finalLeader = group.waitUntilLeaderElected();
    assertNotEquals(leader.getLocalMember(), finalLeader.getLocalMember());
    for (InternalCompletableFuture f : isolatedFutures) {
        try {
            f.joinInternal();
            fail();
        } catch (LeaderDemotedException ignored) {
        }
    }
    assertTrueEventually(() -> {
        for (RaftNodeImpl raftNode : followers) {
            RaftDataService service = group.getService(raftNode);
            assertEquals(11, service.size());
            assertEquals("val1", service.get(1));
            for (int i = 0; i < 10; i++) {
                assertEquals(("valNew" + i), service.get(i + 2));
            }
        }
    });
}
Also used : LeaderDemotedException(com.hazelcast.cp.exception.LeaderDemotedException) ApplyRaftRunnable(com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable) RaftDataService(com.hazelcast.cp.internal.raft.impl.dataservice.RaftDataService) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ArrayList(java.util.ArrayList) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 72 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class MembershipChangeTest method when_leaderIsSteppingDown_then_itDoesNotAcceptNewAppends.

@Test
public void when_leaderIsSteppingDown_then_itDoesNotAcceptNewAppends() throws ExecutionException, InterruptedException {
    group = new LocalRaftGroupBuilder(3).setAppendNopEntryOnLeaderElection(true).build();
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
    group.dropMessagesToMember(leader.getLocalMember(), followers[0].getLocalMember(), AppendRequest.class);
    group.dropMessagesToMember(leader.getLocalMember(), followers[1].getLocalMember(), AppendRequest.class);
    InternalCompletableFuture f1 = leader.replicateMembershipChange(leader.getLocalMember(), REMOVE);
    InternalCompletableFuture f2 = leader.replicate(new PostponedResponseRaftRunnable());
    assertFalse(f1.isDone());
    assertTrueEventually(() -> assertTrue(f2.isDone()));
    try {
        f2.joinInternal();
        fail();
    } catch (CannotReplicateException ignored) {
    }
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) LocalRaftGroupBuilder(com.hazelcast.cp.internal.raft.impl.testing.LocalRaftGroup.LocalRaftGroupBuilder) CannotReplicateException(com.hazelcast.cp.exception.CannotReplicateException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 73 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture 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);
}
Also used : ApplyRaftRunnable(com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) QueryRaftRunnable(com.hazelcast.cp.internal.raft.impl.dataservice.QueryRaftRunnable) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 74 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class SnapshotTest method when_isolatedLeaderAppendsEntries_then_itInvalidatesTheirFeaturesUponInstallSnapshot.

@Test
public void when_isolatedLeaderAppendsEntries_then_itInvalidatesTheirFeaturesUponInstallSnapshot() throws ExecutionException, InterruptedException {
    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());
    for (int i = 0; i < 40; i++) {
        leader.replicate(new ApplyRaftRunnable("val" + i)).get();
    }
    assertTrueEventually(() -> {
        for (RaftNodeImpl raftNode : group.getNodes()) {
            assertEquals(40, getCommitIndex(raftNode));
        }
    });
    group.split(leader.getLocalMember());
    assertTrueEventually(() -> {
        for (RaftNodeImpl raftNode : followers) {
            RaftEndpoint leaderEndpoint = getLeaderMember(raftNode);
            assertNotNull(leaderEndpoint);
            assertNotEquals(leader.getLocalMember(), leaderEndpoint);
        }
    });
    List<InternalCompletableFuture> futures = new ArrayList<>();
    for (int i = 40; i < 45; i++) {
        InternalCompletableFuture f = leader.replicate(new ApplyRaftRunnable("isolated" + i));
        futures.add(f);
    }
    RaftNodeImpl newLeader = group.getNode(getLeaderMember(followers[0]));
    for (int i = 40; i < 51; i++) {
        newLeader.replicate(new ApplyRaftRunnable("val" + i)).get();
    }
    assertTrueEventually(() -> {
        for (RaftNodeImpl raftNode : followers) {
            assertTrue(getSnapshotEntry(raftNode).index() > 0);
        }
    });
    group.dropMessagesToMember(leader.getLocalMember(), followers[0].getLocalMember(), AppendRequest.class);
    group.dropMessagesToMember(leader.getLocalMember(), followers[1].getLocalMember(), AppendRequest.class);
    group.merge();
    for (InternalCompletableFuture f : futures) {
        try {
            f.joinInternal();
            fail();
        } catch (StaleAppendRequestException ignored) {
        }
    }
    assertTrueEventually(() -> {
        for (RaftNodeImpl raftNode : group.getNodes()) {
            assertEquals(51, getCommitIndex(raftNode));
            RaftDataService service = group.getService(raftNode);
            assertEquals(51, service.size());
            for (int i = 0; i < 51; i++) {
                assertEquals(("val" + i), service.get(i + 1));
            }
        }
    });
}
Also used : RaftAlgorithmConfig(com.hazelcast.config.cp.RaftAlgorithmConfig) StaleAppendRequestException(com.hazelcast.cp.exception.StaleAppendRequestException) ApplyRaftRunnable(com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable) RaftDataService(com.hazelcast.cp.internal.raft.impl.dataservice.RaftDataService) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ArrayList(java.util.ArrayList) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 75 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class LeadershipTransferTest method testOldLeaderCannotReplicateAfterLeadershipTransfer.

@Test
public void testOldLeaderCannotReplicateAfterLeadershipTransfer() throws Exception {
    group = newGroup(3);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    RaftNodeImpl follower = group.getNodesExcept(leader.getLocalMember())[0];
    leader.transferLeadership(follower.getLocalMember()).get();
    RaftNodeImpl newLeader = group.waitUntilLeaderElected();
    assertNotSame(leader, newLeader);
    InternalCompletableFuture f = leader.replicate(new NopEntry());
    exceptionRule.expect(NotLeaderException.class);
    f.joinInternal();
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) NopEntry(com.hazelcast.cp.internal.raft.impl.testing.NopEntry) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)90 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)47 QuickTest (com.hazelcast.test.annotation.QuickTest)47 Test (org.junit.Test)47 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)19 HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 Accessors.getOperationService (com.hazelcast.test.Accessors.getOperationService)15 Data (com.hazelcast.internal.serialization.Data)10 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 UUID (java.util.UUID)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Member (com.hazelcast.cluster.Member)7 ApplyRaftRunnable (com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable)7 Future (java.util.concurrent.Future)7 Address (com.hazelcast.cluster.Address)6 List (java.util.List)6 BiConsumer (java.util.function.BiConsumer)6 Nonnull (javax.annotation.Nonnull)6