Search in sources :

Example 1 with OffHeapStore

use of org.h2.mvstore.OffHeapStore in project h2database by h2database.

the class TestMVStore method testProvidedFileStoreNotOpenedAndClosed.

private void testProvidedFileStoreNotOpenedAndClosed() {
    final AtomicInteger openClose = new AtomicInteger();
    FileStore fileStore = new OffHeapStore() {

        @Override
        public void open(String fileName, boolean readOnly, char[] encryptionKey) {
            openClose.incrementAndGet();
            super.open(fileName, readOnly, encryptionKey);
        }

        @Override
        public void close() {
            openClose.incrementAndGet();
            super.close();
        }
    };
    MVStore store = new MVStore.Builder().fileStore(fileStore).open();
    store.close();
    assertEquals(0, openClose.get());
}
Also used : MVStore(org.h2.mvstore.MVStore) FileStore(org.h2.mvstore.FileStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OffHeapStore(org.h2.mvstore.OffHeapStore)

Example 2 with OffHeapStore

use of org.h2.mvstore.OffHeapStore in project h2database by h2database.

the class TestMVStore method testOffHeapStorage.

private void testOffHeapStorage() throws Exception {
    OffHeapStore offHeap = new OffHeapStore();
    MVStore s = new MVStore.Builder().fileStore(offHeap).open();
    int count = 1000;
    Map<Integer, String> map = s.openMap("data");
    for (int i = 0; i < count; i++) {
        map.put(i, "Hello " + i);
        s.commit();
    }
    assertTrue(offHeap.getWriteCount() > count);
    s.close();
    s = new MVStore.Builder().fileStore(offHeap).open();
    map = s.openMap("data");
    for (int i = 0; i < count; i++) {
        assertEquals("Hello " + i, map.get(i));
    }
    s.close();
}
Also used : MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OffHeapStore(org.h2.mvstore.OffHeapStore)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MVStore (org.h2.mvstore.MVStore)2 OffHeapStore (org.h2.mvstore.OffHeapStore)2 FileStore (org.h2.mvstore.FileStore)1