Search in sources :

Example 81 with ConcurrentMap

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

the class ConcurrentHashMap8Test method testComputeIfAbsent.

/**
     * computeIfAbsent adds when the given key is not present
     */
public void testComputeIfAbsent() {
    ConcurrentMap map = map5();
    map.computeIfAbsent(six, (x) -> "Z");
    assertTrue(map.containsKey(six));
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 82 with ConcurrentMap

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

the class ConcurrentHashMap8Test method testCompute3.

/**
     * compute replaces when the given key is present
     */
public void testCompute3() {
    ConcurrentMap map = map5();
    assertEquals("Z", map.compute(one, (x, y) -> "Z"));
}
Also used : NONNULL(java.util.Spliterator.NONNULL) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) Test(junit.framework.Test) Iterator(java.util.Iterator) Collection(java.util.Collection) Set(java.util.Set) ConcurrentMap(java.util.concurrent.ConcurrentMap) TestSuite(junit.framework.TestSuite) DISTINCT(java.util.Spliterator.DISTINCT) NoSuchElementException(java.util.NoSuchElementException) CONCURRENT(java.util.Spliterator.CONCURRENT) Collections(java.util.Collections) Spliterator(java.util.Spliterator) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 83 with ConcurrentMap

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

the class ConcurrentHashMapTest method testReplaceValue2_NullPointerException.

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

Example 84 with ConcurrentMap

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

the class ConcurrentHashMapTest method map5.

/**
     * Returns a new map from Integers 1-5 to Strings "A"-"E".
     */
private static ConcurrentMap<Integer, String> map5() {
    ConcurrentMap map = map();
    assertTrue(map.isEmpty());
    map.put(one, "A");
    map.put(two, "B");
    map.put(three, "C");
    map.put(four, "D");
    map.put(five, "E");
    assertFalse(map.isEmpty());
    assertEquals(5, map.size());
    return map;
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 85 with ConcurrentMap

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

the class ConcurrentHashMapTest method testReplace.

/**
     * replace fails when the given key is not present
     */
public void testReplace() {
    ConcurrentMap map = map5();
    assertNull(map.replace(six, "Z"));
    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