use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestTransactionStore method testGetModifiedMaps.
private void testGetModifiedMaps() {
MVStore s = MVStore.open(null);
TransactionStore ts = new TransactionStore(s);
ts.init();
Transaction tx;
TransactionMap<String, String> m1, m2, m3;
long sp;
tx = ts.begin();
m1 = tx.openMap("m1");
m2 = tx.openMap("m2");
m3 = tx.openMap("m3");
assertFalse(tx.getChanges(0).hasNext());
tx.commit();
tx = ts.begin();
m1 = tx.openMap("m1");
m2 = tx.openMap("m2");
m3 = tx.openMap("m3");
m1.put("1", "100");
sp = tx.setSavepoint();
m2.put("1", "100");
m3.put("1", "100");
Iterator<Change> it = tx.getChanges(sp);
assertTrue(it.hasNext());
Change c;
c = it.next();
assertEquals("m3", c.mapName);
assertEquals("1", c.key.toString());
assertNull(c.value);
assertTrue(it.hasNext());
c = it.next();
assertEquals("m2", c.mapName);
assertEquals("1", c.key.toString());
assertNull(c.value);
assertFalse(it.hasNext());
it = tx.getChanges(0);
assertTrue(it.hasNext());
c = it.next();
assertEquals("m3", c.mapName);
assertEquals("1", c.key.toString());
assertNull(c.value);
assertTrue(it.hasNext());
c = it.next();
assertEquals("m2", c.mapName);
assertEquals("1", c.key.toString());
assertNull(c.value);
assertTrue(it.hasNext());
c = it.next();
assertEquals("m1", c.mapName);
assertEquals("1", c.key.toString());
assertNull(c.value);
assertFalse(it.hasNext());
tx.rollbackToSavepoint(sp);
it = tx.getChanges(0);
assertTrue(it.hasNext());
c = it.next();
assertEquals("m1", c.mapName);
assertEquals("1", c.key.toString());
assertNull(c.value);
assertFalse(it.hasNext());
tx.commit();
s.close();
}
use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestKillProcessWhileWriting method write.
private int write() {
MVStore s;
MVMap<Integer, byte[]> m;
s = new MVStore.Builder().fileName(fileName).pageSplitSize(50).autoCommitDisabled().open();
m = s.openMap("data");
Random r = new Random(seed);
int op = 0;
try {
for (; op < 100; op++) {
int k = r.nextInt(100);
byte[] v = new byte[r.nextInt(100) * 100];
int type = r.nextInt(10);
switch(type) {
case 0:
case 1:
case 2:
case 3:
m.put(k, v);
break;
case 4:
case 5:
m.remove(k);
break;
case 6:
s.commit();
break;
case 7:
s.compact(80, 1024);
break;
case 8:
m.clear();
break;
case 9:
s.close();
s = new MVStore.Builder().fileName(fileName).pageSplitSize(50).autoCommitDisabled().open();
m = s.openMap("data");
break;
}
}
s.close();
return 0;
} catch (Exception e) {
s.closeImmediately();
return op;
}
}
use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestMVStore method testRenameMapRollback.
private void testRenameMapRollback() {
MVStore s = openStore(null);
MVMap<Integer, Integer> map;
map = s.openMap("hello");
map.put(1, 10);
long old = s.commit();
s.renameMap(map, "world");
map.put(2, 20);
assertEquals("world", map.getName());
s.rollbackTo(old);
assertEquals("hello", map.getName());
s.rollbackTo(0);
assertTrue(map.isClosed());
s.close();
}
use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestMVStore method testIterateOldVersion.
private void testIterateOldVersion() {
MVStore s;
Map<Integer, Integer> map;
s = new MVStore.Builder().open();
map = s.openMap("test");
int len = 100;
for (int i = 0; i < len; i++) {
map.put(i, 10 * i);
}
Iterator<Integer> it = map.keySet().iterator();
s.commit();
for (int i = 0; i < len; i += 2) {
map.remove(i);
}
int count = 0;
while (it.hasNext()) {
it.next();
count++;
}
assertEquals(len, count);
s.close();
}
use of org.h2.mvstore.MVStore in project h2database by h2database.
the class TestMVStore method testRollback.
private void testRollback() {
MVStore s = MVStore.open(null);
MVMap<Integer, Integer> m = s.openMap("m");
m.put(1, -1);
s.commit();
for (int i = 0; i < 10; i++) {
m.put(1, i);
s.rollback();
assertEquals(i - 1, m.get(1).intValue());
m.put(1, i);
s.commit();
}
}
Aggregations