use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class MongoDBVLargeCollectionTest method largeObjectByte.
/**
* Tests if large objects with byte arrays/streams/buffers can be saved in the database
* @throws Exception if something goes wrong
*/
@Test
public void largeObjectByte() throws Exception {
VCollection coll = _master.getLargeCollection("images");
byte[] test = new byte[1024 * 1024];
for (int i = 0; i < test.length; ++i) {
test[i] = (byte) (i & 0xFF);
}
Map<String, Object> obj = new HashMap<String, Object>();
obj.put("name", "Mona Lisa");
obj.put("data", test);
coll.insert(obj);
VCursor vc = coll.find();
assertEquals(1, vc.size());
Map<String, Object> obj2 = vc.iterator().next();
assertEquals("Mona Lisa", obj2.get("name"));
assertArrayEquals(test, (byte[]) obj2.get("data"));
ByteArrayInputStream bais = new ByteArrayInputStream(test);
obj = new HashMap<String, Object>();
obj.put("name", "Mona Lisa");
obj.put("data", bais);
coll.insert(obj);
Map<String, Object> obj3 = coll.findOne(_factory.createDocument("uid", obj.get("uid")));
assertEquals("Mona Lisa", obj3.get("name"));
InputStream is3 = (InputStream) obj3.get("data");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[64 * 1024];
int read;
while ((read = is3.read(buf)) > 0) {
baos.write(buf, 0, read);
}
assertArrayEquals(test, baos.toByteArray());
ByteBuffer bb = ByteBuffer.wrap(test);
obj = new HashMap<String, Object>();
obj.put("name", "Mona Lisa");
obj.put("data", bb);
coll.insert(obj);
Map<String, Object> obj4 = coll.findOne(_factory.createDocument("uid", obj.get("uid")));
assertEquals("Mona Lisa", obj4.get("name"));
ByteBuffer bb4 = (ByteBuffer) obj4.get("data");
bb4.rewind();
byte[] test4 = new byte[bb4.remaining()];
bb4.get(test4);
assertArrayEquals(test, test4);
}
use of de.fhg.igd.mongomvcc.VCollection 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 };
}
use of de.fhg.igd.mongomvcc.VCollection 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();
}
use of de.fhg.igd.mongomvcc.VCollection 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"));
}
use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class MongoDBVCollectionTest method lifetimeDeletedOptimization.
/**
* Tests if lifetime optimization takes effect. Objects that have
* been deleted should not be loaded but filtered out on the
* database level already.
*/
@Test
public void lifetimeDeletedOptimization() {
//insert two documents to skip in-index shortcut
putPerson("Max", 6);
putPerson("Pax", 8);
_master.commit();
VCollection persons = _master.getCollection("persons");
VCursor cursor = persons.find();
DBCursor dbcursor = extractDBCursor(cursor);
assertEquals(2, cursor.size());
assertTrue(hasAttachedFilter(cursor));
assertEquals(2, dbcursor.size());
putPerson("Elvis", 3);
_master.commit();
persons = _master.getCollection("persons");
cursor = persons.find();
dbcursor = extractDBCursor(cursor);
assertEquals(3, cursor.size());
assertTrue(hasAttachedFilter(cursor));
assertEquals(3, dbcursor.size());
persons.delete(_factory.createDocument("name", "Max"));
_master.commit();
persons = _master.getCollection("persons");
cursor = persons.find();
dbcursor = extractDBCursor(cursor);
assertEquals(2, cursor.size());
assertTrue(hasAttachedFilter(cursor));
assertEquals(2, dbcursor.size());
}
Aggregations