Search in sources :

Example 36 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project j2objc by google.

the class LongSummaryStatisticsTest method test_getCount.

public void test_getCount() {
    LongSummaryStatistics lss1 = getLongSummaryStatisticsData1();
    assertEquals(data1.length, lss1.getCount());
}
Also used : LongSummaryStatistics(java.util.LongSummaryStatistics)

Example 37 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project j2objc by google.

the class LongSummaryStatisticsTest method test_getMin.

public void test_getMin() {
    LongSummaryStatistics lss1 = getLongSummaryStatisticsData1();
    assertEquals(-5L, lss1.getMin());
}
Also used : LongSummaryStatistics(java.util.LongSummaryStatistics)

Example 38 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project hono by eclipse.

the class TelemetryJmsQoS1IT method testTelemetryUpload.

/**
 * Verifies that telemetry messages uploaded to the Hono server are all received
 * by a downstream consumer.
 *
 * @throws Exception if the test fails.
 */
@Test
@AssumeMessagingSystem(type = MessagingType.amqp)
public void testTelemetryUpload() throws Exception {
    final String tenantId = helper.getRandomTenantId();
    final String deviceId = helper.getRandomDeviceId(tenantId);
    final String username = IntegrationTestSupport.getUsername(deviceId, tenantId);
    final String pwd = "secret";
    final Tenant tenant = new Tenant();
    final VertxTestContext setup = new VertxTestContext();
    helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, pwd).compose(ok -> getAmqpAdapterConnection(username, pwd)).onComplete(setup.succeeding(connection -> {
        amqpAdapter = connection;
        setup.completeNow();
    }));
    assertTrue(setup.awaitCompletion(IntegrationTestSupport.getTestSetupTimeout(), TimeUnit.SECONDS));
    if (setup.failed()) {
        fail(setup.causeOfFailure());
    }
    final CountDownLatch latch = new CountDownLatch(IntegrationTestSupport.MSG_COUNT);
    final LongSummaryStatistics stats = new LongSummaryStatistics();
    givenATelemetryConsumer(tenantId);
    downstreamConsumer.setMessageListener(message -> {
        latch.countDown();
        gatherStatistics(stats, message);
        if (LOG.isInfoEnabled()) {
            final long messagesReceived = IntegrationTestSupport.MSG_COUNT - latch.getCount();
            if (messagesReceived % 100 == 0) {
                LOG.info("Received {} messages.", messagesReceived);
            }
        }
    });
    final MessageProducer messageProducer = amqpAdapter.createAnonymousProducer();
    final Destination telemetryEndpoint = JmsBasedHonoConnection.getDestination(TelemetryConstants.TELEMETRY_ENDPOINT);
    IntStream.range(1, IntegrationTestSupport.MSG_COUNT + 1).forEach(i -> {
        try {
            final Message message = amqpAdapter.newMessage("msg " + i, deviceId);
            messageProducer.send(telemetryEndpoint, message, DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
            if (i % 100 == 0) {
                LOG.info("Sent {} messages", i);
            }
        } catch (final JMSException e) {
            LOG.error("Error occurred while sending message: {}", e.getMessage(), e);
        }
    });
    final long timeToWait = Math.max(DEFAULT_TEST_TIMEOUT, Math.round(IntegrationTestSupport.MSG_COUNT * 1.2));
    // wait for messages to arrive
    assertTrue(latch.await(timeToWait, TimeUnit.MILLISECONDS), () -> "did not receive all " + IntegrationTestSupport.MSG_COUNT + " messages");
    LOG.info("Delivery statistics: {}", stats);
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) IntStream(java.util.stream.IntStream) VertxTestContext(io.vertx.junit5.VertxTestContext) BeforeEach(org.junit.jupiter.api.BeforeEach) LoggerFactory(org.slf4j.LoggerFactory) NamingException(javax.naming.NamingException) Tenant(org.eclipse.hono.service.management.tenant.Tenant) TelemetryConstants(org.eclipse.hono.util.TelemetryConstants) MessagingType(org.eclipse.hono.util.MessagingType) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) MessageProducer(javax.jms.MessageProducer) DeliveryMode(javax.jms.DeliveryMode) Message(javax.jms.Message) LongSummaryStatistics(java.util.LongSummaryStatistics) Logger(org.slf4j.Logger) Vertx(io.vertx.core.Vertx) JmsBasedHonoConnection(org.eclipse.hono.tests.jms.JmsBasedHonoConnection) VertxExtension(io.vertx.junit5.VertxExtension) JMSException(javax.jms.JMSException) AssumeMessagingSystem(org.eclipse.hono.tests.AssumeMessagingSystem) Future(io.vertx.core.Future) TestInfo(org.junit.jupiter.api.TestInfo) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) AfterEach(org.junit.jupiter.api.AfterEach) MessageConsumer(javax.jms.MessageConsumer) Destination(javax.jms.Destination) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Checkpoint(io.vertx.junit5.Checkpoint) LongSummaryStatistics(java.util.LongSummaryStatistics) Destination(javax.jms.Destination) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Message(javax.jms.Message) VertxTestContext(io.vertx.junit5.VertxTestContext) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test) AssumeMessagingSystem(org.eclipse.hono.tests.AssumeMessagingSystem)

Example 39 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project ambry by linkedin.

the class ReplicationMetrics method getAvgLagFromDc.

/**
 * Get tha average replication lag of remote replicas in given datacenter
 * @param dcName the name of dc where remote replicas sit
 * @return the average replication lag
 */
double getAvgLagFromDc(String dcName) {
    Set<RemoteReplicaInfo> replicaInfos = remoteReplicaInfosByDc.get(dcName);
    if (replicaInfos == null || replicaInfos.isEmpty()) {
        return -1.0;
    }
    LongSummaryStatistics longSummaryStatistics = replicaInfos.stream().collect(Collectors.summarizingLong(RemoteReplicaInfo::getRemoteLagFromLocalInBytes));
    dcToReplicaLagStats.put(dcName, longSummaryStatistics);
    return longSummaryStatistics.getAverage();
}
Also used : LongSummaryStatistics(java.util.LongSummaryStatistics)

Example 40 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project ambry by linkedin.

the class ReplicationMetrics method addMetricsForRemoteReplicaInfo.

/**
 * Add metrics for given remote replica.
 * @param remoteReplicaInfo the {@link RemoteReplicaInfo} that contains all infos associated with remote replica
 * @param trackPerDatacenterLag whether to track remote replicas' lag from local by each datacenter. Specifically, it
 *                              tracks min/max/avg remote replica lag from each datacenter.
 */
public void addMetricsForRemoteReplicaInfo(RemoteReplicaInfo remoteReplicaInfo, boolean trackPerDatacenterLag) {
    String metricNamePrefix = generateRemoteReplicaMetricPrefix(remoteReplicaInfo);
    String metadataRequestErrorMetricName = metricNamePrefix + "-metadataRequestError";
    if (metadataRequestErrorMap.containsKey(metadataRequestErrorMetricName)) {
        // Metrics already exist. For VCR: Partition add/remove go back and forth.
        return;
    }
    Counter metadataRequestError = registry.counter(MetricRegistry.name(ReplicaThread.class, metadataRequestErrorMetricName));
    metadataRequestErrorMap.put(metadataRequestErrorMetricName, metadataRequestError);
    String getRequestErrorMetricName = metricNamePrefix + "-getRequestError";
    Counter getRequestError = registry.counter(MetricRegistry.name(ReplicaThread.class, getRequestErrorMetricName));
    getRequestErrorMap.put(getRequestErrorMetricName, getRequestError);
    String localStoreErrorMetricName = metricNamePrefix + "-localStoreError";
    Counter localStoreError = registry.counter(MetricRegistry.name(ReplicaThread.class, localStoreErrorMetricName));
    localStoreErrorMap.put(localStoreErrorMetricName, localStoreError);
    Gauge<Long> replicaLag = remoteReplicaInfo::getRemoteLagFromLocalInBytes;
    registry.register(MetricRegistry.name(ReplicaThread.class, metricNamePrefix + "-remoteLagInBytes"), replicaLag);
    if (trackPerDatacenterLag) {
        String remoteReplicaDc = remoteReplicaInfo.getReplicaId().getDataNodeId().getDatacenterName();
        remoteReplicaInfosByDc.computeIfAbsent(remoteReplicaDc, k -> {
            Gauge<Double> avgReplicaLag = () -> getAvgLagFromDc(remoteReplicaDc);
            registry.register(MetricRegistry.name(ReplicaThread.class, remoteReplicaDc + "-avgReplicaLagFromLocalInBytes"), avgReplicaLag);
            Gauge<Long> maxReplicaLag = () -> {
                LongSummaryStatistics statistics = dcToReplicaLagStats.getOrDefault(remoteReplicaDc, new LongSummaryStatistics());
                return statistics.getMax() == Long.MIN_VALUE ? -1 : statistics.getMax();
            };
            registry.register(MetricRegistry.name(ReplicaThread.class, remoteReplicaDc + "-maxReplicaLagFromLocalInBytes"), maxReplicaLag);
            Gauge<Long> minReplicaLag = () -> {
                LongSummaryStatistics statistics = dcToReplicaLagStats.getOrDefault(remoteReplicaDc, new LongSummaryStatistics());
                return statistics.getMin() == Long.MAX_VALUE ? -1 : statistics.getMin();
            };
            registry.register(MetricRegistry.name(ReplicaThread.class, remoteReplicaDc + "-minReplicaLagFromLocalInBytes"), minReplicaLag);
            return ConcurrentHashMap.newKeySet();
        }).add(remoteReplicaInfo);
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) MetricRegistry(com.codahale.metrics.MetricRegistry) ReplicaType(com.github.ambry.clustermap.ReplicaType) DataNodeId(com.github.ambry.clustermap.DataNodeId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Meter(com.codahale.metrics.Meter) List(java.util.List) ReplicaId(com.github.ambry.clustermap.ReplicaId) Map(java.util.Map) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Gauge(com.codahale.metrics.Gauge) PartitionId(com.github.ambry.clustermap.PartitionId) LongSummaryStatistics(java.util.LongSummaryStatistics) LongSummaryStatistics(java.util.LongSummaryStatistics) Counter(com.codahale.metrics.Counter) Gauge(com.codahale.metrics.Gauge)

Aggregations

LongSummaryStatistics (java.util.LongSummaryStatistics)47 Test (org.junit.Test)18 List (java.util.List)15 Map (java.util.Map)12 CountDownLatch (java.util.concurrent.CountDownLatch)11 ArrayList (java.util.ArrayList)10 Collectors (java.util.stream.Collectors)10 Set (java.util.Set)9 TimeUnit (java.util.concurrent.TimeUnit)9 LoggerFactory (org.slf4j.LoggerFactory)9 HashMap (java.util.HashMap)8 Logger (org.slf4j.Logger)8 BaseTest (io.scalecube.testlib.BaseTest)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Arrays (java.util.Arrays)5 Stream (java.util.stream.Stream)5 Collections (java.util.Collections)4 Comparator (java.util.Comparator)4 Entry (java.util.Map.Entry)4