Search in sources :

Example 71 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.

the class ConcurrentHashMap8Test method testKeySetSpliterator.

/**
     * KeySetView.spliterator returns spliterator over the elements in this set
     */
public void testKeySetSpliterator() {
    LongAdder adder = new LongAdder();
    ConcurrentMap map = map5();
    Set set = map.keySet();
    Spliterator<Integer> sp = set.spliterator();
    checkSpliteratorCharacteristics(sp, CONCURRENT | DISTINCT | NONNULL);
    assertEquals(sp.estimateSize(), map.size());
    Spliterator<Integer> sp2 = sp.trySplit();
    sp.forEachRemaining((Integer x) -> adder.add(x.longValue()));
    long v = adder.sumThenReset();
    sp2.forEachRemaining((Integer x) -> adder.add(x.longValue()));
    long v2 = adder.sum();
    assertEquals(v + v2, 15);
}
Also used : Set(java.util.Set) LongAdder(java.util.concurrent.atomic.LongAdder) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 72 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.

the class ConcurrentHashMapTest method testReplace_NullPointerException.

/**
     * replace(null, x) throws NPE
     */
public void testReplace_NullPointerException() {
    ConcurrentMap c = map();
    try {
        c.replace(null, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 73 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.

the class ConcurrentHashMapTest method testContainsValue_NullPointerException.

/**
     * containsValue(null) throws NPE
     */
public void testContainsValue_NullPointerException() {
    ConcurrentMap c = map();
    try {
        c.containsValue(null);
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 74 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.

the class ConcurrentHashMapTest method testPutIfAbsent1_NullPointerException.

/**
     * putIfAbsent(null, x) throws NPE
     */
public void testPutIfAbsent1_NullPointerException() {
    ConcurrentMap c = map();
    try {
        c.putIfAbsent(null, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 75 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.

the class ConcurrentHashMap8Test method testCompute.

/**
     * compute does not replace if the function returns null
     */
public void testCompute() {
    ConcurrentMap map = map5();
    map.compute(six, (x, y) -> null);
    assertFalse(map.containsKey(six));
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

ConcurrentMap (java.util.concurrent.ConcurrentMap)218 Map (java.util.Map)53 Test (org.junit.Test)47 HashMap (java.util.HashMap)31 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)28 ArrayList (java.util.ArrayList)26 Set (java.util.Set)20 URL (com.alibaba.dubbo.common.URL)17 Iterator (java.util.Iterator)11 IOException (java.io.IOException)10 Collection (java.util.Collection)10 Arrays (java.util.Arrays)9 Collections (java.util.Collections)8 HashSet (java.util.HashSet)7 List (java.util.List)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 LongAdder (java.util.concurrent.atomic.LongAdder)6 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)5