001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.db4ounit.common.concurrency;
022:
023: import com.db4o.*;
024: import com.db4o.config.*;
025: import com.db4o.ext.*;
026: import com.db4o.query.*;
027:
028: import db4ounit.*;
029: import db4ounit.extensions.*;
030:
031: public class MultiLevelIndexTestCase extends Db4oClientServerTestCase {
032:
033: public static void main(String[] args) {
034: new MultiLevelIndexTestCase().runConcurrency();
035: }
036:
037: public MultiLevelIndexTestCase _child;
038:
039: public int _i;
040:
041: public int _level;
042:
043: protected void configure(Configuration config) {
044: config.objectClass(this ).objectField("_child").indexed(true);
045: config.objectClass(this ).objectField("_i").indexed(true);
046: }
047:
048: protected void store() {
049: store(3);
050: store(2);
051: store(5);
052: store(1);
053: for (int i = 6; i < 103; i++) {
054: store(i);
055: }
056: }
057:
058: private void store(int val) {
059: MultiLevelIndexTestCase root = new MultiLevelIndexTestCase();
060: root._i = val;
061: root._child = new MultiLevelIndexTestCase();
062: root._child._level = 1;
063: root._child._i = -val;
064: store(root);
065: }
066:
067: public void conc1(ExtObjectContainer oc) {
068: Query q = oc.query();
069: q.constrain(MultiLevelIndexTestCase.class);
070: q.descend("_child").descend("_i").constrain(new Integer(-102));
071: ObjectSet objectSet = q.execute();
072: Assert.areEqual(1, objectSet.size());
073: MultiLevelIndexTestCase mli = (MultiLevelIndexTestCase) objectSet
074: .next();
075: Assert.areEqual(102, mli._i);
076: }
077:
078: public void conc2(ExtObjectContainer oc, int seq) {
079: oc.configure().objectClass(MultiLevelIndexTestCase.class)
080: .cascadeOnUpdate(true);
081: Query q = oc.query();
082: q.constrain(MultiLevelIndexTestCase.class);
083: q.descend("_child").descend("_i").constrain(
084: new Integer(seq - 102));
085: ObjectSet objectSet = q.execute();
086: Assert.areEqual(1, objectSet.size());
087: MultiLevelIndexTestCase mli = (MultiLevelIndexTestCase) objectSet
088: .next();
089: Assert.areEqual(102 - seq, mli._i);
090: mli._child._i = -(seq + 201);
091: oc.set(mli);
092: }
093:
094: public void check2(ExtObjectContainer oc) {
095: Query q = oc.query();
096: q.constrain(MultiLevelIndexTestCase.class);
097: q.descend("_child").descend("_i").constrain(new Integer(-200))
098: .smaller();
099: ObjectSet objectSet = q.execute();
100: Assert.areEqual(threadCount(), objectSet.size());
101: }
102:
103: }
|