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 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; } }
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(); }
public void testQuery() { Query q = Test.query(); ObjectSet objectSet = q.execute(); Test.ensure(objectSet.size() >= 2); int i = 0; while (objectSet.hasNext()) { Object obj = objectSet.next(); Test.ensure(obj != null); i++; } Test.ensure(i >= 2); }
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 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 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]); } }
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); } }
private void expect(Query query, Object[] results, boolean ordered) { testCases++; ObjectSet set = query.execute(); if (results == null || results.length == 0) { if (set.size() > 0) { error("No content expected."); } return; } int j = 0; if (set.size() == results.length) { while (set.hasNext()) { Object obj = set.next(); boolean found = false; if (ordered) { if (comparer.isEqual(results[j], obj)) { results[j] = null; found = true; } j++; } else { for (int i = 0; i < results.length; i++) { if (results[i] != null) { if (comparer.isEqual(results[i], obj)) { results[i] = null; found = true; break; } } } } if (!found) { error("Object not expected: " + obj); } } for (int i = 0; i < results.length; i++) { if (results[i] != null) { error("Expected object not returned: " + results[i]); } } } else { error("Unexpected size returned.\nExpected: " + results.length + " Returned: " + set.size()); } }
public void testDelete() { ExtObjectContainer oc = fixture().db(); initGenericObjects(); ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME); Assert.isNotNull(rc); Query q = oc.query(); q.constrain(rc); ObjectSet results = q.execute(); while (results.hasNext()) { Object o = results.next(); oc.delete(o); } oc.commit(); // now query to make sure there are none left q = oc.query(); q.constrain(rc); q.descend("surname").constrain("John"); results = q.execute(); Assert.isTrue(results.size() == 0); }
public void log(Query query) { ObjectSet set = query.execute(); while (set.hasNext()) { TLogger.log(set.next()); } }
/** @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); } }