Exemple #1
0
  public void testDefragLinkedList() throws Exception {
    String file = newTestFile();
    DBStore r = new DBStore(file, false, false, false);
    List l = r.createLinkedList("test");
    Map<Long, Double> junk = new LinkedHashMap<Long, Double>();

    for (int i = 0; i < 1e4; i++) {
      // insert some junk
      Double d = Math.random();
      l.add(d);
      junk.put(r.insert(d), d);
    }
    r.commit();
    // make copy of linked list
    List l2 = new ArrayList(l);
    long oldRecCount = r.countRecords();
    r.defrag(true);

    r.close();
    r = new DBStore(file, false, false, false);
    assertEquals(oldRecCount, r.countRecords());

    // compare that list was unchanged
    assertEquals(l2, new ArrayList(r.getLinkedList("test")));

    // and check that random junk still have the same recids
    for (Long recid : junk.keySet()) {
      assertEquals(junk.get(recid), r.fetch(recid));
    }

    r.close();
  }