Search in sources :

Example 11 with VCollection

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

Example 12 with VCollection

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);
    }
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) VCollection(de.fhg.igd.mongomvcc.VCollection) Test(org.junit.Test) BenchmarkOptions(com.carrotsearch.junitbenchmarks.BenchmarkOptions)

Example 13 with VCollection

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 };
}
Also used : VBranch(de.fhg.igd.mongomvcc.VBranch) BasicDBObject(com.mongodb.BasicDBObject) VCollection(de.fhg.igd.mongomvcc.VCollection)

Example 14 with VCollection

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

Example 15 with VCollection

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

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