Exemplo n.º 1
0
  private void testFastDelete() {
    String fileName = getBaseDir() + "/testFastDelete.h3";
    FileUtils.delete(fileName);
    MVStore s;
    MVMap<Integer, String> m;
    s = openStore(fileName);
    s.setMaxPageSize(100);
    m = s.openMap("data", Integer.class, String.class);
    for (int i = 0; i < 1000; i++) {
      m.put(i, "Hello World");
      assertEquals(i + 1, m.size());
    }
    assertEquals(1000, m.size());
    s.store();
    assertEquals(3, s.getWriteCount());
    s.close();

    s = openStore(fileName);
    m = s.openMap("data", Integer.class, String.class);
    m.clear();
    assertEquals(0, m.size());
    s.store();
    // ensure only nodes are read, but not leaves
    assertEquals(4, s.getReadCount());
    assertEquals(2, s.getWriteCount());
    s.close();
  }
Exemplo n.º 2
0
  private void testRollbackInMemory() {
    String fileName = getBaseDir() + "/testRollback.h3";
    FileUtils.delete(fileName);
    MVStore s = openStore(fileName);
    assertEquals(0, s.getCurrentVersion());
    s.setMaxPageSize(5);
    MVMap<String, String> m = s.openMap("data", String.class, String.class);
    s.rollbackTo(0);
    assertTrue(m.isClosed());
    assertEquals(0, s.getCurrentVersion());
    m = s.openMap("data", String.class, String.class);

    MVMap<String, String> m0 = s.openMap("data0", String.class, String.class);
    MVMap<String, String> m2 = s.openMap("data2", String.class, String.class);
    m.put("1", "Hello");
    for (int i = 0; i < 10; i++) {
      m2.put("" + i, "Test");
    }
    long v1 = s.incrementVersion();
    assertEquals(1, v1);
    assertEquals(1, s.getCurrentVersion());
    MVMap<String, String> m1 = s.openMap("data1", String.class, String.class);
    assertEquals("Test", m2.get("1"));
    m.put("1", "Hallo");
    m0.put("1", "Hallo");
    m1.put("1", "Hallo");
    m2.clear();
    assertEquals("Hallo", m.get("1"));
    assertEquals("Hallo", m1.get("1"));
    s.rollbackTo(v1);
    assertEquals(1, s.getCurrentVersion());
    for (int i = 0; i < 10; i++) {
      assertEquals("Test", m2.get("" + i));
    }
    assertEquals("Hello", m.get("1"));
    assertNull(m0.get("1"));
    assertTrue(m1.isClosed());
    assertFalse(m0.isReadOnly());
    assertTrue(m1.isReadOnly());
    s.close();
  }
Exemplo n.º 3
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);
 }