Search in sources :

Example 1 with ReadMetricsOperation

use of com.hazelcast.internal.metrics.managementcenter.ReadMetricsOperation in project hazelcast by hazelcast.

the class ReadMetricsOperationTest method testMetricsPresent_map.

@Test
public void testMetricsPresent_map() {
    Config config = new Config();
    HazelcastInstance hzInstance = createHazelcastInstance(config);
    IMap<Object, Object> map = hzInstance.getMap("map");
    map.put("key", "value");
    NodeEngineImpl nodeEngine = getNode(hzInstance).getNodeEngine();
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    AtomicLong nextSequence = new AtomicLong();
    assertTrueEventually(() -> {
        long sequence = nextSequence.get();
        ReadMetricsOperation readMetricsOperation = new ReadMetricsOperation(sequence);
        InternalCompletableFuture<RingbufferSlice<Map.Entry<Long, byte[]>>> future = operationService.invokeOnTarget(MetricsService.SERVICE_NAME, readMetricsOperation, nodeEngine.getThisAddress());
        RingbufferSlice<Map.Entry<Long, byte[]>> ringbufferSlice = future.get();
        MetricsResultSet metricsResultSet = new MetricsResultSet(ringbufferSlice.nextSequence(), ringbufferSlice.elements());
        nextSequence.set(metricsResultSet.nextSequence());
        boolean mapMetric = false;
        List<Map.Entry<Long, byte[]>> collections = metricsResultSet.collections();
        MetricKeyConsumer metricConsumer = new MetricKeyConsumer();
        for (Map.Entry<Long, byte[]> entry : collections) {
            MetricsCompressor.extractMetrics(entry.getValue(), metricConsumer);
        }
        assertTrue(metricConsumer.mapMetric);
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) RingbufferSlice(com.hazelcast.internal.metrics.managementcenter.ConcurrentArrayRingbuffer.RingbufferSlice) Config(com.hazelcast.config.Config) ReadMetricsOperation(com.hazelcast.internal.metrics.managementcenter.ReadMetricsOperation) MetricsResultSet(com.hazelcast.internal.metrics.managementcenter.MetricsResultSet) AtomicLong(java.util.concurrent.atomic.AtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) IMap(com.hazelcast.map.IMap) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Config (com.hazelcast.config.Config)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 RingbufferSlice (com.hazelcast.internal.metrics.managementcenter.ConcurrentArrayRingbuffer.RingbufferSlice)1 MetricsResultSet (com.hazelcast.internal.metrics.managementcenter.MetricsResultSet)1 ReadMetricsOperation (com.hazelcast.internal.metrics.managementcenter.ReadMetricsOperation)1 IMap (com.hazelcast.map.IMap)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Test (org.junit.Test)1