public void testAddTwice() {
   DummyConfigurationItem item = new DummyConfigurationItem(_applied);
   _config.addConfigurationItem(item);
   _config.addConfigurationItem(item);
   _config.applyConfigurationItems(new MockServer());
   Assert.areEqual(1, item.prepareCount());
   assertListsAreEqual(Arrays.asList(item), _applied);
 }
 private void withCache(final Procedure4<ClientSlotCache> procedure) {
   ClientSlotCache clientSlotCache = null;
   try {
     clientSlotCache =
         (ClientSlotCache) Reflection4.getFieldValue(container(), "_clientSlotCache");
   } catch (ReflectException e) {
     Assert.fail("Can't get field _clientSlotCache on  container. " + e.toString());
   }
   procedure.apply(clientSlotCache);
 }
  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 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));
  }
 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)));
 }
Esempio n. 6
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);
 }
 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);
 }
 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 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);
   }
 }
 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;
   }
 }
Esempio n. 11
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());
  }
Esempio n. 12
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);
 }
Esempio n. 13
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());
    }
  }
  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());
  }
 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());
   }
 }
Esempio n. 18
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);

  }
 public void testDeleteKey() {
   Item keyItem = storedItem(KEY_ID);
   db().delete(keyItem);
   db().commit();
   Holder holder = retrieveOnlyInstance(Holder.class);
   Assert.areEqual(0, holder._map.size());
 }
 private Item storedItem(String id) {
   Query query = newQuery(Item.class);
   query.descend("_id").constrain(id);
   ObjectSet<Item> result = query.execute();
   Assert.isTrue(result.hasNext());
   return result.next();
 }
 void checkHelper(Db4oHashMapHelper helper) {
   ExtObjectContainer con = db();
   if (con.isActive(helper)) {
     Assert.areEqual("hi", helper.i_childList.get(0));
     checkHelper(helper.i_child);
   }
 }
 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);
   }
 }
  public void testVersionIncrease() {

    Item item = (Item) retrieveOnlyInstance(Item.class);
    ObjectInfo objectInfo = db().getObjectInfo(item);
    long version1 = objectInfo.getCommitTimestamp();
    item._name = "modified";
    db().store(item);
    db().commit();
    long version2 = objectInfo.getCommitTimestamp();
    Assert.isGreater(version1, version2);
    db().store(item);
    db().commit();
    objectInfo = db().getObjectInfo(item);
    long version3 = objectInfo.getCommitTimestamp();
    Assert.isGreater(version2, version3);
  }
 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 test() {
   SubClass subClass = retrieveOnlyInstance(SubClass.class);
   db().delete(subClass);
   db().commit();
   ObjectSet objectSet = db().query(Member.class);
   Assert.areEqual(0, objectSet.size());
 }
 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);
   }
 }
Esempio n. 27
0
 public void _test() throws Exception {
   Query query = newQuery();
   query.constrain(new TestEvaluation());
   query.constrain(Item.class);
   query.descend("name").orderDescending();
   ObjectSet set = query.execute();
   Assert.areEqual(3, set.size());
 }
 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]);
   }
 }
Esempio n. 29
0
 @SuppressWarnings("unchecked")
 public void testCircularEvaluation() throws Exception {
   populate();
   CircularEvaluator.D one = new CircularEvaluator.D(null, _a);
   CircularEvaluator.D two = new CircularEvaluator.D(one, _a);
   one._d = two;
   ObjectSet set = executeSODAQuery(_a, new CircularEvaluator(one));
   Assert.areEqual(1, set.size());
 }
 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);
 }