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());
}
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());
}
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);
}
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();
}
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);
}
}
Aggregations