Search in sources :

Example 96 with ConcurrentNavigableMap

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

the class ConcurrentSkipListSubMapTest method testDescendingRemove2.

/**
     * remove(key,value) removes only if pair present
     */
@Test
public void testDescendingRemove2() {
    if (isReadOnly())
        return;
    ConcurrentNavigableMap map = dmap5();
    assertTrue(map.containsKey(m5));
    assertEquals("E", map.get(m5));
    map.remove(m5, "E");
    assertEquals(4, map.size());
    assertFalse(map.containsKey(m5));
    map.remove(m4, "A");
    assertEquals(4, map.size());
    assertTrue(map.containsKey(m4));
}
Also used : ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) Test(org.junit.Test)

Example 97 with ConcurrentNavigableMap

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

the class ConcurrentSkipListMapTest method testTailMapContents.

/**
     * tailMap returns map with keys in requested range
     */
@Test
public void testTailMapContents() {
    ConcurrentNavigableMap map = map5();
    NavigableMap sm = map.tailMap(two, true);
    assertFalse(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertTrue(sm.containsKey(four));
    assertTrue(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(two, k);
    k = (Integer) (i.next());
    assertEquals(three, k);
    k = (Integer) (i.next());
    assertEquals(four, k);
    k = (Integer) (i.next());
    assertEquals(five, k);
    assertFalse(i.hasNext());
    Iterator r = sm.descendingKeySet().iterator();
    k = (Integer) (r.next());
    assertEquals(five, k);
    k = (Integer) (r.next());
    assertEquals(four, k);
    k = (Integer) (r.next());
    assertEquals(three, k);
    k = (Integer) (r.next());
    assertEquals(two, k);
    assertFalse(r.hasNext());
    Iterator ei = sm.entrySet().iterator();
    Map.Entry e;
    e = (Map.Entry) (ei.next());
    assertEquals(two, e.getKey());
    assertEquals("B", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(three, e.getKey());
    assertEquals("C", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(four, e.getKey());
    assertEquals("D", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    assertFalse(i.hasNext());
    NavigableMap ssm = sm.tailMap(four, true);
    assertEquals(four, ssm.firstKey());
    assertEquals(five, ssm.lastKey());
    if (isReadOnly())
        return;
    assertEquals("D", ssm.remove(four));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, map.size());
}
Also used : ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) Test(org.junit.Test)

Example 98 with ConcurrentNavigableMap

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

the class ConcurrentSkipListMapTest method testCeilingKey.

/**
     * ceilingKey returns next element
     */
@Test
public void testCeilingKey() {
    ConcurrentNavigableMap q = map5();
    Object e1 = q.ceilingKey(three);
    assertEquals(three, e1);
    Object e2 = q.ceilingKey(zero);
    assertEquals(one, e2);
    Object e3 = q.ceilingKey(five);
    assertEquals(five, e3);
    Object e4 = q.ceilingKey(six);
    assertNull(e4);
}
Also used : ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) Test(org.junit.Test)

Example 99 with ConcurrentNavigableMap

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

the class ConcurrentSkipListMapTest method testPutIfAbsent.

/**
     * putIfAbsent works when the given key is not present
     */
@Test
public void testPutIfAbsent() {
    ConcurrentNavigableMap map = map5();
    map.putIfAbsent(six, "Z");
    assertTrue(map.containsKey(six));
}
Also used : ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) Test(org.junit.Test)

Example 100 with ConcurrentNavigableMap

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

the class ConcurrentSkipListMapTest method testLastKey.

/**
     * lastKey returns last key
     */
@Test
public void testLastKey() {
    ConcurrentNavigableMap map = map5();
    assertEquals(five, map.lastKey());
}
Also used : ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) Test(org.junit.Test)

Aggregations

ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)156 Test (org.junit.Test)147 SortedMap (java.util.SortedMap)25 Map (java.util.Map)19 NavigableMap (java.util.NavigableMap)19 Iterator (java.util.Iterator)12 Set (java.util.Set)10 Collection (java.util.Collection)4 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)4 Update (co.cask.cdap.data2.dataset2.lib.table.Update)3 ArrayList (java.util.ArrayList)2 IncrementValue (co.cask.cdap.data2.dataset2.lib.table.IncrementValue)1 PutValue (co.cask.cdap.data2.dataset2.lib.table.PutValue)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1