private void checkListSizeAndContents(int expectedSize) throws Exception {
   ArrayList4<Integer> list = retrieveAndAssertNullArrayList4();
   Assert.areEqual(expectedSize, list.size());
   for (int i = 0; i < expectedSize; ++i) {
     Assert.areEqual(new Integer(i), list.get(i));
   }
 }
  public void testTransactionConsistentVersion() throws Exception {

    store(new Item(NEWER));
    db().commit();

    Item newer = itemByName(NEWER);
    Item original = itemByName(ORIGINAL);

    Assert.isGreater(version(original), version(newer));

    newer._name += " modified";
    original._name += " modified";

    store(newer);
    store(original);

    db().commit();

    Assert.areEqual(version(newer), version(original));

    reopen();

    newer = itemByName(newer._name);
    original = itemByName(original._name);

    Assert.areEqual(version(newer), version(original));
  }
 private void checkRemove() throws Exception {
   ArrayList4<Integer> list = retrieveAndAssertNullArrayList4();
   Assert.areEqual(ArrayList4Asserter.CAPACITY - 1, list.size());
   for (int i = 0; i < ArrayList4Asserter.CAPACITY - 1; ++i) {
     Assert.areEqual(new Integer(i + 1), list.get(i));
   }
 }
  /*
   * delete - set - commit delete - commit set
   */
  public void _testDS() {
    ExtObjectContainer oc1 = openNewSession();
    ExtObjectContainer oc2 = openNewSession();
    ExtObjectContainer oc3 = openNewSession();
    try {
      SimpleObject o1 = (SimpleObject) retrieveOnlyInstance(oc1, SimpleObject.class);
      oc1.delete(o1);
      SimpleObject o2 = (SimpleObject) retrieveOnlyInstance(oc2, SimpleObject.class);
      Assert.areEqual("hello", o2.getS());
      o2.setS("o2");
      oc2.store(o2);

      oc1.commit();
      oc2.commit();

      o1 = (SimpleObject) retrieveOnlyInstance(oc1, SimpleObject.class);
      oc1.refresh(o1, Integer.MAX_VALUE);
      Assert.areEqual("o2", o1.getS());

      o2 = (SimpleObject) retrieveOnlyInstance(oc2, SimpleObject.class);
      oc2.refresh(o2, Integer.MAX_VALUE);
      Assert.areEqual("o2", o2.getS());

      SimpleObject o3 = (SimpleObject) retrieveOnlyInstance(oc3, SimpleObject.class);
      oc1.refresh(o1, Integer.MAX_VALUE);
      Assert.areEqual("o2", o3.getS());

    } finally {
      oc1.close();
      oc2.close();
      oc3.close();
    }
  }
  public void testUpdateAndQuery() {

    Item item1 = new Item();
    store(item1);
    Item item2 = new Item();
    store(item2);
    commit();

    long initialCommitTimestamp1 = db().getObjectInfo(item1).getCommitTimestamp();
    long initialCommitTimestamp2 = db().getObjectInfo(item2).getCommitTimestamp();

    Assert.areEqual(initialCommitTimestamp1, initialCommitTimestamp2);

    store(item2);
    commit();

    long secondCommitTimestamp1 = db().getObjectInfo(item1).getCommitTimestamp();
    long secondCommitTimestamp2 = db().getObjectInfo(item2).getCommitTimestamp();

    Assert.areEqual(initialCommitTimestamp1, secondCommitTimestamp1);
    Assert.areNotEqual(initialCommitTimestamp2, secondCommitTimestamp2);

    assertQueryForTimestamp(item1, initialCommitTimestamp1);
    assertQueryForTimestamp(item2, secondCommitTimestamp2);
  }
 public void testAllThere() throws Exception {
   for (int i = 0; i < FOOS.length; i++) {
     Query q = createQuery(FOOS[i]);
     ObjectSet objectSet = q.execute();
     Assert.areEqual(1, objectSet.size());
     FieldIndexItem fii = (FieldIndexItem) objectSet.next();
     Assert.areEqual(FOOS[i], fii.foo);
   }
 }
  public void conc(ExtObjectContainer oc) {
    Query q = oc.query();
    q.constrain(QueryForUnknownFieldTestCase.class);
    q.descend("_name").constrain("name");
    Assert.areEqual(1, q.execute().size());

    q = oc.query();
    q.constrain(QueryForUnknownFieldTestCase.class);
    q.descend("name").constrain("name");
    Assert.areEqual(0, q.execute().size());
  }
 private void tUpdateB(ExtObjectContainer oc) {
   ObjectSet res = query(oc, "b");
   CreateIndexFor ci = (CreateIndexFor) res.next();
   ci.i_name = "j";
   oc.store(ci);
   res = query(oc, "b");
   Assert.areEqual(0, res.size());
   res = query(oc, "j");
   Assert.areEqual(1, res.size());
   ci.i_name = "b";
   oc.store(ci);
   tQueryB(oc);
 }
  public void checkUpdateDifferentObject(ExtObjectContainer oc) throws Exception {

    ObjectSet result = oc.query(SimpleObject.class);
    Assert.areEqual(COUNT, result.size());
    while (result.hasNext()) {
      SimpleObject o = (SimpleObject) result.next();
      int i = o.getI();
      if (i >= COUNT) {
        i -= COUNT;
      }
      Assert.areEqual(testString + i, o.getS());
    }
  }
 public void checkUpdate(ExtObjectContainer oc) {
   Query q = oc.query();
   q.constrain(IndexedByIdentityTestCase.class);
   ObjectSet os = q.execute();
   Assert.areEqual(COUNT, os.size());
   String expected = null;
   while (os.hasNext()) {
     IndexedByIdentityTestCase idi = (IndexedByIdentityTestCase) os.next();
     if (expected == null) {
       expected = idi.atom.name;
       Assert.isTrue(expected.startsWith("updated"));
       Assert.isTrue(expected.length() > "updated".length());
     }
     Assert.areEqual(expected, idi.atom.name);
   }
 }
 void checkHelper(Db4oHashMapHelper helper) {
   ExtObjectContainer con = db();
   if (con.isActive(helper)) {
     Assert.areEqual("hi", helper.i_childList.get(0));
     checkHelper(helper.i_child);
   }
 }
  /*
   * delete - set - commit set - commit delete
   */
  public void testSD() {
    ExtObjectContainer oc1 = openNewSession();
    ExtObjectContainer oc2 = openNewSession();
    ExtObjectContainer oc3 = openNewSession();
    try {
      SimpleObject o1 = (SimpleObject) retrieveOnlyInstance(oc1, SimpleObject.class);
      oc1.delete(o1);
      SimpleObject o2 = (SimpleObject) retrieveOnlyInstance(oc2, SimpleObject.class);
      Assert.areEqual("hello", o2.getS());
      o2.setS("o2");
      oc2.store(o2);

      oc2.commit();
      oc1.commit();

      assertOccurrences(oc1, SimpleObject.class, 0);
      assertOccurrences(oc2, SimpleObject.class, 0);
      assertOccurrences(oc3, SimpleObject.class, 0);

    } finally {
      oc1.close();
      oc2.close();
      oc3.close();
    }
  }
 public void conc(ExtObjectContainer oc) {
   oc.queryByExample((new QueryNonExistantTestCase(true)));
   assertOccurrences(oc, QueryNonExistantTestCase.class, 0);
   Query q = oc.query();
   q.constrain(new QueryNonExistantTestCase(true));
   Assert.areEqual(0, q.execute().size());
 }
 private void assertAreEqual(short expected, short actual) {
   if (expected == Short.MAX_VALUE && db4oHandlerVersion() == 0) {
     // Bug in the oldest format: It treats Short.MAX_VALUE as null.
     expected = 0;
   }
   Assert.areEqual(expected, actual);
 }
 private void assertAreEqual(Object expected, Object actual) {
   if (new Short(Short.MAX_VALUE).equals(expected) && db4oHandlerVersion() == 0) {
     // Bug in the oldest format: It treats Short.MAX_VALUE as null.
     expected = null;
   }
   Assert.areEqual(expected, actual);
 }
 private void tExpectInts(Query q, int[] ints, int zeroSize) {
   ObjectSet res = q.execute();
   Assert.areEqual(ints.length + zeroSize, res.size());
   while (res.hasNext()) {
     CreateIndexFor ci = (CreateIndexFor) res.next();
     for (int i = 0; i < ints.length; i++) {
       if (ints[i] == ci.i_int) {
         ints[i] = 0;
         break;
       }
     }
   }
   for (int i = 0; i < ints.length; i++) {
     Assert.areEqual(0, ints[i]);
   }
 }
 public void concRead(ExtObjectContainer oc) {
   for (int i = 0; i < COUNT; i++) {
     Query q = oc.query();
     q.constrain(Atom.class);
     q.descend("name").constrain("ibi" + i);
     ObjectSet objectSet = q.execute();
     Assert.areEqual(1, objectSet.size());
     Atom child = (Atom) objectSet.next();
     q = oc.query();
     q.constrain(IndexedByIdentityTestCase.class);
     q.descend("atom").constrain(child).identity();
     objectSet = q.execute();
     Assert.areEqual(1, objectSet.size());
     IndexedByIdentityTestCase ibi = (IndexedByIdentityTestCase) objectSet.next();
     Assert.areSame(child, ibi.atom);
   }
 }
 private void assertDescendingRange(int startingValue, TAItem item) {
   TAItem current = item;
   while (current != null) {
     Assert.areEqual(startingValue, current.value());
     current = current.next();
     startingValue--;
   }
 }
 public void checkUpdateSameObject(ExtObjectContainer oc) throws Exception {
   Query query = oc.query();
   query.descend("_s").constrain(testString + COUNT / 2);
   ObjectSet result = query.execute();
   Assert.areEqual(1, result.size());
   SimpleObject o = (SimpleObject) result.next();
   int i = o.getI();
   Assert.isTrue(COUNT <= i && i < COUNT + threadCount());
 }
 public void concUpdateSameObject(ExtObjectContainer oc, int seq) throws Exception {
   Query query = oc.query();
   query.descend("_s").constrain(testString + COUNT / 2);
   ObjectSet result = query.execute();
   Assert.areEqual(1, result.size());
   SimpleObject o = (SimpleObject) result.next();
   o.setI(COUNT + seq);
   oc.store(o);
 }
 private void assertQueryForTimestamp(Item expected, long timestamp) {
   Query query = db().query();
   query.constrain(Item.class);
   query.descend(VirtualField.COMMIT_TIMESTAMP).constrain(timestamp);
   ObjectSet<Object> objectSet = query.execute();
   Assert.areEqual(1, objectSet.size());
   Item actual = (Item) objectSet.next();
   Assert.areSame(expected, actual);
 }
示例#22
0
  private void assertStoredField(
      Class objectClass,
      String fieldName,
      final Object expectedFieldValue,
      Class expectedFieldType,
      boolean hasIndex,
      boolean isArray) {
    StoredClass storedClass = storedClass(objectClass);
    StoredField[] storedFields = storedClass.getStoredFields();
    Assert.areEqual(1, storedFields.length);
    final StoredField storedField = storedFields[0];
    Assert.areEqual(fieldName, storedField.getName());
    StoredField storedFieldByName = storedClass.storedField(fieldName, expectedFieldType);
    Assert.areEqual(storedField, storedFieldByName);

    Object item = retrieveOnlyInstance(objectClass);
    Assert.areEqual(expectedFieldValue, storedField.get(item));
    ReflectClass fieldType = storedField.getStoredType();
    Assert.areEqual(reflector().forClass(expectedFieldType), fieldType);
    Assert.areEqual(isArray, storedField.isArray());

    if (isMultiSession()) {
      return;
    }

    Assert.areEqual(hasIndex, storedField.hasIndex());

    // FIXME: test rename

    if (!hasIndex) {
      Assert.expect(
          RuntimeException.class,
          new CodeBlock() {
            public void run() throws Throwable {
              storedField.traverseValues(
                  new Visitor4() {
                    public void visit(Object obj) {}
                  });
            }
          });
    } else {
      final IntByRef count = new IntByRef();
      storedField.traverseValues(
          new Visitor4() {
            public void visit(Object obj) {
              count.value++;
              Assert.areEqual(expectedFieldValue, obj);
            }
          });
      Assert.areEqual(1, count.value);
    }
  }
 public void concUpdate(ExtObjectContainer oc, int seq) throws Exception {
   Query q = oc.query();
   q.constrain(IndexedByIdentityTestCase.class);
   ObjectSet os = q.execute();
   Assert.areEqual(COUNT, os.size());
   while (os.hasNext()) {
     IndexedByIdentityTestCase idi = (IndexedByIdentityTestCase) os.next();
     idi.atom.name = "updated" + seq;
     oc.store(idi);
     Thread.sleep(100);
   }
 }
 public void concUpdateDifferentObject(ExtObjectContainer oc, int seq) throws Exception {
   Query query = oc.query();
   query
       .descend("_s")
       .constrain(testString + seq)
       .and(query.descend("_i").constrain(new Integer(seq)));
   ObjectSet result = query.execute();
   Assert.areEqual(1, result.size());
   SimpleObject o = (SimpleObject) result.next();
   o.setI(seq + COUNT);
   oc.store(o);
 }
  public void concDelete(ExtObjectContainer oc) throws Exception {
    int size = countOccurences(oc, SimpleObject.class);
    if (size == 0) { // already deleted
      return;
    }
    Assert.areEqual(ELEMENT_COUNT, size);

    ObjectSet os = oc.query(ArrayItem.class);
    if (os.size() == 0) { // already deteled
      return;
    }
    Assert.areEqual(1, os.size());
    ArrayItem item = (ArrayItem) os.next();

    // waits for other threads
    Thread.sleep(500);
    oc.delete(item);

    oc.commit();

    assertOccurrences(oc, SimpleObject.class, 0);
  }
  public void testQueryForVersionNumber() {
    store(new Item(NEWER));
    db().commit();

    Item newer = itemByName(NEWER);

    long version = version(newer);

    Query query = db().query();
    query.descend(VirtualField.COMMIT_TIMESTAMP).constrain(new Long(version)).smaller().not();
    ObjectSet<Item> set = query.execute();
    Assert.areEqual(1, set.size());
    Assert.areSame(newer, set.next());
  }
示例#27
0
  /**
   * This is to ensure that reflector.forObject(GenericArray) returns an instance of
   * GenericArrayClass instead of GenericClass http://tracker.db4o.com/jira/browse/COR-376
   */
  public void testGenericArrayClass() {
    ExtObjectContainer oc = fixture().db();
    initGenericObjects();
    ReflectClass elementType = oc.reflector().forName(PERSON_CLASSNAME);

    Object array = reflector().array().newInstance(elementType, 5);

    ReflectClass arrayClass = oc.reflector().forObject(array);
    Assert.isTrue(arrayClass.isArray());
    Assert.isTrue(arrayClass instanceof GenericArrayClass);

    arrayClass = oc.reflector().forName(array.getClass().getName());
    Assert.isTrue(arrayClass.isArray());
    Assert.isTrue(arrayClass instanceof GenericArrayClass);

    arrayClass = oc.reflector().forClass(array.getClass());
    Assert.isTrue(arrayClass.isArray());
    Assert.isTrue(arrayClass instanceof GenericArrayClass);

    Assert.areEqual(arrayClass.getName(), ReflectPlatform.fullyQualifiedName(array.getClass()));

    Assert.areEqual("(GA) " + elementType.getName(), array.toString());
  }
 private void tDefaultArray(Object[] arr) {
   Assert.areEqual(DEFAULT.length, arr.length);
   String str[] = new String[DEFAULT.length];
   System.arraycopy(DEFAULT, 0, str, 0, DEFAULT.length);
   for (int i = 0; i < arr.length; i++) {
     boolean found = false;
     for (int j = 0; j < str.length; j++) {
       if (arr[i].equals(str[j])) {
         str[j] = null;
         found = true;
       }
     }
     Assert.isTrue(found);
   }
   for (int j = 0; j < str.length; j++) {
     Assert.isNull(str[j]);
   }
 }
  public void test() throws Exception {
    int total = 10;
    ExtObjectContainer[] containers = new ExtObjectContainer[total];
    ExtObjectContainer container = null;
    try {
      for (int i = 0; i < total; i++) {
        containers[i] = openNewSession();
        Assert.areEqual(ELEMENT_COUNT, countOccurences(containers[i], SimpleObject.class));
      }

      for (int i = 0; i < total; i++) {
        deleteAll(containers[i], SimpleObject.class);
      }

      container = openNewSession();

      assertOccurrences(container, SimpleObject.class, ELEMENT_COUNT);
      // ocs[0] deletes all SimpleObject
      containers[0].commit();
      containers[0].close();
      // FIXME: the following assertion fails
      assertOccurrences(container, SimpleObject.class, 0);
      for (int i = 1; i < total; i++) {
        containers[i].close();
      }
      assertOccurrences(container, SimpleObject.class, 0);
    } finally {
      if (container != null) {
        container.close();
      }
      for (int i = 0; i < total; i++) {
        if (containers[i] != null) {
          containers[i].close();
        }
      }
    }
  }
示例#30
0
 private void assertData() {
   Holder holder = (Holder) retrieveOnlyInstance(Holder.class);
   Assert.isNotNull(holder._item);
   Assert.areEqual(NAME, holder._item._name);
 }