Search in sources :

Example 1 with LongAdder

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

the class ConcurrentHashMap8Test method testForEachKeyInParallel.

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

Example 2 with LongAdder

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

the class ConcurrentHashMap8Test method testForEachEntrySequentially.

/**
     * forEachEntrySequentially traverses all entries
     */
public void testForEachEntrySequentially() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachEntry(Long.MAX_VALUE, (Map.Entry<Long, Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
    assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder)

Example 3 with LongAdder

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

the class ConcurrentHashMap8Test method testForEachInParallel.

/**
     * forEachInParallel traverses all mappings
     */
public void testForEachInParallel() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEach(1L, (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 4 with LongAdder

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

the class ConcurrentHashMap8Test method testForEachEntryInParallel.

/**
     * forEachEntryInParallel traverses all entries
     */
public void testForEachEntryInParallel() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachEntry(1L, (Map.Entry<Long, Long> e) -> adder.add(e.getKey().longValue() + e.getValue().longValue()));
    assertEquals(adder.sum(), 3 * SIZE * (SIZE - 1) / 2);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder)

Example 5 with LongAdder

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

the class ConcurrentHashMap8Test method testMappedForEachKeyInParallel.

/**
     * Mapped forEachKeyInParallel traverses the given
     * transformations of all keys
     */
public void testMappedForEachKeyInParallel() {
    LongAdder adder = new LongAdder();
    ConcurrentHashMap<Long, Long> m = longMap();
    m.forEachKey(1L, (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)

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