Search in sources :

Example 1 with VBranch

use of de.fhg.igd.mongomvcc.VBranch in project mongomvcc by igd-geo.

the class IndexTest method stackOverflow.

/**
 * This test checks if a stack overflows when there are too many commits in the database.
 * See https://github.com/igd-geo/mongomvcc/pull/2 for more information.
 * @throws StackOverflowError if the test fails
 */
@Test
@Ignore("Really slow. Not necessary in all situations. See GitHub issue for more information.")
public void stackOverflow() throws StackOverflowError {
    VCollection persons = _master.getCollection("stack");
    Map<String, Object> elvis = _factory.createDocument();
    elvis.put("name", "elvis");
    for (int i = 0; i < 2500; i++) {
        persons.insert(elvis);
        _master.commit();
    }
    VDatabase db = _factory.createDatabase();
    db.connect(((MongoDBVDatabase) _db).getDB().getName());
    VBranch master = db.checkout(VConstants.MASTER);
    persons = master.getCollection("stack");
    persons.find().size();
}
Also used : VDatabase(de.fhg.igd.mongomvcc.VDatabase) MongoDBVDatabase(de.fhg.igd.mongomvcc.impl.MongoDBVDatabase) MongoDBVDatabase(de.fhg.igd.mongomvcc.impl.MongoDBVDatabase) VBranch(de.fhg.igd.mongomvcc.VBranch) VCollection(de.fhg.igd.mongomvcc.VCollection) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractMongoDBVDatabaseTest(de.fhg.igd.mongomvcc.impl.AbstractMongoDBVDatabaseTest)

Example 2 with VBranch

use of de.fhg.igd.mongomvcc.VBranch in project mongomvcc by igd-geo.

the class MongoDBVBranchTest method goBackInTime.

/**
 * Tests if a previous version of a collection can be checked out
 * @throws Exception if something goes wrong
 */
@Test
public void goBackInTime() throws Exception {
    Map<String, Object> max = putPerson("Max", 6);
    long oldCid = _master.commit();
    VCollection persons = _master.getCollection("persons");
    Map<String, Object> max2 = persons.findOne(_factory.createDocument("name", "Max"));
    assertEquals(6, max2.get("age"));
    max.put("age", 7);
    persons.insert(max);
    _master.commit();
    persons = _master.getCollection("persons");
    max2 = persons.findOne(_factory.createDocument("name", "Max"));
    assertEquals(7, max2.get("age"));
    VBranch oldMaster = _db.checkout(oldCid);
    persons = oldMaster.getCollection("persons");
    max2 = persons.findOne(_factory.createDocument("name", "Max"));
    assertEquals(6, max2.get("age"));
}
Also used : VBranch(de.fhg.igd.mongomvcc.VBranch) VCollection(de.fhg.igd.mongomvcc.VCollection) Test(org.junit.Test)

Example 3 with VBranch

use of de.fhg.igd.mongomvcc.VBranch in project mongomvcc by igd-geo.

the class MongoDBVMaintenanceTest method makeDanglingCommits.

private Object[] makeDanglingCommits() throws InterruptedException {
    putPerson("Max", 6);
    long cid1 = _master.commit();
    VBranch master2 = _db.createBranch("master2", cid1);
    putPerson("Elvis", 3);
    long cid2 = _master.commit();
    VBranch master3 = _db.createBranch("master3", cid2);
    VCollection persons2 = master2.getCollection("persons");
    persons2.insert(_factory.createDocument("name", "Pax"));
    long cid3 = master2.commit();
    VCollection persons3 = master3.getCollection("persons");
    persons3.insert(_factory.createDocument("name", "Peter"));
    long cid4 = master3.commit();
    VBranch master1a = _db.checkout(cid2);
    VCollection persons1a = master1a.getCollection("persons");
    persons1a.insert(_factory.createDocument("name", "Tom"));
    long cid5 = master1a.commit();
    VBranch master2a = _db.checkout(cid3);
    VCollection persons2a = master2a.getCollection("persons");
    persons2a.insert(_factory.createDocument("name", "Bob"));
    long cid6 = master2a.commit();
    VBranch master3a = _db.checkout(cid4);
    VCollection persons3a = master3a.getCollection("persons");
    persons3a.insert(_factory.createDocument("name", "Howard"));
    long cid7 = master3a.commit();
    long stime = System.currentTimeMillis();
    Thread.sleep(500);
    persons3a.insert(_factory.createDocument("name", "Brenda"));
    long cid8 = master3a.commit();
    return new Object[] { new long[] { cid5, cid6, cid7, cid8 }, stime };
}
Also used : VBranch(de.fhg.igd.mongomvcc.VBranch) BasicDBObject(com.mongodb.BasicDBObject) VCollection(de.fhg.igd.mongomvcc.VCollection)

Example 4 with VBranch

use of de.fhg.igd.mongomvcc.VBranch in project mongomvcc by igd-geo.

the class FiveMinutes method main.

/**
 * Runs the tutorial
 * @param args the program arguments
 */
public static void main(String[] args) {
    // 1. Connect to a database
    VFactory factory = new MongoDBVFactory();
    VDatabase db = factory.createDatabase();
    db.connect("mongomvcc-five-minutes-tutorial");
    // Checkout the "master" branch
    VBranch master = db.checkout(VConstants.MASTER);
    // 2. Put something into the index
    VCollection persons = master.getCollection("persons");
    Map<String, Object> elvis = factory.createDocument();
    elvis.put("name", "Elvis");
    elvis.put("age", 3);
    persons.insert(elvis);
    // insert another person
    persons.insert(factory.createDocument("name", "Peter"));
    // 3. Commit index to the database
    long firstCid = master.commit();
    // 4. Read documents from the database
    VCursor c = persons.find();
    for (Map<String, Object> person : c) {
        System.out.print("Person { name: " + person.get("name"));
        if (person.containsKey("age")) {
            System.out.print(", age: " + person.get("age"));
        }
        System.out.println(" }");
    }
    Map<String, Object> elvis2 = persons.findOne(factory.createDocument("name", "Elvis"));
    if (elvis2 != null) {
        System.out.println("Elvis lives!");
    }
    // 5. Make another commit
    persons.insert(factory.createDocument("name", "Max"));
    elvis.put("age", 4);
    persons.insert(elvis);
    master.commit();
    // 6. Checkout a previous version
    System.out.println("There are " + persons.find().size() + " persons");
    Map<String, Object> elvis3 = persons.findOne(factory.createDocument("name", "Elvis"));
    System.out.println("Elvis is now " + elvis3.get("age") + " years old");
    VBranch oldMaster = db.checkout(firstCid);
    VCollection oldPersons = oldMaster.getCollection("persons");
    System.out.println("Previously, there were only " + oldPersons.find().size() + " persons");
    Map<String, Object> oldElvis = oldPersons.findOne(factory.createDocument("name", "Elvis"));
    System.out.println("Last year, Elvis was " + oldElvis.get("age") + " years old");
    // 7. Drop the database
    db.drop();
}
Also used : VDatabase(de.fhg.igd.mongomvcc.VDatabase) VBranch(de.fhg.igd.mongomvcc.VBranch) VFactory(de.fhg.igd.mongomvcc.VFactory) MongoDBVFactory(de.fhg.igd.mongomvcc.impl.MongoDBVFactory) MongoDBVFactory(de.fhg.igd.mongomvcc.impl.MongoDBVFactory) VCursor(de.fhg.igd.mongomvcc.VCursor) VCollection(de.fhg.igd.mongomvcc.VCollection)

Example 5 with VBranch

use of de.fhg.igd.mongomvcc.VBranch in project mongomvcc by igd-geo.

the class MongoDBVCollectionTest method lifetimeInsertedLaterOptimization.

/**
 * Tests if lifetime optimization takes effect. Objects that have
 * been inserted in a later commit should not be loaded but filtered
 * out on the database level already.
 */
@Test
@Ignore("Not ready yet. We need to implement full branch history.")
public void lifetimeInsertedLaterOptimization() {
    // ignore this test if we're on MongoDB 1.x
    assumeNotNull(((MongoDBVDatabase) _db).getBuildInfo());
    assumeTrue(((MongoDBVDatabase) _db).getBuildInfo().getMajorVersion() >= 2);
    // insert two documents to skip in-index shortcut
    putPerson("Max", 6);
    putPerson("Pax", 8);
    long firstCID = _master.commit();
    putPerson("Elvis", 3);
    _master.commit();
    VBranch oldMaster = _db.checkout(firstCID);
    VCollection persons = oldMaster.getCollection("persons");
    VCursor cursor = persons.find();
    DBCursor dbcursor = extractDBCursor(cursor);
    assertEquals(2, cursor.size());
    assertTrue(hasAttachedFilter(cursor));
    assertEquals(2, dbcursor.size());
}
Also used : DBCursor(com.mongodb.DBCursor) VBranch(de.fhg.igd.mongomvcc.VBranch) VCursor(de.fhg.igd.mongomvcc.VCursor) VCollection(de.fhg.igd.mongomvcc.VCollection) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

VBranch (de.fhg.igd.mongomvcc.VBranch)10 VCollection (de.fhg.igd.mongomvcc.VCollection)10 Test (org.junit.Test)7 AbstractMongoDBVDatabaseTest (de.fhg.igd.mongomvcc.impl.AbstractMongoDBVDatabaseTest)3 BasicDBObject (com.mongodb.BasicDBObject)2 VCursor (de.fhg.igd.mongomvcc.VCursor)2 VDatabase (de.fhg.igd.mongomvcc.VDatabase)2 Ignore (org.junit.Ignore)2 DBCursor (com.mongodb.DBCursor)1 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 ArrayList (java.util.ArrayList)1