Search in sources :

Example 16 with VCollection

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());
}
Also used : VBranch(de.fhg.igd.mongomvcc.VBranch) VException(de.fhg.igd.mongomvcc.VException) VCollection(de.fhg.igd.mongomvcc.VCollection) Test(org.junit.Test)

Example 17 with VCollection

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")));
}
Also used : VBranch(de.fhg.igd.mongomvcc.VBranch) VCollection(de.fhg.igd.mongomvcc.VCollection) Test(org.junit.Test)

Example 18 with VCollection

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);
}
Also used : VCursor(de.fhg.igd.mongomvcc.VCursor) VCollection(de.fhg.igd.mongomvcc.VCollection) Test(org.junit.Test)

Example 19 with VCollection

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());
}
Also used : VCursor(de.fhg.igd.mongomvcc.VCursor) VCollection(de.fhg.igd.mongomvcc.VCollection) Test(org.junit.Test)

Example 20 with VCollection

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]);
}
Also used : VCollection(de.fhg.igd.mongomvcc.VCollection) Test(org.junit.Test)

Aggregations

VCollection (de.fhg.igd.mongomvcc.VCollection)22 Test (org.junit.Test)17 VBranch (de.fhg.igd.mongomvcc.VBranch)10 VCursor (de.fhg.igd.mongomvcc.VCursor)7 BasicDBObject (com.mongodb.BasicDBObject)4 AbstractMongoDBVDatabaseTest (de.fhg.igd.mongomvcc.impl.AbstractMongoDBVDatabaseTest)3 HashMap (java.util.HashMap)3 BenchmarkOptions (com.carrotsearch.junitbenchmarks.BenchmarkOptions)2 DBCursor (com.mongodb.DBCursor)2 DBObject (com.mongodb.DBObject)2 VDatabase (de.fhg.igd.mongomvcc.VDatabase)2 Ignore (org.junit.Ignore)2 VException (de.fhg.igd.mongomvcc.VException)1 VFactory (de.fhg.igd.mongomvcc.VFactory)1 VHistory (de.fhg.igd.mongomvcc.VHistory)1 MongoDBVDatabase (de.fhg.igd.mongomvcc.impl.MongoDBVDatabase)1 MongoDBVFactory (de.fhg.igd.mongomvcc.impl.MongoDBVFactory)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1