use of de.fhg.igd.mongomvcc.VCollection 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.VCollection 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.VCollection in project mongomvcc by igd-geo.
the class MongoDBVCollectionTest method insertIntoIndex.
/**
* Tests if a person can be added into the local index
*/
@Test
public void insertIntoIndex() {
VCollection persons = _master.getCollection("persons");
assertNotNull(persons);
Map<String, Object> peter = putPerson("Peter", 26);
VCursor c = persons.find();
assertEquals(1, c.size());
Map<String, Object> peter2 = c.iterator().next();
assertDocEquals(peter, peter2);
}
use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class MongoDBVCollectionTest method deleteByExample.
/**
* Deletes an object by example
* @throws Exception if something goes wrong
*/
@Test
public void deleteByExample() throws Exception {
putPerson("Max", 6);
Map<String, Object> p = putPerson("Peter", 26);
VCollection persons = _master.getCollection("persons");
assertEquals(2, persons.find().size());
persons.delete(_factory.createDocument("name", "Max"));
VCursor ps = persons.find();
assertEquals(1, ps.size());
assertDocEquals(p, ps.iterator().next());
}
use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class MongoDBVCollectionTest method delete.
/**
* Deletes an object from the database and tests if other threads
* can see this change after a commit
* @throws Exception if something goes wrong
*/
@Test
public void delete() throws Exception {
putPerson("Max", 6);
//I knew it!
putPerson("Elvis", 3);
Map<String, Object> p = putPerson("Peter", 26);
_master.commit();
VCollection persons = _master.getCollection("persons");
assertEquals(3, persons.find().size());
persons.delete((Long) p.get("uid"));
_master.commit();
assertEquals(2, persons.find().size());
final Integer[] tresult = new Integer[1];
Thread t = new Thread() {
@Override
public void run() {
VCollection persons = _master.getCollection("persons");
tresult[0] = persons.find().size();
}
};
t.start();
t.join();
assertEquals(Integer.valueOf(2), tresult[0]);
}
Aggregations