示例#1
0
 /** Test the set method sets the correct values. */
 @Test
 public void testSet() {
   _dbVector.set(0, ELEMENT2);
   _dbVector.set(1, ELEMENT1);
   assertTrue("Check the number of values", _dbVector.size() == 3);
   assertEquals("Check element 1", ELEMENT1, _dbVector.get(1));
   assertEquals("Check element 2", ELEMENT2, _dbVector.get(0));
   assertEquals("Check element 3", ELEMENT3, _dbVector.get(2));
 }
示例#2
0
  /** Test the addAll methods add the correct values. */
  @Test
  public void testAddAll() {
    LinkedList<String> l = new LinkedList<String>();
    l.add(ELEMENT3);
    l.add(ELEMENT2);
    l.add(ELEMENT1);

    _dbVector.addAll(l);
    assertTrue("Check the number of values", _dbVector.size() == 6);
    assertEquals("Check element 1", ELEMENT1, _dbVector.get(0));
    assertEquals("Check element 2", ELEMENT2, _dbVector.get(1));
    assertEquals("Check element 3", ELEMENT3, _dbVector.get(2));
    assertEquals("Check element 3", ELEMENT3, _dbVector.get(3));
    assertEquals("Check element 2", ELEMENT2, _dbVector.get(4));
    assertEquals("Check element 1", ELEMENT1, _dbVector.get(5));

    _dbVector.addAll(1, l);
    assertTrue("Check the number of values", _dbVector.size() == 9);
    assertEquals("Check element 1", ELEMENT1, _dbVector.get(0));
    assertEquals("Check element 3", ELEMENT3, _dbVector.get(1));
    assertEquals("Check element 2", ELEMENT2, _dbVector.get(2));
    assertEquals("Check element 1", ELEMENT1, _dbVector.get(3));
    assertEquals("Check element 2", ELEMENT2, _dbVector.get(4));
    assertEquals("Check element 3", ELEMENT3, _dbVector.get(5));
    assertEquals("Check element 3", ELEMENT3, _dbVector.get(6));
    assertEquals("Check element 2", ELEMENT2, _dbVector.get(7));
    assertEquals("Check element 1", ELEMENT1, _dbVector.get(8));
  }
示例#3
0
 /** Test the remove method removes the correct values. */
 @Test
 public void testRemove2() {
   _dbVector.remove(ELEMENT2);
   assertEquals("Check element 1", ELEMENT1, _dbVector.get(0));
   assertEquals("Check element 3", ELEMENT3, _dbVector.get(1));
   assertTrue("Check the number of values", _dbVector.size() == 2);
 }
  /** This used to fail because deserialized DbCollection were marked dirty. */
  @SuppressWarnings("unchecked")
  @Test
  public void testSerialization() {
    PersistenceManager pm = TestTools.openPM();
    pm.currentTransaction().begin();
    DBHashMap<TestClass, TestClass> h1 = new DBHashMap<TestClass, TestClass>();
    DBHashMap<TestClass, TestClass> h2 = new DBHashMap<TestClass, TestClass>();
    TestClass k = new TestClass();
    h2.put(k, new TestClass());
    DBArrayList<TestClass> l1 = new DBArrayList<TestClass>();
    DBArrayList<TestClass> l2 = new DBArrayList<TestClass>();
    l2.add(new TestClass());
    pm.makePersistent(h1);
    pm.makePersistent(h2);
    pm.makePersistent(k);
    pm.makePersistent(l1);
    pm.makePersistent(l2);
    Object oid1 = pm.getObjectId(h1);
    Object oid2 = pm.getObjectId(h2);
    Object oidk = pm.getObjectId(k);
    Object oid3 = pm.getObjectId(l1);
    Object oid4 = pm.getObjectId(l2);
    pm.currentTransaction().commit();
    TestTools.closePM();

    pm = TestTools.openPM();
    pm.currentTransaction().begin();
    h1 = (DBHashMap<TestClass, TestClass>) pm.getObjectById(oid1);
    assertEquals(false, JDOHelper.isDirty(h1));
    h2 = (DBHashMap<TestClass, TestClass>) pm.getObjectById(oid2);
    assertEquals(false, JDOHelper.isDirty(h2));
    k = (TestClass) pm.getObjectById(oidk);
    assertEquals(false, JDOHelper.isDirty(k));
    assertEquals(false, JDOHelper.isDirty(h2.get(k)));

    l1 = (DBArrayList<TestClass>) pm.getObjectById(oid3);
    assertEquals(false, JDOHelper.isDirty(l1));
    l2 = (DBArrayList<TestClass>) pm.getObjectById(oid4);
    assertEquals(false, JDOHelper.isDirty(l2));
    assertEquals(false, JDOHelper.isDirty(l2.get(0)));

    pm.currentTransaction().commit();
    pm.close();
  }
示例#5
0
  /** test batch loading. */
  @SuppressWarnings("unchecked")
  @Test
  public void testBatchLoading() {
    System.out.println("Batch-test");
    PersistenceManager pm = null;
    Object oid = null;

    pm = TestTools.openPM();
    pm.currentTransaction().begin();
    DBArrayList<Object> dbv = new DBArrayList<Object>();
    dbv.add("TestString");
    for (int i = 0; i < 100; i++) {
      dbv.add(new PersistentDummyImpl());
    }
    dbv.add("TestString2");
    pm.makePersistent(dbv);
    oid = pm.getObjectId(dbv);
    pm.currentTransaction().commit();
    pm.close();
    pm = null;

    pm = TestTools.openPM();
    pm.currentTransaction().begin();
    dbv = (DBArrayList<Object>) pm.getObjectById(oid);
    long t1 = System.currentTimeMillis();
    for (Object o : dbv) {
      o.hashCode();
    }
    long t2 = System.currentTimeMillis();
    System.out.println("NORMAL: " + (t2 - t1));
    pm.currentTransaction().commit();
    pm.close();
    pm = null;

    pm = TestTools.openPM();
    pm.currentTransaction().begin();
    dbv = (DBArrayList<Object>) pm.getObjectById(oid);
    t1 = System.currentTimeMillis();
    dbv.setBatchSize(1000);
    for (Object o : dbv) {
      o.hashCode();
    }
    t2 = System.currentTimeMillis();
    System.out.println("BATCHED: " + (t2 - t1));
    pm.currentTransaction().commit();
    pm.close();
    pm = null;

    // Close the store and load the stuff
    pm = TestTools.openPM();
    pm.currentTransaction().begin();
    dbv = (DBArrayList<Object>) pm.getObjectById(oid);
    t1 = System.currentTimeMillis();
    dbv.setBatchSize(1);
    for (Object o : dbv) {
      o.hashCode();
    }
    t2 = System.currentTimeMillis();
    System.out.println("NORMAL: " + (t2 - t1));
    pm.currentTransaction().commit();
    pm.close();
    pm = null;

    // Close the store and load the stuff
    pm = TestTools.openPM();
    pm.currentTransaction().begin();
    dbv = (DBArrayList<Object>) pm.getObjectById(oid);
    t1 = System.currentTimeMillis();
    dbv.setBatchSize(0);
    for (Object o : dbv) {
      o.hashCode();
    }
    t2 = System.currentTimeMillis();
    System.out.println("BATCHED: " + (t2 - t1));
    pm.currentTransaction().commit();
    pm.close();
    pm = null;

    // Close the store, load the stuff and test with transient object
    pm = TestTools.openPM();
    pm.currentTransaction().begin();
    dbv = (DBArrayList<Object>) pm.getObjectById(oid);
    PersistentDummyImpl dummyTrans = new PersistentDummyImpl();
    dbv.add(13, dummyTrans);
    t1 = System.currentTimeMillis();
    dbv.setBatchSize(0);
    for (Object o : dbv) {
      o.hashCode();
    }
    t2 = System.currentTimeMillis();
    assertEquals(dummyTrans, dbv.get(13));
    System.out.println("BATCHED: " + (t2 - t1));
    pm.currentTransaction().commit();
    pm.close();
    pm = null;

    // Close the store, load the stuff and test with modified object
    pm = TestTools.openPM();
    pm.currentTransaction().begin();
    dbv = (DBArrayList<Object>) pm.getObjectById(oid);
    ((PersistentDummyImpl) dbv.get(18)).setData(new byte[] {15});
    t1 = System.currentTimeMillis();
    dbv.setBatchSize(0);
    for (Object o : dbv) {
      o.hashCode();
    }
    t2 = System.currentTimeMillis();
    assertEquals(15, ((PersistentDummyImpl) dbv.get(18)).getData()[0]);
    System.out.println("BATCHED but dirty: " + (t2 - t1));
    pm.currentTransaction().rollback();
    TestTools.closePM();

    // TODO use setBatch() also for all other tests to verify batch loading!
    // Or call these tests here again, outside the store.!
  }
示例#6
0
 /** Test the get method returns the correct values. */
 @Test
 public void testGet() {
   assertEquals("Check element 1", ELEMENT1, _dbVector.get(0));
   assertEquals("Check element 2", ELEMENT2, _dbVector.get(1));
   assertEquals("Check element 3", ELEMENT3, _dbVector.get(2));
 }