use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestMVStore method testIsEmpty.
private void testIsEmpty() throws Exception {
MVStore s = new MVStore.Builder().pageSplitSize(50).open();
Map<Integer, byte[]> m = s.openMap("data");
m.put(1, new byte[50]);
m.put(2, new byte[50]);
m.put(3, new byte[50]);
m.remove(1);
m.remove(2);
m.remove(3);
assertEquals(0, m.size());
assertTrue(m.isEmpty());
s.close();
}
use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestMVStore method testLargerThan2G.
private void testLargerThan2G() {
if (!config.big) {
return;
}
String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName);
MVStore store = new MVStore.Builder().cacheSize(16).fileName(fileName).open();
try {
MVMap<Integer, String> map = store.openMap("test");
long last = System.nanoTime();
String data = new String(new char[2500]).replace((char) 0, 'x');
for (int i = 0; ; i++) {
map.put(i, data);
if (i % 10000 == 0) {
store.commit();
long time = System.nanoTime();
if (time - last > TimeUnit.SECONDS.toNanos(2)) {
long mb = store.getFileStore().size() / 1024 / 1024;
trace(mb + "/4500");
if (mb > 4500) {
break;
}
last = time;
}
}
}
store.commit();
store.close();
} finally {
store.closeImmediately();
}
FileUtils.delete(fileName);
}
use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestMVStore method testConcurrentOpen.
private void testConcurrentOpen() {
String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName);
MVStore s = new MVStore.Builder().fileName(fileName).open();
try {
MVStore s1 = new MVStore.Builder().fileName(fileName).open();
s1.close();
fail();
} catch (IllegalStateException e) {
// expected
}
try {
MVStore s1 = new MVStore.Builder().fileName(fileName).readOnly().open();
s1.close();
fail();
} catch (IllegalStateException e) {
// expected
}
assertFalse(s.getFileStore().isReadOnly());
s.close();
s = new MVStore.Builder().fileName(fileName).readOnly().open();
assertTrue(s.getFileStore().isReadOnly());
s.close();
}
use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestMVStore method testExample.
private void testExample() {
String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName);
// open the store (in-memory if fileName is null)
MVStore s = MVStore.open(fileName);
// create/get the map named "data"
MVMap<Integer, String> map = s.openMap("data");
// add and read some data
map.put(1, "Hello World");
// System.out.println(map.get(1));
// close the store (this will persist changes)
s.close();
s = MVStore.open(fileName);
map = s.openMap("data");
assertEquals("Hello World", map.get(1));
s.close();
}
use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestMVStore method testWriteBuffer.
private void testWriteBuffer() {
String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName);
MVStore s;
MVMap<Integer, byte[]> m;
byte[] data = new byte[1000];
long lastSize = 0;
int len = 1000;
for (int bs = 0; bs <= 1; bs++) {
s = new MVStore.Builder().fileName(fileName).autoCommitBufferSize(bs).open();
m = s.openMap("data");
for (int i = 0; i < len; i++) {
m.put(i, data);
}
long size = s.getFileStore().size();
assertTrue("last:" + lastSize + " now: " + size, size > lastSize);
lastSize = size;
s.close();
}
s = new MVStore.Builder().fileName(fileName).open();
m = s.openMap("data");
assertTrue(m.containsKey(1));
m.put(-1, data);
s.commit();
m.put(-2, data);
s.close();
s = new MVStore.Builder().fileName(fileName).open();
m = s.openMap("data");
assertTrue(m.containsKey(-1));
assertTrue(m.containsKey(-2));
s.close();
FileUtils.delete(fileName);
}
Aggregations