Search in sources :

Example 6 with NopEntry

use of com.hazelcast.cp.internal.raft.impl.testing.NopEntry in project hazelcast by hazelcast.

the class LeadershipTransferTest method testDuplicateTransferLeadershipRequestsHandled.

@Test
public void testDuplicateTransferLeadershipRequestsHandled() 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();
    Future f1 = leader.transferLeadership(follower.getLocalMember());
    Future f2 = leader.transferLeadership(follower.getLocalMember());
    group.allowAllMessagesToMember(leader.getLocalMember(), follower.getLocalMember());
    f1.get();
    f2.get();
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) 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 7 with NopEntry

use of com.hazelcast.cp.internal.raft.impl.testing.NopEntry in project hazelcast by hazelcast.

the class LeadershipTransferTest method testInflightOperationsCommittedByCurrentLeaderBeforeLeadershipTransfer.

@Test
public void testInflightOperationsCommittedByCurrentLeaderBeforeLeadershipTransfer() throws Exception {
    group = newGroup(3);
    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);
    Future f1 = leader.replicate(new NopEntry());
    Future f2 = leader.transferLeadership(followers[0].getLocalMember());
    group.allowAllMessagesToMember(leader.getLocalMember(), followers[0].getLocalMember());
    group.allowAllMessagesToMember(leader.getLocalMember(), followers[1].getLocalMember());
    f2.get();
    RaftNodeImpl newLeader = group.waitUntilLeaderElected();
    assertNotSame(leader, newLeader);
    f1.get();
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Future(java.util.concurrent.Future) 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 8 with NopEntry

use of com.hazelcast.cp.internal.raft.impl.testing.NopEntry in project hazelcast by hazelcast.

the class LeadershipTransferTest method testTransferLeadershipTimesOutWhenTargetCannotCatchupInTime.

@Test
public void testTransferLeadershipTimesOutWhenTargetCannotCatchupInTime() 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();
    InternalCompletableFuture f = leader.transferLeadership(follower.getLocalMember());
    exceptionRule.expect(IllegalStateException.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)

Example 9 with NopEntry

use of com.hazelcast.cp.internal.raft.impl.testing.NopEntry in project hazelcast by hazelcast.

the class LeadershipTransferTest method testAnotherTransferLeadershipRequestFailsDuringOngoingLeadershipTransfer.

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

NopEntry (com.hazelcast.cp.internal.raft.impl.testing.NopEntry)9 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 Future (java.util.concurrent.Future)4 RaftAlgorithmConfig (com.hazelcast.config.cp.RaftAlgorithmConfig)1 LocalRaftGroupBuilder (com.hazelcast.cp.internal.raft.impl.testing.LocalRaftGroup.LocalRaftGroupBuilder)1