Search in sources :

Example 11 with VCursor

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

the class MongoDBVCollectionTest method insertIntoIndex.

/**
 * Tests if a person can be added into the local index
 */
@Test
public void insertIntoIndex() {
    VCollection persons = _master.getCollection("persons");
    assertNotNull(persons);
    Map<String, Object> peter = putPerson("Peter", 26);
    VCursor c = persons.find();
    assertEquals(1, c.size());
    Map<String, Object> peter2 = c.iterator().next();
    assertDocEquals(peter, peter2);
}
Also used : VCursor(de.fhg.igd.mongomvcc.VCursor) VCollection(de.fhg.igd.mongomvcc.VCollection) Test(org.junit.Test)

Example 12 with VCursor

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

the class MongoDBVCollectionTest method isolation.

/**
 * Tests if two threads can work isolated
 * @throws Exception if something goes wrong
 */
@Test
public void isolation() throws Exception {
    final CountDownLatch latch1 = new CountDownLatch(1);
    final CountDownLatch latch2 = new CountDownLatch(1);
    final Integer[] tresult = new Integer[2];
    Thread t = new Thread() {

        @Override
        public void run() {
            VCursor pc = _master.getCollection("persons").find();
            tresult[0] = pc.size();
            Map<String, Object> p1 = pc.iterator().next();
            assertEquals("Peter", p1.get("name"));
            latch2.countDown();
            try {
                latch1.await();
            } catch (InterruptedException e) {
                fail();
                throw new RuntimeException(e);
            }
            VCursor pc2 = _master.getCollection("persons").find();
            tresult[1] = pc2.size();
            Map<String, Object> p2 = pc2.iterator().next();
            assertEquals("Peter", p2.get("name"));
        }
    };
    putPerson("Peter", 26);
    _master.commit();
    assertEquals(1, _master.getCollection("persons").find().size());
    // check that the other thread sees the first person
    t.start();
    latch2.await();
    assertEquals(Integer.valueOf(1), tresult[0]);
    // add another person
    putPerson("Max", 6);
    _master.commit();
    assertEquals(2, _master.getCollection("persons").find().size());
    // check that the other thread does not see the second person
    latch1.countDown();
    t.join();
    assertEquals(Integer.valueOf(1), tresult[1]);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) VCursor(de.fhg.igd.mongomvcc.VCursor) Test(org.junit.Test)

Example 13 with VCursor

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

the class MongoDBVCollectionTest method findMore.

/**
 * Tests if multiple objects matching a given example can be retrieved from a collection
 */
@Test
public void findMore() {
    for (int i = 0; i < 20; ++i) {
        putPerson(String.valueOf(i / 2), i / 2);
    }
    _master.commit();
    VCursor vc = _master.getCollection("persons").find(_factory.createDocument("name", "5"));
    assertEquals(2, vc.size());
    Iterator<Map<String, Object>> it = vc.iterator();
    Map<String, Object> p1 = it.next();
    assertEquals("5", p1.get("name"));
    assertEquals(Integer.valueOf(5), p1.get("age"));
    Map<String, Object> p2 = it.next();
    assertEquals("5", p2.get("name"));
    assertEquals(Integer.valueOf(5), p2.get("age"));
}
Also used : Map(java.util.Map) VCursor(de.fhg.igd.mongomvcc.VCursor) 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