@Test public void mod_listener_lock() { DB db = DBMaker.memoryDB().transactionDisable().make(); final BTreeMap m = db.treeMap("name"); final long rootRecid = db.getEngine().get(m.rootRecidRef, Serializer.RECID); final AtomicInteger counter = new AtomicInteger(); m.modificationListenerAdd( new Bind.MapListener() { @Override public void update(Object key, Object oldVal, Object newVal) { assertTrue(m.nodeLocks.get(rootRecid) == Thread.currentThread()); assertEquals(1, m.nodeLocks.size()); counter.incrementAndGet(); } }); m.put("aa", "aa"); m.put("aa", "bb"); m.remove("aa"); m.put("aa", "aa"); m.remove("aa", "aa"); m.putIfAbsent("aa", "bb"); m.replace("aa", "bb", "cc"); m.replace("aa", "cc"); assertEquals(8, counter.get()); }
@Test public void delete() { for (int i : new int[] { 10, 50, 20, 42, // 44, 68, 20, 93, 85, 71, 62, 77, 4, 37, 66 }) { m.put(i, i); } assertEquals(10, m.remove(10)); assertEquals(20, m.remove(20)); assertEquals(42, m.remove(42)); assertEquals(null, m.remove(42999)); }