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);
}
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]);
}
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"));
}
Aggregations