Exemplo n.º 1
0
 private void testDefragment() {
   String fileName = getBaseDir() + "/testDefragment.h3";
   FileUtils.delete(fileName);
   long initialLength = 0;
   for (int j = 0; j < 20; j++) {
     MVStore s = openStore(fileName);
     MVMap<Integer, String> m = s.openMap("data", Integer.class, String.class);
     for (int i = 0; i < 10; i++) {
       m.put(j + i, "Hello " + j);
     }
     s.store();
     s.compact(80);
     s.close();
     long len = FileUtils.size(fileName);
     // System.out.println("   len:" + len);
     if (initialLength == 0) {
       initialLength = len;
     } else {
       assertTrue("initial: " + initialLength + " len: " + len, len <= initialLength * 3);
     }
   }
   // long len = FileUtils.size(fileName);
   // System.out.println("len0: " + len);
   MVStore s = openStore(fileName);
   MVMap<Integer, String> m = s.openMap("data", Integer.class, String.class);
   for (int i = 0; i < 100; i++) {
     m.remove(i);
   }
   s.store();
   s.compact(80);
   s.close();
   // len = FileUtils.size(fileName);
   // System.out.println("len1: " + len);
   s = openStore(fileName);
   m = s.openMap("data", Integer.class, String.class);
   s.compact(80);
   s.close();
   // len = FileUtils.size(fileName);
   // System.out.println("len2: " + len);
 }
Exemplo n.º 2
0
 private void testTruncateFile() {
   String fileName = getBaseDir() + "/testTruncate.h3";
   FileUtils.delete(fileName);
   MVStore s;
   MVMap<Integer, String> m;
   s = openStore(fileName);
   m = s.openMap("data", Integer.class, String.class);
   for (int i = 0; i < 1000; i++) {
     m.put(i, "Hello World");
   }
   s.store();
   s.close();
   long len = FileUtils.size(fileName);
   s = openStore(fileName);
   m = s.openMap("data", Integer.class, String.class);
   m.clear();
   s.store();
   s.compact(100);
   s.close();
   long len2 = FileUtils.size(fileName);
   assertTrue(len2 < len);
 }