Search in sources :

Example 31 with MVStore

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

the class TestStreamStore method testLarge.

private void testLarge() throws IOException {
    String fileName = getBaseDir() + "/testVeryLarge.h3";
    FileUtils.delete(fileName);
    final MVStore s = new MVStore.Builder().fileName(fileName).open();
    MVMap<Long, byte[]> map = s.openMap("data");
    final AtomicInteger count = new AtomicInteger();
    StreamStore streamStore = new StreamStore(map) {

        @Override
        protected void onStore(int len) {
            count.incrementAndGet();
            s.commit();
        }
    };
    long size = 1 * 1024 * 1024;
    streamStore.put(new RandomStream(size, 0));
    s.close();
    assertEquals(4, count.get());
}
Also used : MVStore(org.h2.mvstore.MVStore) StreamStore(org.h2.mvstore.StreamStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 32 with MVStore

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

the class TestKillProcessWhileWriting method verify.

private void verify() {
    MVStore s;
    MVMap<Integer, byte[]> m;
    FileUtils.delete(fileName);
    s = new MVStore.Builder().fileName(fileName).open();
    m = s.openMap("data");
    for (int i = 0; i < 100; i++) {
        byte[] x = m.get(i);
        if (x == null) {
            break;
        }
        assertEquals(i * 100, x.length);
    }
    s.close();
}
Also used : MVStore(org.h2.mvstore.MVStore)

Example 33 with MVStore

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

the class TestMVStore method testCacheInfo.

private void testCacheInfo() {
    String fileName = getBaseDir() + "/" + getTestName();
    FileUtils.delete(fileName);
    MVStore s = new MVStore.Builder().fileName(fileName).cacheSize(2).open();
    assertEquals(2, s.getCacheSize());
    MVMap<Integer, byte[]> map;
    map = s.openMap("data");
    byte[] data = new byte[1024];
    for (int i = 0; i < 1000; i++) {
        map.put(i, data);
        s.commit();
        if (i < 50) {
            assertEquals(0, s.getCacheSizeUsed());
        } else if (i > 300) {
            assertTrue(s.getCacheSizeUsed() >= 1);
        }
    }
    s.close();
    s = new MVStore.Builder().open();
    assertEquals(0, s.getCacheSize());
    assertEquals(0, s.getCacheSizeUsed());
    s.close();
}
Also used : MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 34 with MVStore

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

the class TestMVStore method testMinMaxNextKey.

private void testMinMaxNextKey() {
    MVStore s = openStore(null);
    MVMap<Integer, Integer> map = s.openMap("test");
    map.put(10, 100);
    map.put(20, 200);
    assertEquals(10, map.firstKey().intValue());
    assertEquals(20, map.lastKey().intValue());
    assertEquals(20, map.ceilingKey(15).intValue());
    assertEquals(20, map.ceilingKey(20).intValue());
    assertEquals(10, map.floorKey(15).intValue());
    assertEquals(10, map.floorKey(10).intValue());
    assertEquals(20, map.higherKey(10).intValue());
    assertEquals(10, map.lowerKey(20).intValue());
    final MVMap<Integer, Integer> m = map;
    assertEquals(10, m.ceilingKey(null).intValue());
    assertEquals(10, m.higherKey(null).intValue());
    assertNull(m.lowerKey(null));
    assertNull(m.floorKey(null));
    for (int i = 3; i < 20; i++) {
        s = openStore(null, 4);
        map = s.openMap("test");
        for (int j = 3; j < i; j++) {
            map.put(j * 2, j * 20);
        }
        if (i == 3) {
            assertNull(map.firstKey());
            assertNull(map.lastKey());
        } else {
            assertEquals(6, map.firstKey().intValue());
            int max = (i - 1) * 2;
            assertEquals(max, map.lastKey().intValue());
            for (int j = 0; j < i * 2 + 2; j++) {
                if (j > max) {
                    assertNull(map.ceilingKey(j));
                } else {
                    int ceiling = Math.max((j + 1) / 2 * 2, 6);
                    assertEquals(ceiling, map.ceilingKey(j).intValue());
                }
                int floor = Math.min(max, Math.max(j / 2 * 2, 4));
                if (floor < 6) {
                    assertNull(map.floorKey(j));
                } else {
                    map.floorKey(j);
                }
                int lower = Math.min(max, Math.max((j - 1) / 2 * 2, 4));
                if (lower < 6) {
                    assertNull(map.lowerKey(j));
                } else {
                    assertEquals(lower, map.lowerKey(j).intValue());
                }
                int higher = Math.max((j + 2) / 2 * 2, 6);
                if (higher > max) {
                    assertNull(map.higherKey(j));
                } else {
                    assertEquals(higher, map.higherKey(j).intValue());
                }
            }
        }
    }
}
Also used : MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 35 with MVStore

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

the class TestMVStore method testCloseTwice.

private void testCloseTwice() {
    String fileName = getBaseDir() + "/" + getTestName();
    FileUtils.delete(fileName);
    MVStore s = openStore(fileName);
    MVMap<Integer, String> m = s.openMap("data");
    for (int i = 0; i < 3; i++) {
        m.put(i, "hello " + i);
    }
    // closing twice should be fine
    s.close();
    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