use of de.fhg.igd.mongomvcc.VBranch 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.VBranch in project mongomvcc by igd-geo.
the class MongoDBVBranchTest method createBranchAfterConflict.
/**
* Creates another branch after a conflict has happened
*/
@Test
public void createBranchAfterConflict() {
VBranch master2 = _db.checkout(VConstants.MASTER);
putPerson("Max", 3);
VCollection persons2 = master2.getCollection("persons");
persons2.insert(_factory.createDocument("name", "Elvis"));
long masterCid = _master.commit();
try {
master2.commit();
fail("We expect a VException here since the branch's head " + "could not be updated");
} catch (VException e) {
// this is what we expect here
}
// committing master2 failed, but the commit is still there
long master2Cid = master2.getHead();
assertTrue(masterCid != master2Cid);
_db.createBranch("master2", master2Cid);
VBranch master = _db.checkout(VConstants.MASTER);
assertEquals(masterCid, master.getHead());
master2 = _db.checkout("master2");
assertEquals(master2Cid, master2.getHead());
}
use of de.fhg.igd.mongomvcc.VBranch in project mongomvcc by igd-geo.
the class MongoDBVBranchTest method branch.
/**
* Creates another branch and tests its isolation against the master branch
*/
@Test
public void branch() {
putPerson("Peter", 26);
long peterCid = _master.commit();
VBranch maxBranch = _db.createBranch("Max", peterCid);
VCollection maxPersons = maxBranch.getCollection("persons");
assertEquals(1, maxPersons.find().size());
maxPersons.insert(_factory.createDocument("name", "Max"));
long maxCid = maxBranch.commit();
maxBranch = _db.checkout("Max");
assertEquals(maxCid, maxBranch.getHead());
VBranch peterBranch = _db.checkout(VConstants.MASTER);
assertEquals(peterCid, peterBranch.getHead());
maxPersons = maxBranch.getCollection("persons");
VCollection peterPersons = peterBranch.getCollection("persons");
assertEquals(2, maxPersons.find().size());
assertEquals(1, peterPersons.find().size());
assertNotNull(maxPersons.findOne(_factory.createDocument("name", "Max")));
assertNull(peterPersons.findOne(_factory.createDocument("name", "Max")));
putPerson("Elvis", 3);
long elvisCid = _master.commit();
maxBranch = _db.checkout("Max");
peterBranch = _db.checkout(VConstants.MASTER);
assertEquals(maxCid, maxBranch.getHead());
assertEquals(elvisCid, peterBranch.getHead());
maxPersons = maxBranch.getCollection("persons");
peterPersons = peterBranch.getCollection("persons");
assertEquals(2, maxPersons.find().size());
assertEquals(2, peterPersons.find().size());
assertNotNull(maxPersons.findOne(_factory.createDocument("name", "Max")));
assertNull(peterPersons.findOne(_factory.createDocument("name", "Max")));
assertNotNull(peterPersons.findOne(_factory.createDocument("name", "Elvis")));
assertNull(maxPersons.findOne(_factory.createDocument("name", "Elvis")));
}
use of de.fhg.igd.mongomvcc.VBranch 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.VBranch 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