Search in sources :

Example 41 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project scalecube by scalecube.

the class ClusterMessagingStressTest method clusterMessagingStressTest.

@Test
public void clusterMessagingStressTest() throws Exception {
    // Init transports
    Cluster echoServer = Cluster.joinAwait();
    Cluster[] latentNodes = new Cluster[ClusterConfig.DEFAULT_PING_REQ_MEMBERS];
    Cluster client1 = null;
    // Init measured params
    long sentTime = 0;
    long receivedTime = 0;
    LongSummaryStatistics rttStats = null;
    // Run experiment
    try {
        // Subscribe echo server handler
        echoServer.listen().subscribe(msg -> echoServer.send(msg.sender(), msg));
        // Start latent nodes (for indirect pings)
        for (int i = 0; i < latentNodes.length; i++) {
            latentNodes[i] = Cluster.joinAwait(echoServer.address());
        }
        // Init client
        CountDownLatch measureLatch = new CountDownLatch(msgCount);
        ArrayList<Long> rttRecords = new ArrayList<>(msgCount);
        client1 = Cluster.joinAwait(echoServer.address());
        client1.listen().subscribe(msg -> {
            long sentAt = Long.valueOf(msg.data());
            long rttTime = System.currentTimeMillis() - sentAt;
            rttRecords.add(rttTime);
            measureLatch.countDown();
        });
        // Subscribe on member removed event
        AtomicBoolean receivedMemberRemovedEvent = new AtomicBoolean(false);
        client1.listenMembership().filter(MembershipEvent::isRemoved).subscribe(event -> {
            LOGGER.warn("Received member removed event: {}", event);
            receivedMemberRemovedEvent.set(true);
        });
        // Measure
        long startAt = System.currentTimeMillis();
        for (int i = 0; i < msgCount; i++) {
            client1.send(echoServer.address(), Message.fromData(Long.toString(System.currentTimeMillis())));
        }
        sentTime = System.currentTimeMillis() - startAt;
        measureLatch.await(timeoutSeconds, TimeUnit.SECONDS);
        receivedTime = System.currentTimeMillis() - startAt;
        rttStats = rttRecords.stream().mapToLong(v -> v).summaryStatistics();
        assertTrue(measureLatch.getCount() == 0);
        assertFalse("Received member removed event", receivedMemberRemovedEvent.get());
    } finally {
        // Print results
        LOGGER.info("Finished sending {} messages in {} ms", msgCount, sentTime);
        LOGGER.info("Finished receiving {} messages in {} ms", msgCount, receivedTime);
        LOGGER.info("Round trip stats (ms): {}", rttStats);
        // Shutdown
        shutdown(echoServer);
        shutdown(latentNodes);
        shutdown(client1);
    }
}
Also used : LongSummaryStatistics(java.util.LongSummaryStatistics) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) BaseTest(io.scalecube.testlib.BaseTest)

Example 42 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project scalecube by scalecube.

the class GossipProtocolTest method computeMessageSentStats.

private LongSummaryStatistics computeMessageSentStats(List<GossipProtocolImpl> gossipProtocols) {
    List<Long> messageSentPerNode = new ArrayList<>(gossipProtocols.size());
    for (GossipProtocolImpl gossipProtocol : gossipProtocols) {
        Transport transport = gossipProtocol.getTransport();
        messageSentPerNode.add(transport.networkEmulator().totalMessageSentCount());
    }
    return messageSentPerNode.stream().mapToLong(v -> v).summaryStatistics();
}
Also used : Arrays(java.util.Arrays) Address(io.scalecube.transport.Address) MembershipProtocol(io.scalecube.cluster.membership.MembershipProtocol) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) ClusterConfig(io.scalecube.cluster.ClusterConfig) ClusterMath.maxMessagesPerGossipTotal(io.scalecube.cluster.ClusterMath.maxMessagesPerGossipTotal) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Transport(io.scalecube.transport.Transport) Message(io.scalecube.transport.Message) DummyMembershipProtocol(io.scalecube.cluster.membership.DummyMembershipProtocol) BaseTest(io.scalecube.testlib.BaseTest) ClusterMath.gossipConvergencePercent(io.scalecube.cluster.ClusterMath.gossipConvergencePercent) Parameterized(org.junit.runners.Parameterized) LongSummaryStatistics(java.util.LongSummaryStatistics) ClusterMath(io.scalecube.cluster.ClusterMath) Logger(org.slf4j.Logger) ClusterMath.maxMessagesPerGossipPerNode(io.scalecube.cluster.ClusterMath.maxMessagesPerGossipPerNode) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Member(io.scalecube.cluster.Member) TransportConfig(io.scalecube.transport.TransportConfig) Assert(org.junit.Assert) ClusterMath.gossipDisseminationTime(io.scalecube.cluster.ClusterMath.gossipDisseminationTime) ArrayList(java.util.ArrayList) Transport(io.scalecube.transport.Transport)

Example 43 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project eclipse-collections by eclipse.

the class SerializableLongSummaryStatisticsTest method valuesEqual.

@Test
public void valuesEqual() {
    SerializableLongSummaryStatistics with = SerializableLongSummaryStatistics.with(1, 2, 3);
    LongSummaryStatistics without = new LongSummaryStatistics();
    without.accept(1L);
    without.accept(2L);
    without.accept(3L);
    Assert.assertTrue(with.valuesEqual(without));
}
Also used : LongSummaryStatistics(java.util.LongSummaryStatistics) Test(org.junit.Test)

Example 44 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project keycloak by keycloak.

the class ClosingLongStream method summaryStatistics.

@Override
public LongSummaryStatistics summaryStatistics() {
    LongSummaryStatistics result = delegate.summaryStatistics();
    close();
    return result;
}
Also used : LongSummaryStatistics(java.util.LongSummaryStatistics)

Example 45 with LongSummaryStatistics

use of java.util.LongSummaryStatistics in project accumulo by apache.

the class DefaultCompactionStrategyTest method simulationTest.

@Test
public void simulationTest() throws Exception {
    for (int n = 1; n < 10; n++) {
        LongSummaryStatistics lss = new LongSummaryStatistics();
        SimulatedTablet simuTablet = new SimulatedTablet(10, 15);
        for (int i = 0; i < 1000; i++) {
            simuTablet.addFiles(n, 1000, 10);
            simuTablet.compact(MajorCompactionReason.NORMAL);
            lss.accept(simuTablet.getNumFiles());
        }
        while (simuTablet.compact(MajorCompactionReason.NORMAL) > 0) {
            lss.accept(simuTablet.getNumFiles());
        }
        assertTrue(simuTablet.getTotalRead() < 6 * simuTablet.getTotalAdded());
        assertTrue(lss.getAverage() < (n >= 8 ? 15 : 7));
    }
}
Also used : LongSummaryStatistics(java.util.LongSummaryStatistics) Test(org.junit.Test)

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