Search in sources :

Example 26 with ConcurrentMap

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

the class ConcurrentHashMapTest method testPutIfAbsent2_NullPointerException.

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

Example 27 with ConcurrentMap

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

the class ConcurrentHashMapTest method testRemove2.

/**
     * remove(key,value) removes only if pair present
     */
@Test
public void testRemove2() {
    ConcurrentMap map = map5();
    map.remove(five, "E");
    assertEquals(4, map.size());
    assertFalse(map.containsKey(five));
    map.remove(four, "A");
    assertEquals(4, map.size());
    assertTrue(map.containsKey(four));
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) Test(org.junit.Test)

Example 28 with ConcurrentMap

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

the class ConcurrentHashMapTest method testContains.

//TODO hash code
//    /**
//     * hashCode() equals sum of each key.hashCode ^ value.hashCode
//     */
//    @Test public void testHashCode() {
//        ConcurrentMap<Integer,String> map = map5();
//        int sum = 0;
//        for (Map.Entry<Integer,String> e : map.entrySet())
//            sum += e.getKey().hashCode() ^ e.getValue().hashCode();
//        assertEquals(sum, map.hashCode());
//    }
/**
     * contains returns true for contained value
     */
@Test
public void testContains() {
    ConcurrentMap map = map5();
    assertTrue(map.containsValue("A"));
    assertFalse(map.containsValue("Z"));
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) Test(org.junit.Test)

Example 29 with ConcurrentMap

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

the class ConcurrentHashMapTest method testReplace2.

/**
     * replace succeeds if the key is already present
     */
@Test
public void testReplace2() {
    ConcurrentMap map = map5();
    assertNotNull(map.replace(one, "Z"));
    assertEquals("Z", map.get(one));
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) Test(org.junit.Test)

Example 30 with ConcurrentMap

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

the class ConcurrentHashMapTest method testRemove1_NullPointerException.

/**
     * remove(null) throws NPE
     */
@Test
public void testRemove1_NullPointerException() {
    ConcurrentMap c = makeGenericMap();
    c.put("sadsdf", "asdads");
    try {
        c.remove(null);
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) Test(org.junit.Test)

Aggregations

ConcurrentMap (java.util.concurrent.ConcurrentMap)450 Map (java.util.Map)125 Test (org.junit.Test)111 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)83 HashMap (java.util.HashMap)75 ArrayList (java.util.ArrayList)58 Set (java.util.Set)41 URL (com.alibaba.dubbo.common.URL)32 List (java.util.List)26 Collectors (java.util.stream.Collectors)22 IOException (java.io.IOException)21 HashSet (java.util.HashSet)21 Collection (java.util.Collection)19 UsageCount (org.apache.felix.framework.ServiceRegistry.UsageCount)19 Bundle (org.osgi.framework.Bundle)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 Arrays (java.util.Arrays)15 Field (java.lang.reflect.Field)14 Iterator (java.util.Iterator)13