Search in sources :

Example 41 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture 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) {
    }
}
Also used : LeaderDemotedException(com.hazelcast.cp.exception.LeaderDemotedException) 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 42 with InternalCompletableFuture

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

the class LocalRaftTest method when_leaderStaysInMinority_then_itDemotesItselfToFollower.

@Test
public void when_leaderStaysInMinority_then_itDemotesItselfToFollower() {
    group = newGroup(3);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    group.split(leader.getLocalMember());
    InternalCompletableFuture f = leader.replicate(new ApplyRaftRunnable("val"));
    try {
        f.joinInternal();
        fail();
    } catch (StaleAppendRequestException ignored) {
    }
}
Also used : StaleAppendRequestException(com.hazelcast.cp.exception.StaleAppendRequestException) ApplyRaftRunnable(com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 43 with InternalCompletableFuture

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

the class LeadershipTransferTest method testCannotTransferLeadershipToInvalidEndpoint.

@Test
public void testCannotTransferLeadershipToInvalidEndpoint() throws Exception {
    group = newGroup(3);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    RaftEndpoint invalidEndpoint = newRaftMember(1000);
    InternalCompletableFuture future = leader.transferLeadership(invalidEndpoint);
    exceptionRule.expect(IllegalArgumentException.class);
    future.joinInternal();
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture 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)

Example 45 with InternalCompletableFuture

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

the class LeadershipTransferTest method testCannotReplicateNewEntryDuringLeadershipTransfer.

@Test
public void testCannotReplicateNewEntryDuringLeadershipTransfer() throws Exception {
    group = newGroup(3);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    RaftNodeImpl follower = group.getNodesExcept(leader.getLocalMember())[0];
    group.dropMessagesToMember(leader.getLocalMember(), follower.getLocalMember(), AppendRequest.class);
    leader.replicate(new NopEntry()).get();
    leader.transferLeadership(follower.getLocalMember());
    InternalCompletableFuture f = leader.replicate(new NopEntry());
    exceptionRule.expect(CannotReplicateException.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