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