Search in sources :

Example 41 with CPGroupId

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

the class RaftInvocationManagerTest method when_raftGroupIsCreated_then_raftOperationsAreExecutedOnNonCPNode.

@Test
public void when_raftGroupIsCreated_then_raftOperationsAreExecutedOnNonCPNode() throws ExecutionException, InterruptedException {
    int cpNodeCount = 5;
    instances = newInstances(cpNodeCount, 3, 1);
    RaftInvocationManager invocationService = getRaftInvocationManager(instances[instances.length - 1]);
    CPGroupId groupId = invocationService.createRaftGroup("test", cpNodeCount).get();
    for (int i = 0; i < 100; i++) {
        invocationService.invoke(groupId, new RaftTestApplyOp("val" + i)).get();
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 42 with CPGroupId

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

the class RaftInvocationManagerTest method when_raftGroupIsDestroyed_then_operationsEventuallyFail.

@Test
public void when_raftGroupIsDestroyed_then_operationsEventuallyFail() throws ExecutionException, InterruptedException {
    int nodeCount = 3;
    instances = newInstances(nodeCount);
    RaftInvocationManager invocationManager = getRaftInvocationManager(instances[0]);
    CPGroupId groupId = invocationManager.createRaftGroup("test", nodeCount).get();
    invocationManager.invoke(groupId, new RaftTestApplyOp("val")).get();
    invocationManager.invoke(getRaftService(instances[0]).getMetadataGroupId(), new TriggerDestroyRaftGroupOp(groupId)).get();
    assertTrueEventually(() -> {
        try {
            invocationManager.invoke(groupId, new RaftTestApplyOp("val")).get();
            fail();
        } catch (ExecutionException e) {
            assertInstanceOf(CPGroupDestroyedException.class, e.getCause());
        }
    });
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroupDestroyedException(com.hazelcast.cp.exception.CPGroupDestroyedException) ExecutionException(java.util.concurrent.ExecutionException) 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 43 with CPGroupId

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

the class RaftInvocationManagerTest method when_raftGroupIsCreated_then_raftOperationsAreExecuted.

@Test
public void when_raftGroupIsCreated_then_raftOperationsAreExecuted() throws ExecutionException, InterruptedException {
    int nodeCount = 5;
    instances = newInstances(nodeCount);
    RaftInvocationManager invocationService = getRaftInvocationManager(instances[0]);
    CPGroupId groupId = invocationService.createRaftGroup("test", nodeCount).get();
    for (int i = 0; i < 100; i++) {
        invocationService.invoke(groupId, new RaftTestApplyOp("val" + i)).get();
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with CPGroupId

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

the class RaftService method publishGroupAvailabilityEvents.

private void publishGroupAvailabilityEvents(MemberImpl removedMember) {
    ClusterService clusterService = nodeEngine.getClusterService();
    if (clusterService.getClusterVersion().isUnknownOrLessThan(Versions.V4_1)) {
        return;
    }
    // they will be the ones that keep track of unreachable CP members.
    for (CPGroupId groupId : metadataGroupManager.getActiveGroupIds()) {
        CPGroupSummary group = metadataGroupManager.getGroup(groupId);
        Collection<CPMember> missing = new ArrayList<>();
        boolean availabilityDecreased = false;
        for (CPMember member : group.members()) {
            if (member.getAddress().equals(removedMember.getAddress())) {
                // Group's availability decreased because of this removed member
                availabilityDecreased = true;
                missing.add(member);
            } else if (clusterService.getMember(member.getAddress()) == null) {
                missing.add(member);
            }
        }
        if (availabilityDecreased) {
            CPGroupAvailabilityEvent e = new CPGroupAvailabilityEventImpl(group.id(), group.members(), missing);
            nodeEngine.getEventService().publishEvent(SERVICE_NAME, EVENT_TOPIC_AVAILABILITY, e, EVENT_TOPIC_AVAILABILITY.hashCode());
        }
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) CPGroupAvailabilityEventImpl(com.hazelcast.cp.event.impl.CPGroupAvailabilityEventImpl) CPGroupAvailabilityEvent(com.hazelcast.cp.event.CPGroupAvailabilityEvent) ClusterService(com.hazelcast.internal.cluster.ClusterService) ArrayList(java.util.ArrayList) CPMember(com.hazelcast.cp.CPMember)

Example 45 with CPGroupId

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

the class RaftService method provideDynamicMetrics.

@Override
public void provideDynamicMetrics(MetricDescriptor descriptor, MetricsCollectionContext context) {
    MetricDescriptor rootDescriptor = descriptor.withPrefix(CP_PREFIX_RAFT_GROUP);
    for (Entry<CPGroupId, RaftNodeMetrics> entry : nodeMetrics.entrySet()) {
        CPGroupId groupId = entry.getKey();
        RaftRole role = entry.getValue().role;
        MetricDescriptor groupDescriptor = rootDescriptor.copy().withDiscriminator(CP_DISCRIMINATOR_GROUPID, String.valueOf(groupId.getId())).withTag(CP_TAG_NAME, groupId.getName()).withTag("role", role != null ? role.toString() : "NONE");
        context.collect(groupDescriptor, entry.getValue());
    }
}
Also used : CPGroupId(com.hazelcast.cp.CPGroupId) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) RaftRole(com.hazelcast.cp.internal.raft.impl.RaftRole)

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