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();
 }
 private void restoreMembers(Data data) {
   Query q = newQuery(Data.class);
   ObjectSet objectSet = q.execute();
   Data rdata = (Data) objectSet.next();
   data.i_map = rdata.i_map;
   data.i_helper = rdata.i_helper;
 }
 public void test() {
   SubClass subClass = retrieveOnlyInstance(SubClass.class);
   db().delete(subClass);
   db().commit();
   ObjectSet objectSet = db().query(Member.class);
   Assert.areEqual(0, objectSet.size());
 }
Пример #4
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());
 }
Пример #5
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);
   }
 }
Пример #6
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());
 }
 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 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);
 }
 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());
 }
 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;
   }
 }
Пример #11
0
 private boolean expect(ObjectContainer container, String[] names) {
   Collection4 expected = new Collection4(names);
   ObjectSet actual = container.query(CrashData.class);
   while (actual.hasNext()) {
     CrashData current = (CrashData) actual.next();
     if (!expected.remove(current._name)) {
       return false;
     }
   }
   return expected.isEmpty();
 }
Пример #12
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 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);
   }
 }
Пример #14
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);
 }
Пример #15
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);
 }
 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 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());
    }
  }
 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 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());
  }
Пример #20
0
  public void test() {
    final ItemDates item1 = new ItemDates(new Date(0), new Date());
    final ItemDates item2 =
        new ItemDates(new Date(10000), new Date(System.currentTimeMillis() - 10000));

    a().provider().storeNew(item1);
    a().provider().storeNew(item2);
    a().provider().commit();

    replicateAll(a().provider(), b().provider());

    final ObjectSet found = b().provider().getStoredObjects(ItemDates.class);
    Iterator4Assert.sameContent(
        new Object[] {item2, item1}, ReplicationTestPlatform.adapt(found.iterator()));
  }
Пример #21
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);

  }
 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]);
   }
 }
Пример #23
0
 private void populate(ObjectContainer container) {
   for (int i = 0; i < 10; i++) {
     container.store(new Item("delme"));
   }
   CrashData one = new CrashData(null, "one");
   CrashData two = new CrashData(one, "two");
   CrashData three = new CrashData(one, "three");
   container.store(one);
   container.store(two);
   container.store(three);
   container.commit();
   ObjectSet objectSet = container.query(Item.class);
   while (objectSet.hasNext()) {
     container.delete(objectSet.next());
   }
 }
 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 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);
   }
 }
  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);
  }
Пример #27
0
 @SuppressWarnings("unchecked")
 public void testDeepTwoEvaluation() throws Exception {
   populate();
   ObjectSet set = executeSODAQuery(_a, new DeepTwoEvaluator(new DeepTwoEvaluator.C(_a)));
   Assert.areEqual(1, set.size());
 }
Пример #28
0
    /** @sharpen.remove */
    public void test() throws IOException {

      boolean cached = USE_CACHE.value().booleanValue();
      boolean useLogFile = USE_LOGFILE.value().booleanValue();
      boolean writeTrash = WRITE_TRASH.value().booleanValue();

      if (cached && writeTrash) {
        System.err.println(
            "DISABLED CrashSimulatingTestCase: combination of write trash and cache");
        // The cache may touch more bytes than the ones we modified.
        // We should be safe even if we don't get this test to pass.
        return;
      }

      if (useLogFile && writeTrash) {
        System.err.println(
            "DISABLED CrashSimulatingTestCase: combination of write trash and use log file");

        // The log file is not a public API yet anyway.
        // It's only needed for the PointerBasedIdSystem
        // With the new BTreeIdSystem it's not likely to become important
        // so we can safely ignore the failing write trash case.
        return;
      }

      if (Platform4.needsLockFileThread()) {
        System.out.println(
            "CrashSimulatingTestCase is ignored on platforms with lock file thread.");
        return;
      }

      String path = Path4.combine(Path4.getTempPath(), "crashSimulate");
      String fileName = Path4.combine(path, "cs");

      File4.delete(fileName);
      File4.mkdirs(path);

      createFile(baseConfig(useLogFile), fileName);

      CrashSimulatingStorage crashSimulatingStorage =
          new CrashSimulatingStorage(new FileStorage(), fileName);
      Storage storage =
          cached ? (Storage) new CachingStorage(crashSimulatingStorage) : crashSimulatingStorage;

      Configuration recordConfig = baseConfig(useLogFile);
      recordConfig.storage(storage);

      ObjectContainer oc = Db4o.openFile(recordConfig, fileName);

      ObjectSet objectSet = oc.queryByExample(new CrashData(null, "three"));
      oc.delete(objectSet.next());

      oc.store(new CrashData(null, "four"));
      oc.store(new CrashData(null, "five"));
      oc.store(new CrashData(null, "six"));
      oc.store(new CrashData(null, "seven"));
      oc.store(new CrashData(null, "eight"));
      oc.store(new CrashData(null, "nine"));
      oc.store(new CrashData(null, "10"));
      oc.store(new CrashData(null, "11"));
      oc.store(new CrashData(null, "12"));
      oc.store(new CrashData(null, "13"));
      oc.store(new CrashData(null, "14"));

      oc.commit();

      Query q = oc.query();
      q.constrain(CrashData.class);
      objectSet = q.execute();
      while (objectSet.hasNext()) {
        CrashData cData = (CrashData) objectSet.next();
        if (!(cData._name.equals("10") || cData._name.equals("13"))) {
          oc.delete(cData);
        }
      }

      oc.commit();

      oc.close();

      int count = crashSimulatingStorage._batch.writeVersions(fileName, writeTrash);

      checkFiles(useLogFile, fileName, "R", crashSimulatingStorage._batch.numSyncs());
      checkFiles(useLogFile, fileName, "W", count);
      if (VERBOSE) {
        System.out.println("Total versions: " + count);
      }
    }
 private void tQueryB(ExtObjectContainer oc) {
   ObjectSet res = query(oc, "b");
   Assert.areEqual(1, res.size());
   CreateIndexFor ci = (CreateIndexFor) res.next();
   Assert.areEqual("b", ci.i_name);
 }
 private void assertSingleElementQueryResult(Query query, Object element) {
   ObjectSet objectSet = query.execute();
   Assert.areEqual(1, objectSet.size());
   Item item = (Item) objectSet.next();
   Assert.areEqual(element, item.list.get(0));
 }