Package de.fhg.igd.mongomvcc

Examples of de.fhg.igd.mongomvcc.VCollection


  /**
   * 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);
  }
View Full Code Here


   * Deletes an object from the index
   */
  @Test
  public void deleteFromIndex() {
    Map<String, Object> p = putPerson("Peter", 26);
    VCollection persons = _master.getCollection("persons");
    assertEquals(1, persons.find().size());
    persons.delete((Long)p.get("uid"));
    assertEquals(0, persons.find().size());
  }
View Full Code Here

  public void delete() throws Exception {
    putPerson("Max", 6);
    putPerson("Elvis", 3); //I knew it!
    Map<String, Object> p = putPerson("Peter", 26);
    _master.commit();
    VCollection persons = _master.getCollection("persons");
    assertEquals(3, persons.find().size());
    persons.delete((Long)p.get("uid"));
    _master.commit();
    assertEquals(2, persons.find().size());
   
    final Integer[] tresult = new Integer[1];
    Thread t = new Thread() {
      @Override
      public void run() {
        VCollection persons = _master.getCollection("persons");
        tresult[0] = persons.find().size();
      }
    };
    t.start();
    t.join();
    assertEquals(Integer.valueOf(2), tresult[0]);
View Full Code Here

   */
  @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());
  }
View Full Code Here

   * 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);
View Full Code Here

      coll.insert(obj);
    }
  }
 
  private void mvccInsert(int offset) {
    VCollection coll = _master.getCollection("persons");
    for (long i = 0; i < DOCUMENTS; ++i) {
      Map<String, Object> obj = _factory.createDocument();
      obj.put("name", String.valueOf(i));
      obj.put("age", i + offset);
      obj.put("uid", 1 + i + offset);
      coll.insert(obj);
    }
  }
View Full Code Here

   */
  @Test
  @BenchmarkOptions(benchmarkRounds = 2, warmupRounds = 1)
  public void mvccInsertDelete() {
    mvccInsert();
    VCollection coll = _master.getCollection("persons");
    for (long i = 0; i < DOCUMENTS; ++i) {
      coll.delete(1 + i);
    }
  }
View Full Code Here

   */
  @Test
  @BenchmarkOptions(benchmarkRounds = 2, warmupRounds = 1)
  public void mvccInsertDeleteInsertQuery() {
    mvccInsertDeleteInsert();
    VCollection coll = _master.getCollection("persons");
    for (Map<String, Object> o : coll.find()) {
      assertTrue(((Long)o.get("age")).longValue() >= DOCUMENTS);
    }
  }
View Full Code Here

   * 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);
View Full Code Here

    assertArrayEquals(new long[] { c1 }, h.getChildren(root));
    assertArrayEquals(new long[] { c2 }, h.getChildren(c1));
    assertArrayEquals(new long[0], h.getChildren(c2));
   
    VBranch master2 = _db.createBranch("master2", c1);
    VCollection persons = master2.getCollection("persons");
    persons.insert(_factory.createDocument("name", "Elvis"));
    long c3 = master2.commit();
   
    h = _db.getHistory();
    assertEquals(c1, h.getParent(c2));
    assertEquals(c1, h.getParent(c3));
View Full Code Here

TOP

Related Classes of de.fhg.igd.mongomvcc.VCollection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.