use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class MongoDBVCollectionTest method rollback.
/**
* Tests if changes to the index can be rolled back
*/
@Test
public void rollback() {
VCollection persons = _master.getCollection("persons");
assertEquals(0, persons.find().size());
putPerson("Max", 6);
assertEquals(1, persons.find().size());
_master.rollback();
assertEquals(0, persons.find().size());
}
use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class MongoDBVDatabaseBenchmark method mvccInsertDeleteInsertQuery.
/**
* Queries a lot of objects after inserting, deleting and inserting again
*/
@Test
@BenchmarkOptions(benchmarkRounds = 2, warmupRounds = 1)
public void mvccInsertDeleteInsertQuery() {
mvccInsertDeleteInsert();
VCollection coll = _master.getCollection("persons");
for (Map<String, Object> o : coll.find()) {
assertTrue(((Long) o.get("age")).longValue() >= DOCUMENTS);
}
}
use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class MongoDBVMaintenanceTest method makeUnreferencedDocuments.
private Object[] makeUnreferencedDocuments() throws InterruptedException {
long[] r = new long[3];
putPerson("Max", 6);
long cid1 = _master.commit();
putPerson("Brenda", 40);
_master.commit();
Map<String, Object> elvis = putPerson("Elvis", 3);
r[0] = (Long) elvis.get(MongoDBConstants.ID);
VBranch master2 = _db.createBranch("master2", cid1);
VCollection persons2 = master2.getCollection("persons");
persons2.insert(_factory.createDocument("name", "Howard"));
master2.commit();
Map<String, Object> fritz = _factory.createDocument("name", "Fritz");
persons2.insert(fritz);
r[1] = (Long) fritz.get(MongoDBConstants.ID);
long stime = System.currentTimeMillis();
Thread.sleep(500);
Map<String, Object> david = _factory.createDocument("name", "David");
persons2.insert(david);
r[2] = (Long) david.get(MongoDBConstants.ID);
return new Object[] { r, stime };
}
use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class IndexTest method loadingOrder.
/**
* This test checks if indexes are loaded in the correct order:
* oldest should be first, newest come later.
*/
@Test
public void loadingOrder() {
VCollection persons = _master.getCollection("persons");
// add two test objects to 'persons' collection
Map<String, Object> elvis = _factory.createDocument();
elvis.put("name", "elvis");
elvis.put("age", "2");
persons.insert(elvis);
Map<String, Object> max = _factory.createDocument();
max.put("name", "max");
max.put("age", "3");
persons.insert(max);
// save commit and objects currently stored in the database
long first = _master.commit();
ArrayList<String> beforeInSession = new ArrayList<String>();
for (Map<String, Object> person : persons.find()) {
beforeInSession.add(person.toString());
}
// change an object and insert it again (i.e. update it)
elvis.put("age", "4");
persons.insert(elvis);
// save commit and objects now stored in the database
long second = _master.commit();
ArrayList<String> afterInSession = new ArrayList<String>();
for (Map<String, Object> person : persons.find()) {
afterInSession.add(person.toString());
}
// checkout old commit and save objects stored in the database
VBranch oldMaster = _db.checkout(first);
VCollection oldWells = oldMaster.getCollection("persons");
ArrayList<String> beforeOutOfSession = new ArrayList<String>();
for (Map<String, Object> person : oldWells.find()) {
beforeOutOfSession.add(person.toString());
}
// checkout new commit and save objects stored in the database
VBranch newMaster = _db.checkout(second);
VCollection newWells = newMaster.getCollection("persons");
ArrayList<String> afterOutOfSession = new ArrayList<String>();
for (Map<String, Object> person : newWells.find()) {
afterOutOfSession.add(person.toString());
}
// compare stored objects
assertArrayEquals(beforeInSession.toArray(), beforeOutOfSession.toArray());
assertArrayEquals(afterInSession.toArray(), afterOutOfSession.toArray());
}
use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class TreeTest method history.
/**
* Tests if the history works correctly
*/
@Test
public void history() {
long root = _master.getHead();
putPerson("Max", 3);
long c1 = _master.commit();
putPerson("Peter", 26);
long c2 = _master.commit();
VHistory h = _db.getHistory();
assertEquals(c1, h.getParent(c2));
assertEquals(root, h.getParent(c1));
assertEquals(0, h.getParent(root));
assertArrayEquals(new long[] { root }, h.getChildren(0));
assertArrayEquals(new long[] { c1 }, h.getChildren(root));
assertArrayEquals(new long[] { c2 }, h.getChildren(c1));
assertArrayEquals(new long[0], h.getChildren(c2));
VBranch master2 = _db.createBranch("master2", c1);
VCollection persons = master2.getCollection("persons");
persons.insert(_factory.createDocument("name", "Elvis"));
long c3 = master2.commit();
h = _db.getHistory();
assertEquals(c1, h.getParent(c2));
assertEquals(c1, h.getParent(c3));
assertEquals(root, h.getParent(c1));
assertEquals(0, h.getParent(root));
assertArrayEquals(new long[] { root }, h.getChildren(0));
assertArrayEquals(new long[] { c1 }, h.getChildren(root));
long[] c1c = h.getChildren(c1);
assertEquals(2, c1c.length);
assertTrue((c1c[0] == c2 && c1c[1] == c3) || (c1c[0] == c3 && c1c[1] == c2));
assertArrayEquals(new long[0], h.getChildren(c2));
assertArrayEquals(new long[0], h.getChildren(c3));
}
Aggregations