Search in sources :

Example 31 with RaftAlgorithmConfig

use of com.hazelcast.config.cp.RaftAlgorithmConfig 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 32 with RaftAlgorithmConfig

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

the class SnapshotTest method when_commitLogAdvances_then_snapshotIsTaken.

@Test
public void when_commitLogAdvances_then_snapshotIsTaken() 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());
            RaftDataService service = group.getService(raftNode);
            assertEquals(entryCount, service.size());
            for (int i = 0; i < entryCount; i++) {
                assertEquals(("val" + i), service.get(i + 1));
            }
        }
    });
}
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)

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