use of de.fhg.igd.mongomvcc.VCursor in project mongomvcc by igd-geo.
the class MongoDBVLargeCollectionTest method largeObjectFloat.
/**
* Tests if large objects with float arrays/streams/buffers can be saved in the database
* @throws Exception if something goes wrong
*/
@Test
public void largeObjectFloat() throws Exception {
VCollection coll = _master.getLargeCollection("images");
float[] test = new float[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, (float[]) obj2.get("data"), 0.00001f);
FloatBuffer bb = FloatBuffer.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"));
FloatBuffer bb4 = (FloatBuffer) obj4.get("data");
bb4.rewind();
float[] test4 = new float[bb4.remaining()];
bb4.get(test4);
assertArrayEquals(test, test4, 0.00001f);
}
use of de.fhg.igd.mongomvcc.VCursor in project mongomvcc by igd-geo.
the class MongoDBVCollectionTest method findNone.
/**
* Tests what happens if a query returns an empty result
*/
@Test
public void findNone() {
for (int i = 0; i < 20; ++i) {
putPerson(String.valueOf(i), i);
}
_master.commit();
VCursor vc = _master.getCollection("persons").find(_factory.createDocument("name", "100"));
assertEquals(0, vc.size());
}
use of de.fhg.igd.mongomvcc.VCursor 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());
}
use of de.fhg.igd.mongomvcc.VCursor in project mongomvcc by igd-geo.
the class MongoDBVCollectionTest method findFields.
/**
* Tests if a partial object can be retrieved
*/
@Test
public void findFields() {
putPerson("Peter", 26);
_master.commit();
VCursor vc = _master.getCollection("persons").find(_factory.createDocument("name", "Peter"), "name");
assertEquals(1, vc.size());
Map<String, Object> p = vc.iterator().next();
assertEquals("Peter", p.get("name"));
assertNull(p.get("age"));
assertNotNull(p.get("_id"));
assertNotNull(p.get("uid"));
// name, UID and OID
assertEquals(3, p.size());
}
use of de.fhg.igd.mongomvcc.VCursor 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());
}
Aggregations