Search in sources :

Example 16 with CPGroupId

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

the class CPGroupRebalanceTest method getLeadershipsMap.

private Map<CPMember, Collection<CPGroupId>> getLeadershipsMap(HazelcastInstance instance, Collection<CPMember> members) {
    OperationServiceImpl operationService = getOperationService(instance);
    Map<CPMember, Collection<CPGroupId>> leaderships = new HashMap<>();
    for (CPMember member : members) {
        Collection<CPGroupId> groups = operationService.<Collection<CPGroupId>>invokeOnTarget(null, new GetLeadedGroupsOp(), member.getAddress()).join();
        leaderships.put(member, groups);
    }
    return leaderships;
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) GetLeadedGroupsOp(com.hazelcast.cp.internal.operation.GetLeadedGroupsOp) HashMap(java.util.HashMap) Collection(java.util.Collection) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) CPMember(com.hazelcast.cp.CPMember)

Example 17 with CPGroupId

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

the class CPMemberAddRemoveTest method testExpandRaftGroupMultipleTimes.

@Test
public void testExpandRaftGroupMultipleTimes() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(5, 5, 3);
    CPGroupId metadataGroupId = getMetadataGroupId(instances[0]);
    waitAllForLeaderElection(Arrays.copyOf(instances, 5), metadataGroupId);
    instances[0].shutdown();
    instances[1].shutdown();
    instances[2].shutdown();
    CPSubsystemManagementService managementService = instances[3].getCPSubsystem().getCPSubsystemManagementService();
    CPGroup group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(2, group.members().size());
    instances[5].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(3, group.members().size());
    Collection<CPMember> members = group.members();
    assertTrue(members.contains(instances[5].getCPSubsystem().getLocalCPMember()));
    assertTrueEventually(() -> assertNotNull(getRaftNode(instances[5], metadataGroupId)));
    instances[6].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(4, group.members().size());
    members = group.members();
    assertTrue(members.contains(instances[6].getCPSubsystem().getLocalCPMember()));
    assertTrueEventually(() -> assertNotNull(getRaftNode(instances[5], metadataGroupId)));
    instances[7].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    group = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    assertEquals(5, group.members().size());
    members = group.members();
    assertTrue(members.contains(instances[7].getCPSubsystem().getLocalCPMember()));
    assertTrueEventually(() -> assertNotNull(getRaftNode(instances[5], metadataGroupId)));
    CPGroup metadataGroup = group;
    HazelcastInstance[] newInstances = { instances[3], instances[4], instances[5], instances[6], instances[7] };
    assertTrueEventually(() -> {
        long commitIndex = getCommitIndex(getLeaderNode(newInstances, metadataGroupId));
        for (int i = 3; i < instances.length; i++) {
            HazelcastInstance instance = instances[i];
            RaftNodeImpl raftNode = getRaftNode(instance, metadataGroupId);
            assertNotNull(raftNode);
            assertEquals(commitIndex, getCommitIndex(raftNode));
            CPGroup g = queryRaftGroupLocally(instance, metadataGroupId);
            assertNotNull(g);
            assertArrayEquals(metadataGroup.members().toArray(new CPMember[0]), g.members().toArray(new CPMember[0]));
        }
    });
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) CPSubsystemManagementService(com.hazelcast.cp.CPSubsystemManagementService) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 18 with CPGroupId

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

the class CPMemberAddRemoveTest method testRemoveMemberFromForceDestroyedRaftGroup.

@Test
public void testRemoveMemberFromForceDestroyedRaftGroup() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3, 3, 0);
    waitAllForLeaderElection(instances, getMetadataGroupId(instances[0]));
    CPGroupId groupId = getRaftInvocationManager(instances[0]).createRaftGroup("test", 2).get();
    CPGroup group = instances[0].getCPSubsystem().getCPSubsystemManagementService().getCPGroup(groupId.getName()).toCompletableFuture().get();
    CPMember crashedMember = group.members().iterator().next();
    HazelcastInstance runningInstance = (getAddress(instances[0])).equals(crashedMember.getAddress()) ? instances[1] : instances[0];
    factory.getInstance(crashedMember.getAddress()).getLifecycleService().terminate();
    CPSubsystemManagementService cpSubsystemManagementService = runningInstance.getCPSubsystem().getCPSubsystemManagementService();
    cpSubsystemManagementService.forceDestroyCPGroup(groupId.getName()).toCompletableFuture().get();
    cpSubsystemManagementService.removeCPMember(crashedMember.getUuid()).toCompletableFuture().get();
    Collection<CPMember> activeMembers = cpSubsystemManagementService.getCPMembers().toCompletableFuture().get();
    assertFalse(activeMembers.contains(crashedMember));
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) CPSubsystemManagementService(com.hazelcast.cp.CPSubsystemManagementService) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 19 with CPGroupId

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

the class AbstractCountDownLatchAdvancedTest method testSuccessfulAwaitClearsWaitTimeouts.

@Test
public void testSuccessfulAwaitClearsWaitTimeouts() {
    latch.trySetCount(1);
    CPGroupId groupId = getGroupId(latch);
    HazelcastInstance leader = leaderInstanceOf(groupId);
    CountDownLatchService service = getNodeEngineImpl(leader).getService(CountDownLatchService.SERVICE_NAME);
    CountDownLatchRegistry registry = service.getRegistryOrNull(groupId);
    CountDownLatch threadLatch = new CountDownLatch(1);
    spawn(() -> {
        try {
            latch.await(10, MINUTES);
            threadLatch.countDown();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
    assertTrueEventually(() -> {
        assertFalse(registry.getWaitTimeouts().isEmpty());
        assertFalse(registry.getLiveOperations().isEmpty());
    });
    latch.countDown();
    assertOpenEventually(threadLatch);
    assertTrue(registry.getWaitTimeouts().isEmpty());
    assertTrue(registry.getLiveOperations().isEmpty());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 20 with CPGroupId

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

the class AbstractCountDownLatchAdvancedTest method testFailedAwaitClearsWaitTimeouts.

@Test
public void testFailedAwaitClearsWaitTimeouts() throws InterruptedException {
    latch.trySetCount(1);
    CPGroupId groupId = getGroupId(latch);
    HazelcastInstance leader = leaderInstanceOf(groupId);
    CountDownLatchService service = getNodeEngineImpl(leader).getService(CountDownLatchService.SERVICE_NAME);
    CountDownLatchRegistry registry = service.getRegistryOrNull(groupId);
    boolean success = latch.await(1, TimeUnit.SECONDS);
    assertFalse(success);
    assertTrue(registry.getWaitTimeouts().isEmpty());
    assertTrue(registry.getLiveOperations().isEmpty());
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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