Search in sources :

Example 11 with ConcurrentMap

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

the class ConcurrentHashMapTest method testContainsKey_NullPointerException.

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

Example 12 with ConcurrentMap

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

the class ConcurrentHashMapTest method testSetValueWriteThrough.

//TODO serialization
//    /**
//     * A deserialized map equals original
//     */
//    @Test public void testSerialization() throws Exception {
//        Map x = map5();
//        Map y = serialClone(x);
//
//        assertNotSame(x, y);
//        assertEquals(x.size(), y.size());
//        assertEquals(x, y);
//        assertEquals(y, x);
//    }
/**
     * SetValue of an EntrySet entry sets value in the map.
     */
@Test
public void testSetValueWriteThrough() {
    // Adapted from a bug report by Eric Zoerner
    ConcurrentMap map = makeGenericMap();
    assertTrue(map.isEmpty());
    for (int i = 0; i < 20; i++) map.put(new Integer(i), new Integer(i));
    assertFalse(map.isEmpty());
    Map.Entry entry1 = (Map.Entry) map.entrySet().iterator().next();
    // cloned in map
    if (!entry1.getKey().equals(new Integer(16))) {
        map.remove(new Integer(16));
        entry1.setValue("XYZ");
        // fails if write-through broken
        assertTrue(map.containsValue("XYZ"));
    }
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Test(org.junit.Test)

Example 13 with ConcurrentMap

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

the class ConcurrentHashMapTest method testContains_NullPointerException.

/**
     * contains(null) throws NPE
     */
@Test
public void testContains_NullPointerException() {
    ConcurrentMap c = makeMap();
    try {
        c.containsKey(null);
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) Test(org.junit.Test)

Example 14 with ConcurrentMap

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

the class ConcurrentHashMapTest method map5.

/**
     * Returns a new map from Integers 1-5 to Strings "A"-"E".
     */
ConcurrentMap<Integer, String> map5() {
    ConcurrentMap map = makeMap();
    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 15 with ConcurrentMap

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

the class ConcurrentHashMapTest method testKeySet.

/**
     * keySet returns a Set containing all the keys
     */
@Test
public void testKeySet() {
    ConcurrentMap map = map5();
    Set s = map.keySet();
    assertEquals(5, s.size());
    assertTrue(s.contains(one));
    assertTrue(s.contains(two));
    assertTrue(s.contains(three));
    assertTrue(s.contains(four));
    assertTrue(s.contains(five));
}
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