Search in sources :

Example 1 with RingbufferSlice

use of com.hazelcast.internal.metrics.managementcenter.ConcurrentArrayRingbuffer.RingbufferSlice 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)

Example 2 with RingbufferSlice

use of com.hazelcast.internal.metrics.managementcenter.ConcurrentArrayRingbuffer.RingbufferSlice in project hazelcast by hazelcast.

the class ReadMetricsOperation method run.

@Override
public void run() {
    ILogger logger = getNodeEngine().getLogger(getClass());
    MetricsService service = getService();
    CompletableFuture<RingbufferSlice<Entry<Long, byte[]>>> future = service.readMetrics(offset);
    future.whenCompleteAsync(withTryCatch(logger, (slice, error) -> doSendResponse(error != null ? peel(error) : slice)), CALLER_RUNS);
}
Also used : CALLER_RUNS(com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS) IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) ExceptionUtil.peel(com.hazelcast.internal.util.ExceptionUtil.peel) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) MetricsService(com.hazelcast.internal.metrics.impl.MetricsService) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) ReadonlyOperation(com.hazelcast.spi.impl.operationservice.ReadonlyOperation) Entry(java.util.Map.Entry) ExceptionUtil.withTryCatch(com.hazelcast.internal.util.ExceptionUtil.withTryCatch) RingbufferSlice(com.hazelcast.internal.metrics.managementcenter.ConcurrentArrayRingbuffer.RingbufferSlice) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) RingbufferSlice(com.hazelcast.internal.metrics.managementcenter.ConcurrentArrayRingbuffer.RingbufferSlice) MetricsService(com.hazelcast.internal.metrics.impl.MetricsService) ILogger(com.hazelcast.logging.ILogger)

Example 3 with RingbufferSlice

use of com.hazelcast.internal.metrics.managementcenter.ConcurrentArrayRingbuffer.RingbufferSlice in project hazelcast by hazelcast.

the class MetricsServiceTest method readMetrics.

private void readMetrics(MetricsService metricsService, long sequence, MetricConsumer metricConsumer) throws InterruptedException, java.util.concurrent.ExecutionException {
    CompletableFuture<RingbufferSlice<Map.Entry<Long, byte[]>>> future = metricsService.readMetrics(sequence);
    RingbufferSlice<Map.Entry<Long, byte[]>> ringbufferSlice = future.get();
    MetricsResultSet metricsResultSet = new MetricsResultSet(ringbufferSlice.nextSequence(), ringbufferSlice.elements());
    metricsResultSet.collections().forEach(entry -> extractMetrics(entry.getValue(), metricConsumer));
}
Also used : MetricsResultSet(com.hazelcast.internal.metrics.managementcenter.MetricsResultSet) RingbufferSlice(com.hazelcast.internal.metrics.managementcenter.ConcurrentArrayRingbuffer.RingbufferSlice) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Map(java.util.Map)

Aggregations

RingbufferSlice (com.hazelcast.internal.metrics.managementcenter.ConcurrentArrayRingbuffer.RingbufferSlice)3 MetricsResultSet (com.hazelcast.internal.metrics.managementcenter.MetricsResultSet)2 Map (java.util.Map)2 Config (com.hazelcast.config.Config)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 MetricsService (com.hazelcast.internal.metrics.impl.MetricsService)1 ReadMetricsOperation (com.hazelcast.internal.metrics.managementcenter.ReadMetricsOperation)1 CALLER_RUNS (com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS)1 ExceptionUtil.peel (com.hazelcast.internal.util.ExceptionUtil.peel)1 ExceptionUtil.withTryCatch (com.hazelcast.internal.util.ExceptionUtil.withTryCatch)1 ILogger (com.hazelcast.logging.ILogger)1 IMap (com.hazelcast.map.IMap)1 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)1 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)1 IdentifiedDataSerializable (com.hazelcast.nio.serialization.IdentifiedDataSerializable)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 Operation (com.hazelcast.spi.impl.operationservice.Operation)1 ReadonlyOperation (com.hazelcast.spi.impl.operationservice.ReadonlyOperation)1 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1