Search in sources :

Example 1 with NopEntry

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

the class LeadershipTransferTest method testTransferLeadershipWhenEntriesAppended.

@Test
public void testTransferLeadershipWhenEntriesAppended() throws Exception {
    group = newGroup(3);
    group.start();
    RaftNodeImpl leader = group.waitUntilLeaderElected();
    int term1 = getTerm(leader);
    leader.replicate(new NopEntry()).get();
    RaftNodeImpl follower = group.getNodesExcept(leader.getLocalMember())[0];
    Future f = leader.transferLeadership(follower.getLocalMember());
    f.get();
    RaftNodeImpl newLeader = group.waitUntilLeaderElected();
    int term2 = getTerm(newLeader);
    assertNotSame(leader, newLeader);
    assertTrue(term2 > term1);
    assertEquals(RaftRole.FOLLOWER, getRole(leader));
}
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 2 with NopEntry

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

the class LeadershipTransferTest method testNewLeaderCommitsAfterLeadershipTransfer.

@Test
public void testNewLeaderCommitsAfterLeadershipTransfer() 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);
    Future f = newLeader.replicate(new NopEntry());
    f.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 3 with NopEntry

use of com.hazelcast.cp.internal.raft.impl.testing.NopEntry 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 4 with NopEntry

use of com.hazelcast.cp.internal.raft.impl.testing.NopEntry 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)

Example 5 with NopEntry

use of com.hazelcast.cp.internal.raft.impl.testing.NopEntry 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

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