Search in sources :

Example 46 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project mapdb by jankotek.

the class ConcurrentHashMap8Test method testCompute.

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

Example 47 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project mapdb by jankotek.

the class ConcurrentHashMap8Test method testComputeIfAbsent.

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

Example 48 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project mapdb by jankotek.

the class ConcurrentHashMap8Test method testComputeIfPresent2.

/**
     * computeIfPresent adds when the given key is not present
     */
public void testComputeIfPresent2() {
    ConcurrentHashMap map = map5();
    assertEquals("Z", map.computeIfPresent(one, (x, y) -> "Z"));
}
Also used : NONNULL(java.util.Spliterator.NONNULL) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) Test(junit.framework.Test) Iterator(java.util.Iterator) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TestSuite(junit.framework.TestSuite) AbstractMap(java.util.AbstractMap) DISTINCT(java.util.Spliterator.DISTINCT) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException) CONCURRENT(java.util.Spliterator.CONCURRENT) Collections(java.util.Collections) Spliterator(java.util.Spliterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 49 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project mapdb by jankotek.

the class ConcurrentHashMap8Test method testGetMappedValue.

/**
     * KeySetView.getMappedValue returns the map's mapped value
     */
public void testGetMappedValue() {
    ConcurrentHashMap map = map5();
    assertNull(map.keySet().getMappedValue());
    try {
        map.keySet(null);
        shouldThrow();
    } catch (NullPointerException success) {
    }
    ConcurrentHashMap.KeySetView set = map.keySet(one);
    assertFalse(set.add(one));
    assertTrue(set.add(six));
    assertTrue(set.add(seven));
    assertTrue(set.getMappedValue() == one);
    assertTrue(map.get(one) != one);
    assertTrue(map.get(six) == one);
    assertTrue(map.get(seven) == one);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 50 with ConcurrentHashMap

use of java.util.concurrent.ConcurrentHashMap in project mapdb by jankotek.

the class ConcurrentHashMap8Test method testComputeIfAbsent2.

/**
     * computeIfAbsent does not replace if the key is already present
     */
public void testComputeIfAbsent2() {
    ConcurrentHashMap map = map5();
    assertEquals("A", map.computeIfAbsent(one, (x) -> "Z"));
}
Also used : NONNULL(java.util.Spliterator.NONNULL) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) Test(junit.framework.Test) Iterator(java.util.Iterator) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TestSuite(junit.framework.TestSuite) AbstractMap(java.util.AbstractMap) DISTINCT(java.util.Spliterator.DISTINCT) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException) CONCURRENT(java.util.Spliterator.CONCURRENT) Collections(java.util.Collections) Spliterator(java.util.Spliterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)420 Map (java.util.Map)106 Test (org.junit.Test)102 HashMap (java.util.HashMap)75 ArrayList (java.util.ArrayList)73 CountDownLatch (java.util.concurrent.CountDownLatch)53 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)49 IOException (java.io.IOException)47 List (java.util.List)38 Set (java.util.Set)36 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)33 HashSet (java.util.HashSet)31 AtomicLong (java.util.concurrent.atomic.AtomicLong)29 ConcurrentMap (java.util.concurrent.ConcurrentMap)28 Random (java.util.Random)25 ExecutorService (java.util.concurrent.ExecutorService)23 Collection (java.util.Collection)20 UUID (java.util.UUID)20 Iterator (java.util.Iterator)19 Configuration (org.apache.hadoop.conf.Configuration)17