Search in sources :

Example 66 with CPGroupId

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

the class FencedLockAdvancedTest method testNewRaftGroupMemberSchedulesTimeoutsWithSnapshot.

@Test
public void testNewRaftGroupMemberSchedulesTimeoutsWithSnapshot() throws ExecutionException, InterruptedException {
    long fence = this.lock.lockAndGetFence();
    assertTrue(fence > 0);
    spawn(() -> {
        lock.tryLock(10, MINUTES);
    });
    CPGroupId groupId = this.lock.getGroupId();
    assertTrueEventually(() -> {
        HazelcastInstance leader = getLeaderInstance(instances, groupId);
        LockService service = getNodeEngineImpl(leader).getService(LockService.SERVICE_NAME);
        ResourceRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        assertFalse(registry.getWaitTimeouts().isEmpty());
    });
    spawn(() -> {
        for (int i = 0; i < LOG_ENTRY_COUNT_TO_SNAPSHOT; i++) {
            lock.isLocked();
        }
    });
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            RaftNodeImpl raftNode = getRaftNode(instance, groupId);
            assertNotNull(raftNode);
            LogEntry snapshotEntry = getSnapshotEntry(raftNode);
            assertTrue(snapshotEntry.index() > 0);
            List<RestoreSnapshotOp> ops = (List<RestoreSnapshotOp>) snapshotEntry.operation();
            for (RestoreSnapshotOp op : ops) {
                if (op.getServiceName().equals(LockService.SERVICE_NAME)) {
                    ResourceRegistry registry = (ResourceRegistry) op.getSnapshot();
                    assertFalse(registry.getWaitTimeouts().isEmpty());
                    return;
                }
            }
            fail();
        }
    });
    HazelcastInstance instanceToShutdown = (instances[0] == proxyInstance) ? instances[1] : instances[0];
    instanceToShutdown.shutdown();
    HazelcastInstance newInstance = factory.newHazelcastInstance(createConfig(groupSize, groupSize));
    newInstance.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    assertTrueEventually(() -> {
        RaftNodeImpl raftNode = getRaftNode(newInstance, groupId);
        assertNotNull(raftNode);
        assertTrue(getSnapshotEntry(raftNode).index() > 0);
        LockService service = getNodeEngineImpl(newInstance).getService(LockService.SERVICE_NAME);
        LockRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        assertFalse(registry.getWaitTimeouts().isEmpty());
        LockOwnershipState ownership = registry.getLockOwnershipState(objectName);
        assertTrue(ownership.isLocked());
        assertTrue(ownership.getLockCount() > 0);
        assertEquals(fence, ownership.getFence());
    });
}
Also used : RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RestoreSnapshotOp(com.hazelcast.cp.internal.raftop.snapshot.RestoreSnapshotOp) ResourceRegistry(com.hazelcast.cp.internal.datastructures.spi.blocking.ResourceRegistry) CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) List(java.util.List) LogEntry(com.hazelcast.cp.internal.raft.impl.log.LogEntry) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 67 with CPGroupId

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

the class CPMemberAddRemoveTest method testExpandMultipleRaftGroupsMultipleTimes.

@Test
public void testExpandMultipleRaftGroupsMultipleTimes() throws ExecutionException, InterruptedException, TimeoutException {
    HazelcastInstance[] instances = newInstances(5, 5, 2);
    CPGroupId metadataGroupId = getMetadataGroupId(instances[0]);
    CPSubsystemManagementService managementService = instances[6].getCPSubsystem().getCPSubsystemManagementService();
    String groupName = "group1";
    instances[0].getCPSubsystem().getAtomicLong("long1@" + groupName).set(5);
    CPGroup otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
    CPGroupId groupId = otherGroup.id();
    waitAllForLeaderElection(Arrays.copyOf(instances, 5), groupId);
    CPMember[] otherGroupMembers = otherGroup.members().toArray(new CPMember[0]);
    List<Address> shutdownAddresses = asList(otherGroupMembers[0].getAddress(), otherGroupMembers[1].getAddress());
    instances[5].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get(30, TimeUnit.SECONDS);
    HazelcastInstance[] runningInstances = new HazelcastInstance[instances.length - shutdownAddresses.size()];
    for (int i = 0, j = 0; i < instances.length; i++) {
        HazelcastInstance instance = instances[i];
        if (shutdownAddresses.contains(getAddress(instance))) {
            instance.shutdown();
        } else {
            runningInstances[j++] = instance;
        }
    }
    CPGroup metadataGroup = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
    assertEquals(4, metadataGroup.members().size());
    assertEquals(4, otherGroup.members().size());
    assertTrueEventually(() -> {
        assertNotNull(getRaftNode(instances[5], metadataGroupId));
        assertNotNull(getRaftNode(instances[5], groupId));
    });
    instances[6].getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get(30, TimeUnit.SECONDS);
    metadataGroup = managementService.getCPGroup(metadataGroupId.getName()).toCompletableFuture().get();
    otherGroup = managementService.getCPGroup(groupName).toCompletableFuture().get();
    assertEquals(5, metadataGroup.members().size());
    assertEquals(5, otherGroup.members().size());
    CPGroup metadataGroupRef = metadataGroup;
    CPGroup otherGroupRef = otherGroup;
    assertTrueEventually(() -> {
        long commitIndex = getCommitIndex(getLeaderNode(runningInstances, metadataGroupId));
        assertNotNull(getRaftNode(instances[6], groupId));
        for (HazelcastInstance instance : asList(instances[5], instances[6])) {
            RaftNodeImpl raftNode = getRaftNode(instance, metadataGroupId);
            assertNotNull(raftNode);
            assertEquals(commitIndex, getCommitIndex(raftNode));
            CPGroup g1 = queryRaftGroupLocally(instance, metadataGroupId);
            CPGroup g2 = queryRaftGroupLocally(instance, otherGroupRef.id());
            assertNotNull(g1);
            assertNotNull(g2);
            assertArrayEquals(metadataGroupRef.members().toArray(new CPMember[0]), g1.members().toArray(new CPMember[0]));
            assertArrayEquals(otherGroupRef.members().toArray(new CPMember[0]), g2.members().toArray(new CPMember[0]));
        }
    });
}
Also used : Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) CPMember(com.hazelcast.cp.CPMember) 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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 68 with CPGroupId

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

the class AbstractCountDownLatchAdvancedTest method testDestroyClearsWaitTimeouts.

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

Example 69 with CPGroupId

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

the class CountDownLatchAdvancedTest method testNewRaftGroupMemberSchedulesTimeoutsWithSnapshot.

@Test
public void testNewRaftGroupMemberSchedulesTimeoutsWithSnapshot() throws ExecutionException, InterruptedException {
    latch.trySetCount(1);
    spawn(() -> {
        try {
            latch.await(10, MINUTES);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
    CPGroupId groupId = getGroupId(latch);
    assertTrueEventually(() -> {
        HazelcastInstance leader = getLeaderInstance(instances, groupId);
        CountDownLatchService service = getNodeEngineImpl(leader).getService(CountDownLatchService.SERVICE_NAME);
        ResourceRegistry registry = service.getRegistryOrNull(groupId);
        assertFalse(registry.getWaitTimeouts().isEmpty());
    });
    for (int i = 0; i < LOG_ENTRY_COUNT_TO_SNAPSHOT; i++) {
        latch.trySetCount(1);
    }
    assertTrueEventually(() -> {
        for (HazelcastInstance instance : instances) {
            RaftNodeImpl raftNode = getRaftNode(instance, groupId);
            assertNotNull(raftNode);
            LogEntry snapshotEntry = getSnapshotEntry(raftNode);
            assertTrue(snapshotEntry.index() > 0);
            List<RestoreSnapshotOp> ops = (List<RestoreSnapshotOp>) snapshotEntry.operation();
            for (RestoreSnapshotOp op : ops) {
                if (op.getServiceName().equals(CountDownLatchService.SERVICE_NAME)) {
                    ResourceRegistry registry = (ResourceRegistry) op.getSnapshot();
                    assertFalse(registry.getWaitTimeouts().isEmpty());
                    return;
                }
            }
            fail();
        }
    });
    instances[1].shutdown();
    HazelcastInstance newInstance = factory.newHazelcastInstance(createConfig(groupSize, groupSize));
    newInstance.getCPSubsystem().getCPSubsystemManagementService().promoteToCPMember().toCompletableFuture().get();
    assertTrueEventually(() -> {
        CountDownLatchService service = getNodeEngineImpl(newInstance).getService(CountDownLatchService.SERVICE_NAME);
        CountDownLatchRegistry registry = service.getRegistryOrNull(groupId);
        assertNotNull(registry);
        assertFalse(registry.getWaitTimeouts().isEmpty());
        Assert.assertEquals(1, registry.getRemainingCount(objectName));
    });
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RaftNodeImpl(com.hazelcast.cp.internal.raft.impl.RaftNodeImpl) RestoreSnapshotOp(com.hazelcast.cp.internal.raftop.snapshot.RestoreSnapshotOp) List(java.util.List) ResourceRegistry(com.hazelcast.cp.internal.datastructures.spi.blocking.ResourceRegistry) LogEntry(com.hazelcast.cp.internal.raft.impl.log.LogEntry) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 70 with CPGroupId

use of com.hazelcast.cp.CPGroupId 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

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