Search in sources :

Example 1 with Node

use of com.hazelcast.instance.impl.Node in project hazelcast by hazelcast.

the class ClusterInfoTest method test_start_time_single_node_cluster.

@Test
public void test_start_time_single_node_cluster() {
    HazelcastInstance h1 = factory.newHazelcastInstance();
    Node node1 = getNode(h1);
    assertNotEquals(Long.MIN_VALUE, node1.getClusterService().getClusterClock().getClusterStartTime());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with Node

use of com.hazelcast.instance.impl.Node in project hazelcast by hazelcast.

the class ClusterShutdownTest method testClusterShutdownWithMultipleMembers.

private void testClusterShutdownWithMultipleMembers(int clusterSize, int nodeCountToTriggerShutdown) {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(clusterSize);
    HazelcastInstance[] instances = factory.newInstances();
    assertClusterSizeEventually(clusterSize, instances);
    instances[0].getCluster().changeClusterState(ClusterState.PASSIVE);
    Node[] nodes = getNodes(instances);
    final CountDownLatch latch = new CountDownLatch(1);
    for (int i = 0; i < nodeCountToTriggerShutdown; i++) {
        final HazelcastInstance instance = instances[i];
        final Runnable shutdownRunnable = new Runnable() {

            @Override
            public void run() {
                assertOpenEventually(latch);
                instance.getCluster().shutdown();
            }
        };
        new Thread(shutdownRunnable).start();
    }
    latch.countDown();
    assertNodesShutDownEventually(nodes);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 3 with Node

use of com.hazelcast.instance.impl.Node in project hazelcast by hazelcast.

the class DistributedObjectCounterCollector method forEachMetric.

@Override
public void forEachMetric(Node node, BiConsumer<PhoneHomeMetrics, String> metricsConsumer) {
    InternalProxyService proxyService = node.nodeEngine.getProxyService();
    Map<String, Long> objectsPerService = proxyService.getAllDistributedObjects().stream().filter(obj -> INTERNAL_OBJECTS_PREFIXES.stream().noneMatch(prefix -> obj.getName().startsWith(prefix))).filter(obj -> SERVICE_NAME_TO_METRIC_NAME.containsKey(obj.getServiceName())).collect(groupingBy(DistributedObject::getServiceName, Collectors.counting()));
    SERVICE_NAME_TO_METRIC_NAME.forEach((serviceName, metricNames) -> {
        metricsConsumer.accept(metricNames[0], String.valueOf(objectsPerService.getOrDefault(serviceName, 0L)));
        metricsConsumer.accept(metricNames[1], String.valueOf(proxyService.getCreatedCount(serviceName)));
    });
}
Also used : COUNT_OF_RING_BUFFERS(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_RING_BUFFERS) INTERNAL_OBJECTS_PREFIXES(com.hazelcast.spi.impl.proxyservice.impl.ProxyRegistry.INTERNAL_OBJECTS_PREFIXES) COUNT_OF_MULTIMAPS_ALL_TIME(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_MULTIMAPS_ALL_TIME) COUNT_OF_REPLICATED_MAPS(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_REPLICATED_MAPS) COUNT_OF_SETS_ALL_TIME(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_SETS_ALL_TIME) COUNT_OF_TOPICS(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_TOPICS) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) QueueService(com.hazelcast.collection.impl.queue.QueueService) COUNT_OF_CARDINALITY_ESTIMATORS(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_CARDINALITY_ESTIMATORS) COUNT_OF_CARDINALITY_ESTIMATORS_ALL_TIME(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_CARDINALITY_ESTIMATORS_ALL_TIME) SetService(com.hazelcast.collection.impl.set.SetService) MultiMapService(com.hazelcast.multimap.impl.MultiMapService) COUNT_OF_QUEUES_ALL_TIME(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_QUEUES_ALL_TIME) MapUtil(com.hazelcast.internal.util.MapUtil) COUNT_OF_TOPICS_ALL_TIME(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_TOPICS_ALL_TIME) ListService(com.hazelcast.collection.impl.list.ListService) CacheService(com.hazelcast.cache.impl.CacheService) InternalProxyService(com.hazelcast.spi.impl.proxyservice.InternalProxyService) Map(java.util.Map) COUNT_OF_REPLICATED_MAPS_ALL_TIME(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_REPLICATED_MAPS_ALL_TIME) BiConsumer(java.util.function.BiConsumer) CardinalityEstimatorService(com.hazelcast.cardinality.impl.CardinalityEstimatorService) RingbufferService(com.hazelcast.ringbuffer.impl.RingbufferService) COUNT_OF_MAPS_ALL_TIME(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_MAPS_ALL_TIME) COUNT_OF_LISTS(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_LISTS) COUNT_OF_PN_COUNTERS_ALL_TIME(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_PN_COUNTERS_ALL_TIME) COUNT_OF_LISTS_ALL_TIME(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_LISTS_ALL_TIME) COUNT_OF_MULTIMAPS(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_MULTIMAPS) COUNT_OF_RING_BUFFERS_ALL_TIME(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_RING_BUFFERS_ALL_TIME) MapService(com.hazelcast.map.impl.MapService) FlakeIdGeneratorService(com.hazelcast.flakeidgen.impl.FlakeIdGeneratorService) TopicService(com.hazelcast.topic.impl.TopicService) PNCounterService(com.hazelcast.internal.crdt.pncounter.PNCounterService) Collectors(java.util.stream.Collectors) Node(com.hazelcast.instance.impl.Node) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) COUNT_OF_CACHES(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_CACHES) DistributedObject(com.hazelcast.core.DistributedObject) COUNT_OF_MAPS(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_MAPS) COUNT_OF_SETS(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_SETS) COUNT_OF_FLAKE_ID_GENERATORS_ALL_TIME(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_FLAKE_ID_GENERATORS_ALL_TIME) COUNT_OF_QUEUES(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_QUEUES) COUNT_OF_PN_COUNTERS(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_PN_COUNTERS) COUNT_OF_CACHES_ALL_TIME(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_CACHES_ALL_TIME) COUNT_OF_FLAKE_ID_GENERATORS(com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.COUNT_OF_FLAKE_ID_GENERATORS) InternalProxyService(com.hazelcast.spi.impl.proxyservice.InternalProxyService)

Example 4 with Node

use of com.hazelcast.instance.impl.Node in project hazelcast by hazelcast.

the class CachePutAllTest method testPutAll.

@Test
public void testPutAll() {
    ICache<String, String> cache = createCache();
    String cacheName = cache.getName();
    Map<String, String> entries = createAndFillEntries();
    cache.putAll(entries);
    // Verify that put-all works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String expectedValue = entries.get(key);
        String actualValue = cache.get(key);
        assertEquals(expectedValue, actualValue);
    }
    Node node = getNode(hazelcastInstance);
    InternalPartitionService partitionService = node.getPartitionService();
    SerializationService serializationService = node.getSerializationService();
    // Verify that backup of put-all works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String expectedValue = entries.get(key);
        Data keyData = serializationService.toData(key);
        int keyPartitionId = partitionService.getPartitionId(keyData);
        for (int i = 0; i < INSTANCE_COUNT; i++) {
            Node n = getNode(hazelcastInstances[i]);
            ICacheService cacheService = n.getNodeEngine().getService(ICacheService.SERVICE_NAME);
            ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
            assertNotNull(recordStore);
            String actualValue = serializationService.toObject(recordStore.get(keyData, null));
            assertEquals(expectedValue, actualValue);
        }
    }
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) ICacheService(com.hazelcast.cache.impl.ICacheService) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ICacheRecordStore(com.hazelcast.cache.impl.ICacheRecordStore) HashMap(java.util.HashMap) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with Node

use of com.hazelcast.instance.impl.Node in project hazelcast by hazelcast.

the class CachePutAllTest method createAndFillEntries.

private Map<String, String> createAndFillEntries() {
    final int ENTRY_COUNT_PER_PARTITION = 3;
    Node node = getNode(hazelcastInstance);
    int partitionCount = node.getPartitionService().getPartitionCount();
    Map<String, String> entries = new HashMap<String, String>(partitionCount * ENTRY_COUNT_PER_PARTITION);
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        for (int i = 0; i < ENTRY_COUNT_PER_PARTITION; i++) {
            String key = generateKeyForPartition(hazelcastInstance, partitionId);
            String value = generateRandomString(16);
            entries.put(key, value);
        }
    }
    return entries;
}
Also used : HashMap(java.util.HashMap) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node)

Aggregations

Node (com.hazelcast.instance.impl.Node)144 Accessors.getNode (com.hazelcast.test.Accessors.getNode)84 HazelcastInstance (com.hazelcast.core.HazelcastInstance)68 Test (org.junit.Test)60 QuickTest (com.hazelcast.test.annotation.QuickTest)57 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)44 Config (com.hazelcast.config.Config)22 Address (com.hazelcast.cluster.Address)20 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)19 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)13 UUID (java.util.UUID)13 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)12 SerializationService (com.hazelcast.internal.serialization.SerializationService)12 ILogger (com.hazelcast.logging.ILogger)10 MapService (com.hazelcast.map.impl.MapService)10 ClientConnectionRegistration (com.hazelcast.client.impl.spi.impl.listener.ClientConnectionRegistration)9 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 HashMap (java.util.HashMap)9 Data (com.hazelcast.internal.serialization.Data)8 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)8