Ejemplo n.º 1
0
 public void run() {
   Assert.areEqual(_idx, _counter.value);
   _counter.value++;
   if (_fail) {
     Assert.fail();
   }
 }
  public void testBlockSize() {
    Assert.expect(
        IllegalArgumentException.class,
        new CodeBlock() {
          public void run() throws Throwable {
            db().configure().blockSize(-1);
          }
        });

    Assert.expect(
        IllegalArgumentException.class,
        new CodeBlock() {
          public void run() throws Throwable {
            db().configure().blockSize(128);
          }
        });

    Assert.expect(
        GlobalOnlyConfigException.class,
        new CodeBlock() {
          public void run() throws Throwable {
            db().configure().blockSize(12);
          }
        });
  }
  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));
   }
 }
Ejemplo n.º 5
0
 public void testNewInstance() {
   String[][] a23 = newStringMatrix(2, 3);
   Assert.areEqual(2, a23.length);
   for (int i = 0; i < a23.length; ++i) {
     Assert.areEqual(3, a23[i].length);
   }
 }
 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));
   }
 }
Ejemplo n.º 7
0
  /*
   * 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 test() throws Exception {

    store(new Original("original"));

    db().commit();

    Assert.areEqual(1, countOccurences(Original.class));

    // Rename messages are visible at level 1
    // fixture().config().messageLevel(1);

    ObjectClass oc = fixture().config().objectClass(Original.class);

    // allways rename fields first
    oc.objectField("originalName").rename("changedName");
    // we must use ReflectPlatform here as the string must include
    // the assembly name in .net
    oc.rename(CrossPlatformServices.fullyQualifiedName(Changed.class));

    reopen();

    Assert.areEqual(0, countOccurences(Original.class));
    Assert.areEqual(1, countOccurences(Changed.class));

    Changed changed = (Changed) retrieveOnlyInstance(Changed.class);

    Assert.areEqual("original", changed.changedName);
  }
Ejemplo n.º 9
0
 public void testAreEqual() {
   Assert.areEqual(true, true);
   Assert.areEqual(42, 42);
   Assert.areEqual(new Integer(42), new Integer(42));
   Assert.areEqual(null, null);
   expectFailure(
       new CodeBlock() {
         public void run() throws Throwable {
           Assert.areEqual(true, false);
         }
       });
   expectFailure(
       new CodeBlock() {
         public void run() throws Throwable {
           Assert.areEqual(42, 43);
         }
       });
   expectFailure(
       new CodeBlock() {
         public void run() throws Throwable {
           Assert.areEqual(new Object(), new Object());
         }
       });
   expectFailure(
       new CodeBlock() {
         public void run() throws Throwable {
           Assert.areEqual(null, new Object());
         }
       });
 }
  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);
  }
  private void check(
      CollectionHolder holder, CollectionHolder original1, CollectionHolder original2) {
    Assert.isTrue(holder != original1);
    Assert.isTrue(holder != original2);

    if (holder.name().equals("h1")) checkH1(holder);
    else checkH2(holder);
  }
 public void testDeleteValue() {
   Item valueItem = storedItem(VALUE_ID);
   db().delete(valueItem);
   db().commit();
   Holder holder = retrieveOnlyInstance(Holder.class);
   Assert.areEqual(1, holder._map.size());
   Assert.isNull(holder._map.get(storedItem(KEY_ID)));
 }
 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);
 }
 private void assertOrdered(ObjectSet result) {
   Assert.areEqual(IDS.length, result.size());
   int previousId = 0;
   while (result.hasNext()) {
     Data data = (Data) result.next();
     Assert.isTrue(previousId < data._id);
     previousId = data._id;
   }
 }
Ejemplo n.º 15
0
 private void peek(Item original, int depth) {
   Item peeked = (Item) db().peekPersisted(original, depth, true);
   for (int i = 0; i <= depth; i++) {
     Assert.isNotNull(peeked, "Failed to peek at child " + i + " at depth " + depth);
     Assert.isFalse(db().isStored(peeked));
     peeked = peeked.child;
   }
   Assert.isNull(peeked);
 }
Ejemplo n.º 16
0
 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);
   }
 }
Ejemplo n.º 17
0
  public void testIsNDimensional() {
    ReflectClass arrayOfArrayOfString = reflectClass(String[][].class);
    Assert.isTrue(arrayOfArrayOfString.isArray());

    final ReflectClass arrayOfString = reflectClass(String[].class);
    Assert.areSame(arrayOfString, arrayOfArrayOfString.getComponentType());
    Assert.isTrue(arrayReflector().isNDimensional(arrayOfArrayOfString));
    Assert.isFalse(arrayReflector().isNDimensional(arrayOfString));
  }
 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());
 }
Ejemplo n.º 19
0
  // It will fail for C/S because the reference system in the
  // server is not in sync.
  @SuppressWarnings("unchecked")
  public void _testChangingSODA() throws Exception {
    populate();
    _b.a = new A();

    ObjectSet set = executeSODAQuery(_a, new Evaluator(_a));
    Assert.areEqual(0, set.size());

    set = executeSODAQuery(_b.a, new Evaluator(_b.a));
    Assert.areEqual(1, set.size());
  }
 public void testObjectReferenceCount() {
   int objectCount = 10;
   Item[] items = new Item[objectCount];
   for (int i = 0; i < objectCount; i++) {
     Assert.areEqual(referenceCountForDb4oDatabase() + i, objectReferenceCount());
     items[i] = new Item();
     store(items[i]);
   }
   db().purge(items[0]);
   Assert.areEqual(referenceCountForDb4oDatabase() + objectCount - 1, objectReferenceCount());
 }
  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());
  }
Ejemplo n.º 22
0
  public void testGetStoredFields() {
    assertStoredField(Item.class, FIELD_NAME, ITEM_NAME, String.class, true, false);
    assertStoredField(ItemParent.class, "_array", null, String.class, false, true);

    StoredClass itemStoredClass = itemStoredClass();
    StoredField storedField = itemStoredClass.storedField(FIELD_NAME, null);
    StoredField sameStoredField = itemStoredClass.getStoredFields()[0];
    StoredField otherStoredField = storedClass(ItemParent.class).getStoredFields()[0];
    Assert.equalsAndHashcode(storedField, sameStoredField, otherStoredField);

    Assert.isNull(itemStoredClass.storedField("", null));
  }
Ejemplo n.º 23
0
 public void testQuery() {
   ExtObjectContainer oc = fixture().db();
   initGenericObjects();
   ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME);
   Assert.isNotNull(rc);
   // now query to make sure there are none left
   Query q = oc.query();
   q.constrain(rc);
   q.descend("surname").constrain("John");
   ObjectSet results = q.execute();
   Assert.isTrue(results.size() == 1);
 }
Ejemplo n.º 24
0
 public void testUpdate() {
   ExtObjectContainer oc = fixture().db();
   initGenericObjects();
   // Db4oUtil.dump(oc);
   ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME);
   Assert.isNotNull(rc);
   Query q = oc.query();
   q.constrain(rc);
   ObjectSet results = q.execute();
   // Db4oUtil.dumpResults(oc, results);
   Assert.isTrue(results.size() == 1);
 }
 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());
    }
  }
Ejemplo n.º 27
0
 public static void runTestAndExpect(
     final Iterable4 tests, int expFailures, boolean checkException) {
   final TestResult result = new TestResult();
   new TestRunner(tests).run(result);
   if (expFailures != result.failures().size()) {
     Assert.fail(result.failures().toString());
   }
   if (checkException) {
     for (Iterator4 iter = result.failures().iterator(); iter.moveNext(); ) {
       TestFailure failure = (TestFailure) iter.current();
       Assert.areEqual(EXCEPTION, failure.reason());
     }
   }
 }
 public void testPrepareApply() {
   List<DummyConfigurationItem> items =
       Arrays.asList(new DummyConfigurationItem(_applied), new DummyConfigurationItem(_applied));
   for (DummyConfigurationItem item : items) {
     _config.addConfigurationItem(item);
     Assert.areEqual(1, item.prepareCount());
   }
   Assert.areEqual(0, _applied.size());
   _config.applyConfigurationItems(new MockServer());
   assertListsAreEqual(items, _applied);
   for (DummyConfigurationItem item : items) {
     Assert.areEqual(1, item.prepareCount());
   }
 }
Ejemplo n.º 29
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());
  }
Ejemplo n.º 30
0
  public void testCreate() throws Exception {

    initGenericObjects();
    // fixture().reopen();
    ExtObjectContainer oc = fixture().db();
    // now check to see if person was saved
    ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME);
    Assert.isNotNull(rc);
    Query q = oc.query();
    q.constrain(rc);
    ObjectSet results = q.execute();
    Assert.isTrue(results.size() == 1);
    // Db4oUtil.dumpResults(fixture().db(), results);

  }