Search in sources :

Example 91 with MVStore

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

the class TestMVStore method testStoreVersion.

private void testStoreVersion() {
    String fileName = getBaseDir() + "/" + getTestName();
    FileUtils.delete(fileName);
    MVStore s = MVStore.open(fileName);
    assertEquals(0, s.getCurrentVersion());
    assertEquals(0, s.getStoreVersion());
    s.setStoreVersion(0);
    s.commit();
    s.setStoreVersion(1);
    s.closeImmediately();
    s = MVStore.open(fileName);
    assertEquals(1, s.getCurrentVersion());
    assertEquals(0, s.getStoreVersion());
    s.setStoreVersion(1);
    s.close();
    s = MVStore.open(fileName);
    assertEquals(2, s.getCurrentVersion());
    assertEquals(1, s.getStoreVersion());
    s.close();
}
Also used : MVStore(org.h2.mvstore.MVStore)

Example 92 with MVStore

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

the class TestMVStore method testEntrySet.

private void testEntrySet() {
    MVStore s = new MVStore.Builder().open();
    MVMap<Integer, Integer> map;
    map = s.openMap("data");
    for (int i = 0; i < 20; i++) {
        map.put(i, i * 10);
    }
    int next = 0;
    for (Entry<Integer, Integer> e : map.entrySet()) {
        assertEquals(next, e.getKey().intValue());
        assertEquals(next * 10, e.getValue().intValue());
        next++;
    }
}
Also used : MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 93 with MVStore

use of org.h2.mvstore.MVStore 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 94 with MVStore

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

the class TestMVStore method testFileFormatChange.

private void testFileFormatChange() {
    String fileName = getBaseDir() + "/" + getTestName();
    FileUtils.delete(fileName);
    MVStore s;
    MVMap<Integer, Integer> m;
    s = openStore(fileName);
    s.setRetentionTime(Integer.MAX_VALUE);
    m = s.openMap("test");
    m.put(1, 1);
    Map<String, Object> header = s.getStoreHeader();
    int format = Integer.parseInt(header.get("format").toString());
    assertEquals(1, format);
    header.put("format", Integer.toString(format + 1));
    forceWriteStoreHeader(s);
    s.close();
    try {
        openStore(fileName).close();
        fail();
    } catch (IllegalStateException e) {
        assertEquals(DataUtils.ERROR_UNSUPPORTED_FORMAT, DataUtils.getErrorCode(e.getMessage()));
    }
    FileUtils.delete(fileName);
}
Also used : MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 95 with MVStore

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

the class TestMVStore method testCompactFully.

private void testCompactFully() throws Exception {
    String fileName = getBaseDir() + "/" + getTestName();
    FileUtils.delete(fileName);
    MVStore s = new MVStore.Builder().fileName(fileName).autoCommitDisabled().open();
    MVMap<Integer, String> m;
    for (int i = 0; i < 100; i++) {
        m = s.openMap("data" + i);
        m.put(0, "Hello World");
        s.commit();
    }
    for (int i = 0; i < 100; i += 2) {
        m = s.openMap("data" + i);
        s.removeMap(m);
        s.commit();
    }
    long sizeOld = s.getFileStore().size();
    s.compactMoveChunks();
    long sizeNew = s.getFileStore().size();
    assertTrue("old: " + sizeOld + " new: " + sizeNew, sizeNew < sizeOld);
    s.close();
}
Also used : MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

MVStore (org.h2.mvstore.MVStore)123 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)69 Random (java.util.Random)23 Task (org.h2.util.Task)20 TransactionStore (org.h2.mvstore.db.TransactionStore)19 Transaction (org.h2.mvstore.db.TransactionStore.Transaction)17 MVRTreeMap (org.h2.mvstore.rtree.MVRTreeMap)8 SpatialKey (org.h2.mvstore.rtree.SpatialKey)8 IOException (java.io.IOException)6 Connection (java.sql.Connection)5 Statement (java.sql.Statement)5 FileStore (org.h2.mvstore.FileStore)5 StreamStore (org.h2.mvstore.StreamStore)5 ArrayList (java.util.ArrayList)4 TreeMap (java.util.TreeMap)4 Store (org.h2.mvstore.db.MVTableEngine.Store)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3 PreparedStatement (java.sql.PreparedStatement)3