use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestMVStore method testFileHeader.
private void testFileHeader() {
String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName);
MVStore s = openStore(fileName);
s.setRetentionTime(Integer.MAX_VALUE);
long time = System.currentTimeMillis();
Map<String, Object> m = s.getStoreHeader();
assertEquals("1", m.get("format").toString());
long creationTime = (Long) m.get("created");
assertTrue(Math.abs(time - creationTime) < 100);
m.put("test", "123");
forceWriteStoreHeader(s);
s.close();
s = openStore(fileName);
Object test = s.getStoreHeader().get("test");
assertNotNull(test);
assertEquals("123", test.toString());
s.close();
}
use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestMVStore method testRemoveMapRollback.
private void testRemoveMapRollback() {
MVStore store = new MVStore.Builder().open();
MVMap<String, String> map = store.openMap("test");
map.put("1", "Hello");
store.commit();
store.removeMap(map);
store.rollback();
assertTrue(store.hasMap("test"));
map = store.openMap("test");
// TODO the data should get back alive
assertNull(map.get("1"));
store.close();
String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName);
store = new MVStore.Builder().autoCommitDisabled().fileName(fileName).open();
map = store.openMap("test");
map.put("1", "Hello");
store.commit();
store.removeMap(map);
store.rollback();
assertTrue(store.hasMap("test"));
map = store.openMap("test");
// the data will get back alive
assertEquals("Hello", map.get("1"));
store.close();
}
use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestMVStore method testVersionsToKeep2.
private void testVersionsToKeep2() {
MVStore s = new MVStore.Builder().autoCommitDisabled().open();
s.setVersionsToKeep(2);
final MVMap<Integer, String> m = s.openMap("data");
s.commit();
assertEquals(1, s.getCurrentVersion());
m.put(1, "version 1");
s.commit();
assertEquals(2, s.getCurrentVersion());
m.put(1, "version 2");
s.commit();
assertEquals(3, s.getCurrentVersion());
m.put(1, "version 3");
s.commit();
m.put(1, "version 4");
assertEquals("version 4", m.openVersion(4).get(1));
assertEquals("version 3", m.openVersion(3).get(1));
assertEquals("version 2", m.openVersion(2).get(1));
new AssertThrows(IllegalArgumentException.class) {
@Override
public void test() throws Exception {
m.openVersion(1);
}
};
s.close();
}
use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestMVStore method testCustomMapType.
private void testCustomMapType() {
String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName);
MVStore s = openStore(fileName);
SequenceMap seq = s.openMap("data", new SequenceMap.Builder());
StringBuilder buff = new StringBuilder();
for (long x : seq.keySet()) {
buff.append(x).append(';');
}
assertEquals("1;2;3;4;5;6;7;8;9;10;", buff.toString());
s.close();
}
use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestMVStore method testNewerWriteVersion.
private void testNewerWriteVersion() throws Exception {
String fileName = getBaseDir() + "/" + getTestName();
FileUtils.delete(fileName);
MVStore s = new MVStore.Builder().encryptionKey("007".toCharArray()).fileName(fileName).open();
s.setRetentionTime(Integer.MAX_VALUE);
Map<String, Object> header = s.getStoreHeader();
assertEquals("1", header.get("format").toString());
header.put("formatRead", "1");
header.put("format", "2");
forceWriteStoreHeader(s);
MVMap<Integer, String> m = s.openMap("data");
forceWriteStoreHeader(s);
m.put(0, "Hello World");
s.close();
try {
s = new MVStore.Builder().encryptionKey("007".toCharArray()).fileName(fileName).open();
header = s.getStoreHeader();
fail(header.toString());
} catch (IllegalStateException e) {
assertEquals(DataUtils.ERROR_UNSUPPORTED_FORMAT, DataUtils.getErrorCode(e.getMessage()));
}
s = new MVStore.Builder().encryptionKey("007".toCharArray()).readOnly().fileName(fileName).open();
assertTrue(s.getFileStore().isReadOnly());
m = s.openMap("data");
assertEquals("Hello World", m.get(0));
s.close();
FileUtils.setReadOnly(fileName);
s = new MVStore.Builder().encryptionKey("007".toCharArray()).fileName(fileName).open();
assertTrue(s.getFileStore().isReadOnly());
m = s.openMap("data");
assertEquals("Hello World", m.get(0));
s.close();
}
Aggregations