Search in sources :

Example 6 with VCursor

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

Example 7 with VCursor

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

Example 8 with VCursor

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());
}
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)

Example 9 with VCursor

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

Example 10 with VCursor

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

Aggregations

VCursor (de.fhg.igd.mongomvcc.VCursor)13 Test (org.junit.Test)11 VCollection (de.fhg.igd.mongomvcc.VCollection)7 DBCursor (com.mongodb.DBCursor)2 VBranch (de.fhg.igd.mongomvcc.VBranch)2 HashMap (java.util.HashMap)2 VDatabase (de.fhg.igd.mongomvcc.VDatabase)1 VFactory (de.fhg.igd.mongomvcc.VFactory)1 MongoDBVFactory (de.fhg.igd.mongomvcc.impl.MongoDBVFactory)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 FloatBuffer (java.nio.FloatBuffer)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Ignore (org.junit.Ignore)1