use of java.util.concurrent.ConcurrentNavigableMap in project mapdb by jankotek.
the class ConcurrentSkipListSubMapTest method testSubMapContents.
// TODO serialization?
// /**
// * A deserialized map equals original
// */
// @Test public void testSerialization() throws Exception {
// NavigableMap x = map5();
// NavigableMap y = serialClone(x);
//
// assertNotSame(x, y);
// assertEquals(x.size(), y.size());
// assertEquals(x.toString(), y.toString());
// assertEquals(x, y);
// assertEquals(y, x);
// }
/**
* subMap returns map with keys in requested range
*/
@Test
public void testSubMapContents() {
ConcurrentNavigableMap map = map5();
SortedMap sm = map.subMap(two, four);
assertEquals(two, sm.firstKey());
assertEquals(three, sm.lastKey());
assertEquals(2, sm.size());
assertFalse(sm.containsKey(one));
assertTrue(sm.containsKey(two));
assertTrue(sm.containsKey(three));
assertFalse(sm.containsKey(four));
assertFalse(sm.containsKey(five));
Iterator i = sm.keySet().iterator();
Object k;
k = (Integer) (i.next());
assertEquals(two, k);
k = (Integer) (i.next());
assertEquals(three, k);
assertFalse(i.hasNext());
if (isReadOnly())
return;
Iterator j = sm.keySet().iterator();
j.next();
j.remove();
assertFalse(map.containsKey(two));
assertEquals(4, map.size());
assertEquals(1, sm.size());
assertEquals(three, sm.firstKey());
assertEquals(three, sm.lastKey());
assertEquals("C", sm.remove(three));
assertTrue(sm.isEmpty());
assertEquals(3, map.size());
}
use of java.util.concurrent.ConcurrentNavigableMap in project mapdb by jankotek.
the class ConcurrentSkipListSubMapTest method testRemove.
/**
* remove removes the correct key-value pair from the map
*/
@Test
public void testRemove() {
if (isReadOnly())
return;
ConcurrentNavigableMap map = map5();
map.remove(five);
assertEquals(4, map.size());
assertFalse(map.containsKey(five));
}
use of java.util.concurrent.ConcurrentNavigableMap in project mapdb by jankotek.
the class ConcurrentSkipListSubMapTest method testDescendingKeySetOrder.
/**
* keySet is ordered
*/
@Test
public void testDescendingKeySetOrder() {
ConcurrentNavigableMap map = dmap5();
Set s = map.keySet();
Iterator i = s.iterator();
Integer last = (Integer) i.next();
assertEquals(last, m1);
while (i.hasNext()) {
Integer k = (Integer) i.next();
assertTrue(last.compareTo(k) > 0);
last = k;
}
}
use of java.util.concurrent.ConcurrentNavigableMap in project mapdb by jankotek.
the class TupleTest method testSubMap.
@Test
public void testSubMap() {
int[] nums = { 1, 2, 3, 4, 5 };
ConcurrentNavigableMap m = new ConcurrentSkipListMap();
for (int a : nums) for (int b : nums) {
m.put(t2(a, b), "");
}
assertEquals(5, m.subMap(t2(3, null), t2(3, HI)).size());
assertEquals(3, m.subMap(t2(3, 3), t2(3, HI)).size());
assertEquals(10, m.headMap(t2(3, null)).size());
assertEquals(15, m.tailMap(t2(3, null)).size());
assertEquals(10, m.headMap(t2(2, HI)).size());
assertEquals(15, m.tailMap(t2(2, HI)).size());
}
use of java.util.concurrent.ConcurrentNavigableMap in project cdap by caskdata.
the class InMemoryTableService method increment.
// todo: remove it from here: only used by "system" metrics table, which should be revised
@Deprecated
public static synchronized Map<byte[], Long> increment(String tableName, byte[] row, Map<byte[], Long> increments) {
Map<byte[], Long> resultMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
ConcurrentNavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, Update>>> table = tables.get(tableName);
// get the correct row from the table, create it if it doesn't exist
NavigableMap<byte[], NavigableMap<Long, Update>> rowMap = table.get(row);
if (rowMap == null) {
rowMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
table.put(row, rowMap);
}
// now increment each column, one by one
long versionForWrite = System.currentTimeMillis();
for (Map.Entry<byte[], Long> inc : increments.entrySet()) {
IncrementValue increment = new IncrementValue(inc.getValue());
// create the column in the row if it does not exist
NavigableMap<Long, Update> colMap = rowMap.get(inc.getKey());
Update last = null;
if (colMap == null) {
colMap = Maps.newTreeMap();
rowMap.put(inc.getKey(), colMap);
} else {
last = colMap.lastEntry().getValue();
}
Update merged = Updates.mergeUpdates(last, increment);
// put into the column with given version
long newValue = Bytes.toLong(merged.getBytes());
resultMap.put(inc.getKey(), newValue);
colMap.put(versionForWrite, merged);
}
return resultMap;
}
Aggregations