Search in sources :

Example 11 with RaftAlgorithmConfig

use of com.hazelcast.config.cp.RaftAlgorithmConfig 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) {
    }
}
Also used : RaftAlgorithmConfig(com.hazelcast.config.cp.RaftAlgorithmConfig) ApplyRaftRunnable(com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable) CannotReplicateException(com.hazelcast.cp.exception.CannotReplicateException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with RaftAlgorithmConfig

use of com.hazelcast.config.cp.RaftAlgorithmConfig in project hazelcast by hazelcast.

the class SnapshotTest method when_followersMatchIndexIsUnknown_then_itInstallsSnapshot.

@Test
public void when_followersMatchIndexIsUnknown_then_itInstallsSnapshot() throws ExecutionException, InterruptedException {
    final 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());
    RaftNodeImpl slowFollower = followers[1];
    group.dropMessagesToMember(leader.getLocalMember(), slowFollower.getLocalMember(), AppendRequest.class);
    group.dropMessagesToMember(leader.getLocalMember(), slowFollower.getLocalMember(), InstallSnapshot.class);
    for (int i = 0; i < entryCount; i++) {
        leader.replicate(new ApplyRaftRunnable("val" + i)).get();
    }
    assertTrueEventually(() -> assertEquals(entryCount, getSnapshotEntry(leader).index()));
    leader.replicate(new ApplyRaftRunnable("valFinal")).get();
    group.allowMessagesToMember(leader.getLocalMember(), slowFollower.getLocalMember(), InstallSnapshot.class);
    assertTrueEventually(() -> assertEquals(entryCount, getCommitIndex(slowFollower)));
    group.resetAllRulesFrom(leader.getLocalMember());
    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));
        }
    });
}
Also used : RaftAlgorithmConfig(com.hazelcast.config.cp.RaftAlgorithmConfig) ApplyRaftRunnable(com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable) RaftDataService(com.hazelcast.cp.internal.raft.impl.dataservice.RaftDataService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with RaftAlgorithmConfig

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

Example 14 with RaftAlgorithmConfig

use of com.hazelcast.config.cp.RaftAlgorithmConfig in project hazelcast by hazelcast.

the class SnapshotTest method when_followersLastAppendIsMembershipChange_then_itUpdatesRaftNodeStateWithInstalledSnapshot.

@Test
public void when_followersLastAppendIsMembershipChange_then_itUpdatesRaftNodeStateWithInstalledSnapshot() throws ExecutionException, InterruptedException {
    final int entryCount = 50;
    final RaftAlgorithmConfig config = new RaftAlgorithmConfig().setCommitIndexAdvanceCountToSnapshot(entryCount);
    group = newGroup(5, config);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    RaftNodeImpl[] followers = group.getNodesExcept(leader.getLocalMember());
    leader.replicate(new ApplyRaftRunnable("val")).get();
    assertTrueEventually(() -> {
        for (RaftNodeImpl follower : followers) {
            assertEquals(1L, getCommitIndex(follower));
        }
    });
    RaftNodeImpl slowFollower = followers[0];
    for (RaftNodeImpl follower : followers) {
        if (follower != slowFollower) {
            group.dropMessagesToMember(follower.getLocalMember(), follower.getLeader(), AppendSuccessResponse.class);
            group.dropMessagesToMember(follower.getLocalMember(), follower.getLeader(), AppendFailureResponse.class);
        }
    }
    RaftNodeImpl newRaftNode1 = group.createNewRaftNode();
    Future f1 = leader.replicateMembershipChange(newRaftNode1.getLocalMember(), MembershipChangeMode.ADD);
    assertTrueEventually(() -> {
        for (RaftNodeImpl follower : followers) {
            assertEquals(2L, getLastLogOrSnapshotEntry(follower).index());
        }
    });
    group.dropMessagesToMember(leader.getLocalMember(), slowFollower.getLocalMember(), AppendRequest.class);
    group.dropMessagesToMember(leader.getLocalMember(), slowFollower.getLocalMember(), InstallSnapshot.class);
    for (RaftNodeImpl follower : followers) {
        if (follower != slowFollower) {
            group.allowAllMessagesToMember(follower.getLocalMember(), leader.getLeader());
        }
    }
    f1.get();
    for (int i = 0; i < entryCount; i++) {
        leader.replicate(new ApplyRaftRunnable("val" + i)).get();
    }
    assertTrueEventually(() -> assertThat(getSnapshotEntry(leader).index(), greaterThanOrEqualTo((long) entryCount)));
    group.allowAllMessagesToMember(leader.getLeader(), slowFollower.getLocalMember());
    assertTrueEventually(() -> assertThat(getSnapshotEntry(slowFollower).index(), greaterThanOrEqualTo((long) entryCount)));
    assertTrueEventually(() -> {
        assertEquals(getCommittedGroupMembers(leader).index(), getCommittedGroupMembers(slowFollower).index());
        assertEquals(ACTIVE, getStatus(slowFollower));
    });
}
Also used : RaftAlgorithmConfig(com.hazelcast.config.cp.RaftAlgorithmConfig) ApplyRaftRunnable(com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with RaftAlgorithmConfig

use of com.hazelcast.config.cp.RaftAlgorithmConfig in project hazelcast by hazelcast.

the class LeadershipTransferTest method testCannotTransferLeadershipWhileChangingMemberList.

@Test
public void testCannotTransferLeadershipWhileChangingMemberList() throws Exception {
    RaftAlgorithmConfig config = new RaftAlgorithmConfig().setLeaderHeartbeatPeriodInMillis(SECONDS.toMillis(30));
    group = new LocalRaftGroupBuilder(3, config).build();
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    leader.replicate(new NopEntry()).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);
    leader.replicateMembershipChange(followers[0].getLocalMember(), MembershipChangeMode.REMOVE);
    InternalCompletableFuture f = leader.transferLeadership(followers[0].getLocalMember());
    exceptionRule.expect(IllegalStateException.class);
    f.joinInternal();
}
Also used : RaftAlgorithmConfig(com.hazelcast.config.cp.RaftAlgorithmConfig) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) LocalRaftGroupBuilder(com.hazelcast.cp.internal.raft.impl.testing.LocalRaftGroup.LocalRaftGroupBuilder) 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

RaftAlgorithmConfig (com.hazelcast.config.cp.RaftAlgorithmConfig)32 QuickTest (com.hazelcast.test.annotation.QuickTest)28 Test (org.junit.Test)28 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)27 ApplyRaftRunnable (com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable)23 RaftDataService (com.hazelcast.cp.internal.raft.impl.dataservice.RaftDataService)14 LocalRaftGroupBuilder (com.hazelcast.cp.internal.raft.impl.testing.LocalRaftGroup.LocalRaftGroupBuilder)9 RestoredRaftState (com.hazelcast.cp.internal.raft.impl.persistence.RestoredRaftState)8 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)7 InMemoryRaftStateStore (com.hazelcast.cp.internal.raft.impl.testing.InMemoryRaftStateStore)6 CPSubsystemConfig (com.hazelcast.config.cp.CPSubsystemConfig)4 FencedLockConfig (com.hazelcast.config.cp.FencedLockConfig)4 SemaphoreConfig (com.hazelcast.config.cp.SemaphoreConfig)4 StaleAppendRequestException (com.hazelcast.cp.exception.StaleAppendRequestException)3 KerberosAuthenticationConfig (com.hazelcast.config.security.KerberosAuthenticationConfig)2 KerberosIdentityConfig (com.hazelcast.config.security.KerberosIdentityConfig)2 LdapAuthenticationConfig (com.hazelcast.config.security.LdapAuthenticationConfig)2 RealmConfig (com.hazelcast.config.security.RealmConfig)2 SimpleAuthenticationConfig (com.hazelcast.config.security.SimpleAuthenticationConfig)2 CannotReplicateException (com.hazelcast.cp.exception.CannotReplicateException)2