Exemple #1
0
  @Test
  public void NoSuchElem_After_Clear() {
    //      bug reported by :	Lazaros Tsochatzidis
    //        But after clearing the tree using:
    //
    //        public void Delete() {
    //            db.getTreeMap("Names").clear();
    //            db.compact();
    //        }
    //
    //        every next call of getLastKey() leads to the exception "NoSuchElement". Not
    //        only the first one...

    DB db = DBMaker.memoryDB().transactionDisable().make();
    NavigableMap m = db.treeMap("name");
    try {
      m.lastKey();
      fail();
    } catch (NoSuchElementException e) {
    }
    m.put("aa", "aa");
    assertEquals("aa", m.lastKey());
    m.put("bb", "bb");
    assertEquals("bb", m.lastKey());
    db.treeMap("name").clear();
    db.compact();
    try {
      Object key = m.lastKey();
      fail(key.toString());
    } catch (NoSuchElementException e) {
    }
    m.put("aa", "aa");
    assertEquals("aa", m.lastKey());
    m.put("bb", "bb");
    assertEquals("bb", m.lastKey());
  }