Search in sources :

Example 6 with LongAdder

use of java.util.concurrent.atomic.LongAdder in project mapdb by jankotek.

the class ConcurrentHashMap8Test method testMappedForEachKeySequentially.

/**
     * Mapped forEachKeySequentially traverses the given
     * transformations of all keys
     */
public void testMappedForEachKeySequentially() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachKey(Long.MAX_VALUE, (Long x) -> Long.valueOf(4 * x.longValue()), (Long x) -> adder.add(x.longValue()));
    assertEquals(adder.sum(), 4 * SIZE * (SIZE - 1) / 2);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder)

Example 7 with LongAdder

use of java.util.concurrent.atomic.LongAdder in project mapdb by jankotek.

the class ConcurrentHashMap8Test method testForEachValueInParallel.

/**
     * forEachValueInParallel traverses all values
     */
public void testForEachValueInParallel() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachValue(1L, (Long x) -> adder.add(x.longValue()));
    assertEquals(adder.sum(), SIZE * (SIZE - 1));
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder)

Example 8 with LongAdder

use of java.util.concurrent.atomic.LongAdder in project mapdb by jankotek.

the class ConcurrentHashMap8Test method testForEachSequentially.

/**
     * forEachSequentially traverses all mappings
     */
public void testForEachSequentially() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEach(Long.MAX_VALUE, (Long x, Long y) -> adder.add(x.longValue() + y.longValue()));
    assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder)

Example 9 with LongAdder

use of java.util.concurrent.atomic.LongAdder in project mapdb by jankotek.

the class ConcurrentHashMap8Test method testForEachKeySequentially.

/**
     * forEachKeySequentially traverses all keys
     */
public void testForEachKeySequentially() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachKey(Long.MAX_VALUE, (Long x) -> adder.add(x.longValue()));
    assertEquals(adder.sum(), SIZE * (SIZE - 1) / 2);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder)

Example 10 with LongAdder

use of java.util.concurrent.atomic.LongAdder in project spring-boot by spring-projects.

the class BufferGaugeServiceSpeedTests method reader.

@Theory
public void reader(String input) throws Exception {
    iterate("writeReader");
    double rate = number / watch.getLastTaskTimeMillis() * 1000;
    System.err.println("Rate(" + count + ")=" + rate + ", " + watch);
    watch.start("readReader" + count);
    this.reader.findAll().forEach(new Consumer<Metric<?>>() {

        @Override
        public void accept(Metric<?> metric) {
            err.println(metric);
        }
    });
    final LongAdder total = new LongAdder();
    this.reader.findAll().forEach(new Consumer<Metric<?>>() {

        @Override
        public void accept(Metric<?> value) {
            total.add(value.getValue().intValue());
        }
    });
    watch.stop();
    System.err.println("Read(" + count + ")=" + watch.getLastTaskTimeMillis() + "ms");
    assertThat(0 < total.longValue()).isTrue();
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) Metric(org.springframework.boot.actuate.metrics.Metric) Theory(org.junit.experimental.theories.Theory)

Aggregations

LongAdder (java.util.concurrent.atomic.LongAdder)65 Random (java.util.Random)9 SplittableRandom (java.util.SplittableRandom)9 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)9 HashMap (java.util.HashMap)6 Theory (org.junit.experimental.theories.Theory)6 Map (java.util.Map)5 Metric (org.springframework.boot.actuate.metrics.Metric)5 HashSet (java.util.HashSet)3 ExecutorService (java.util.concurrent.ExecutorService)3 Future (java.util.concurrent.Future)3 ConcurrentModificationException (java.util.ConcurrentModificationException)2 NoSuchElementException (java.util.NoSuchElementException)2 Set (java.util.Set)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Deferred (org.osgi.util.promise.Deferred)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1