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());
}
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();
}
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();
}
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());
}
}
}
}
}
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();
}
Aggregations