Search in sources :

Example 11 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class MetadataRaftGroupTest method when_memberIsShutdown_then_itIsRemovedFromRaftGroups.

@Test
public void when_memberIsShutdown_then_itIsRemovedFromRaftGroups() throws ExecutionException, InterruptedException {
    int cpNodeCount = 7;
    int metadataGroupSize = 5;
    int atomicLong1GroupSize = 3;
    instances = newInstances(cpNodeCount, metadataGroupSize, 0);
    CPGroupId groupId1 = createNewRaftGroup(instances[0], "id1", atomicLong1GroupSize);
    CPGroupId groupId2 = createNewRaftGroup(instances[0], "id2", cpNodeCount);
    CPMember endpoint = findCommonEndpoint(instances[0], getMetadataGroupId(instances[0]), groupId1);
    assertNotNull(endpoint);
    RaftInvocationManager invocationService = null;
    HazelcastInstance aliveInstance = null;
    for (HazelcastInstance instance : instances) {
        if (!getAddress(instance).equals(endpoint.getAddress())) {
            aliveInstance = instance;
            invocationService = getRaftInvocationManager(instance);
            break;
        }
    }
    assertNotNull(invocationService);
    factory.getInstance(endpoint.getAddress()).shutdown();
    CPGroupId metadataGroupId = getMetadataGroupId(aliveInstance);
    InternalCompletableFuture<List<CPMember>> f1 = invocationService.query(metadataGroupId, new GetActiveCPMembersOp(), LINEARIZABLE);
    List<CPMember> activeEndpoints = f1.get();
    assertThat(activeEndpoints, not(hasItem(endpoint)));
    InternalCompletableFuture<CPGroup> f2 = invocationService.query(metadataGroupId, new GetRaftGroupOp(metadataGroupId), LINEARIZABLE);
    InternalCompletableFuture<CPGroup> f3 = invocationService.query(metadataGroupId, new GetRaftGroupOp(groupId1), LINEARIZABLE);
    InternalCompletableFuture<CPGroup> f4 = invocationService.query(metadataGroupId, new GetRaftGroupOp(groupId2), LINEARIZABLE);
    CPGroup metadataGroup = f2.get();
    assertFalse(metadataGroup.members().contains(endpoint));
    assertEquals(metadataGroupSize, metadataGroup.members().size());
    CPGroup atomicLongGroup1 = f3.get();
    assertFalse(atomicLongGroup1.members().contains(endpoint));
    assertEquals(atomicLong1GroupSize, atomicLongGroup1.members().size());
    CPGroup atomicLongGroup2 = f4.get();
    assertFalse(atomicLongGroup2.members().contains(endpoint));
    assertEquals(cpNodeCount - 1, atomicLongGroup2.members().size());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) GetRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) RaftEndpoint(com.hazelcast.cp.internal.raft.impl.RaftEndpoint) GetActiveCPMembersOp(com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class MetadataRaftGroupTest method when_nonReachableEndpointsExist_createRaftGroupPrefersReachableEndpoints.

@Test
public void when_nonReachableEndpointsExist_createRaftGroupPrefersReachableEndpoints() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(5);
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            Collection<CPMemberInfo> raftMembers = getRaftService(instance).getMetadataGroupManager().getActiveMembers();
            assertFalse(raftMembers.isEmpty());
        }
    });
    CPMember endpoint3 = instances[3].getCPSubsystem().getLocalCPMember();
    CPMember endpoint4 = instances[4].getCPSubsystem().getLocalCPMember();
    instances[3].getLifecycleService().terminate();
    instances[4].getLifecycleService().terminate();
    RaftInvocationManager invocationManager = getRaftInvocationManager(instances[0]);
    CPGroupId groupId3 = invocationManager.createRaftGroup("groupId3", 3).get();
    CPGroupId groupId4 = invocationManager.createRaftGroup("g4", 4).get();
    RaftNodeImpl leaderNode = waitAllForLeaderElection(Arrays.copyOf(instances, 3), getMetadataGroupId(instances[0]));
    HazelcastInstance leader = getInstance(leaderNode.getLocalMember());
    CPGroup group3 = queryRaftGroupLocally(leader, groupId3);
    assertNotNull(group3);
    assertThat(group3.members(), not(hasItem(endpoint3)));
    assertThat(group3.members(), not(hasItem(endpoint4)));
    CPGroup group4 = queryRaftGroupLocally(leader, groupId4);
    assertNotNull(group4);
    boolean b3 = group4.members().contains(endpoint3);
    boolean b4 = group4.members().contains(endpoint4);
    assertTrue(b3 ^ b4);
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class RaftInvocationManagerQueryTest method when_queryLocalFromFollower_onStableCluster_thenReadLatestValueEventually.

@Test
public void when_queryLocalFromFollower_onStableCluster_thenReadLatestValueEventually() throws Exception {
    int nodeCount = 3;
    instances = newInstances(nodeCount);
    RaftInvocationManager invocationService = getRaftInvocationManager(instances[0]);
    CPGroupId groupId = invocationService.createRaftGroup("test", nodeCount).get();
    String value = "value";
    invocationService.invoke(groupId, new RaftTestApplyOp(value)).get();
    HazelcastInstance follower = getRandomFollowerInstance(instances, groupId);
    assertTrueEventually(() -> {
        Future<Object> future = getRaftInvocationManager(follower).query(groupId, new RaftTestQueryOp(), ANY_LOCAL);
        assertEquals(value, future.get());
    });
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class RaftInvocationManagerQueryTest method when_queryLocalFromFollower_withLeaderLocalPolicy_thenFail.

@Test
public void when_queryLocalFromFollower_withLeaderLocalPolicy_thenFail() throws Exception {
    int nodeCount = 3;
    instances = newInstances(nodeCount);
    RaftInvocationManager invocationService = getRaftInvocationManager(instances[0]);
    CPGroupId groupId = invocationService.createRaftGroup("test", nodeCount).get();
    String value = "value";
    invocationService.invoke(groupId, new RaftTestApplyOp(value)).get();
    HazelcastInstance follower = getRandomFollowerInstance(instances, groupId);
    Future<Object> future = getRaftInvocationManager(follower).queryLocally(groupId, new RaftTestQueryOp(), LEADER_LOCAL);
    try {
        future.get();
    } catch (ExecutionException e) {
        assertInstanceOf(NotLeaderException.class, e.getCause());
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) NotLeaderException(com.hazelcast.cp.exception.NotLeaderException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ExecutionException(java.util.concurrent.ExecutionException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with CPGroupId

use of com.hazelcast.cp.CPGroupId in project hazelcast by hazelcast.

the class RaftInvocationManagerQueryTest method when_queryLocalFromLeader_onStableCluster_thenReadLatestValue.

@Test
public void when_queryLocalFromLeader_onStableCluster_thenReadLatestValue() throws Exception {
    int nodeCount = 3;
    instances = newInstances(nodeCount);
    RaftInvocationManager invocationService = getRaftInvocationManager(instances[0]);
    CPGroupId groupId = invocationService.createRaftGroup("test", nodeCount).get();
    String value = "value";
    invocationService.invoke(groupId, new RaftTestApplyOp(value)).get();
    Future<Object> future = invocationService.query(groupId, new RaftTestQueryOp(), LEADER_LOCAL);
    assertEquals(value, future.get());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CPGroupId (com.hazelcast.cp.CPGroupId)81 Test (org.junit.Test)50 HazelcastInstance (com.hazelcast.core.HazelcastInstance)42 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)37 QuickTest (com.hazelcast.test.annotation.QuickTest)31 CPGroup (com.hazelcast.cp.CPGroup)14 CPMember (com.hazelcast.cp.CPMember)13 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)11 RaftNodeImpl (com.hazelcast.cp.internal.raft.impl.RaftNodeImpl)9 ArrayList (java.util.ArrayList)8 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 ExecutionException (java.util.concurrent.ExecutionException)7 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)6 SlowTest (com.hazelcast.test.annotation.SlowTest)6 IndeterminateOperationStateException (com.hazelcast.core.IndeterminateOperationStateException)5 MemberLeftException (com.hazelcast.core.MemberLeftException)5 StaleAppendRequestException (com.hazelcast.cp.exception.StaleAppendRequestException)5 DefaultRaftReplicateOp (com.hazelcast.cp.internal.operation.DefaultRaftReplicateOp)5 CallerNotMemberException (com.hazelcast.spi.exception.CallerNotMemberException)5