Search in sources :

Example 1 with GetRaftGroupOp

use of com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp 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 2 with GetRaftGroupOp

use of com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp in project hazelcast by hazelcast.

the class AtomicLongBasicTest method testRecreate_afterGroupDestroy.

@Test
public void testRecreate_afterGroupDestroy() throws Exception {
    atomicLong.destroy();
    CPGroupId groupId = getGroupId(atomicLong);
    RaftInvocationManager invocationManager = getRaftInvocationManager(instances[0]);
    invocationManager.invoke(getRaftService(instances[0]).getMetadataGroupId(), new TriggerDestroyRaftGroupOp(groupId)).get();
    assertTrueEventually(() -> {
        CPGroup group = invocationManager.<CPGroup>query(getMetadataGroupId(instances[0]), new GetRaftGroupOp(groupId), LINEARIZABLE).join();
        assertEquals(CPGroupStatus.DESTROYED, group.status());
    });
    try {
        atomicLong.incrementAndGet();
        fail();
    } catch (CPGroupDestroyedException ignored) {
    }
    atomicLong = createAtomicLong(name);
    CPGroupId newGroupId = getGroupId(atomicLong);
    assertNotEquals(groupId, newGroupId);
    atomicLong.incrementAndGet();
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) GetRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) TriggerDestroyRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.TriggerDestroyRaftGroupOp) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with GetRaftGroupOp

use of com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp in project hazelcast by hazelcast.

the class CPMemberAddRemoveTest method testRaftMemberIsRemovedForGracefulShutdown.

@Test
public void testRaftMemberIsRemovedForGracefulShutdown() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = newInstances(3, 3, 0);
    CPMember shutdownCPMember = instances[0].getCPSubsystem().getLocalCPMember();
    instances[0].getLifecycleService().shutdown();
    RaftInvocationManager invocationManager = getRaftInvocationManager(instances[1]);
    CPGroupId metadataGroupId = getMetadataGroupId(instances[1]);
    MembershipChangeSchedule schedule = invocationManager.<MembershipChangeSchedule>query(metadataGroupId, new GetMembershipChangeScheduleOp(), LINEARIZABLE).get();
    assertNull(schedule);
    CPGroup group = invocationManager.<CPGroup>invoke(metadataGroupId, new GetRaftGroupOp(metadataGroupId)).join();
    assertEquals(2, group.members().size());
    for (CPMember member : group.members()) {
        assertNotEquals(shutdownCPMember, member);
    }
}
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) GetRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp) GetMembershipChangeScheduleOp(com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp) CPMember(com.hazelcast.cp.CPMember) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 4 with GetRaftGroupOp

use of com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp in project hazelcast by hazelcast.

the class AtomicRefBasicTest method testRecreate_afterGroupDestroy.

@Test
public void testRecreate_afterGroupDestroy() throws Exception {
    atomicRef.destroy();
    CPGroupId groupId = getGroupId(atomicRef);
    RaftInvocationManager invocationManager = getRaftInvocationManager(instances[0]);
    invocationManager.invoke(getRaftService(instances[0]).getMetadataGroupId(), new TriggerDestroyRaftGroupOp(groupId)).get();
    assertTrueEventually(() -> {
        CPGroup group = invocationManager.<CPGroup>invoke(getMetadataGroupId(instances[0]), new GetRaftGroupOp(groupId)).join();
        assertEquals(CPGroupStatus.DESTROYED, group.status());
    });
    try {
        atomicRef.get();
        fail();
    } catch (CPGroupDestroyedException ignored) {
    }
    atomicRef = createAtomicRef(name);
    assertNotEquals(groupId, getGroupId(atomicRef));
    atomicRef.set("str1");
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroup(com.hazelcast.cp.CPGroup) RaftInvocationManager(com.hazelcast.cp.internal.RaftInvocationManager) GetRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) TriggerDestroyRaftGroupOp(com.hazelcast.cp.internal.raftop.metadata.TriggerDestroyRaftGroupOp) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CPGroup (com.hazelcast.cp.CPGroup)4 CPGroupId (com.hazelcast.cp.CPGroupId)4 GetRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.GetRaftGroupOp)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 Test (org.junit.Test)4 QuickTest (com.hazelcast.test.annotation.QuickTest)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 CPMember (com.hazelcast.cp.CPMember)2 CPGroupDestroyedException (com.hazelcast.cp.exception.CPGroupDestroyedException)2 RaftInvocationManager (com.hazelcast.cp.internal.RaftInvocationManager)2 TriggerDestroyRaftGroupOp (com.hazelcast.cp.internal.raftop.metadata.TriggerDestroyRaftGroupOp)2 RaftEndpoint (com.hazelcast.cp.internal.raft.impl.RaftEndpoint)1 GetActiveCPMembersOp (com.hazelcast.cp.internal.raftop.metadata.GetActiveCPMembersOp)1 GetMembershipChangeScheduleOp (com.hazelcast.cp.internal.raftop.metadata.GetMembershipChangeScheduleOp)1 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)1 SlowTest (com.hazelcast.test.annotation.SlowTest)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1