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 IndexedUpdatesWithNullTestCase extends
032: Db4oClientServerTestCase {
033:
034: public static void main(String[] args) {
035: new IndexedUpdatesWithNullTestCase().runConcurrency();
036: }
037:
038: public String str;
039:
040: public IndexedUpdatesWithNullTestCase() {
041: }
042:
043: public IndexedUpdatesWithNullTestCase(String str) {
044: this .str = str;
045: }
046:
047: protected void configure(Configuration config) {
048: config.objectClass(this ).objectField("str").indexed(true);
049: }
050:
051: protected void store() {
052: store(new IndexedUpdatesWithNullTestCase("one"));
053: store(new IndexedUpdatesWithNullTestCase("two"));
054: store(new IndexedUpdatesWithNullTestCase("three"));
055: store(new IndexedUpdatesWithNullTestCase(null));
056: store(new IndexedUpdatesWithNullTestCase(null));
057: store(new IndexedUpdatesWithNullTestCase(null));
058: store(new IndexedUpdatesWithNullTestCase(null));
059: store(new IndexedUpdatesWithNullTestCase("four"));
060: }
061:
062: public void conc1(ExtObjectContainer oc) {
063: Query q = oc.query();
064: q.constrain(IndexedUpdatesWithNullTestCase.class);
065: q.descend("str").constrain(null);
066: ObjectSet objectSet = q.execute();
067: Assert.areEqual(4, objectSet.size());
068: }
069:
070: public void conc2(ExtObjectContainer oc) throws Exception {
071: Query q = oc.query();
072: q.constrain(IndexedUpdatesWithNullTestCase.class);
073: q.descend("str").constrain(null);
074: ObjectSet objectSet = q.execute();
075: if (objectSet.size() == 0) { // already set by other threads
076: return;
077: }
078: Assert.areEqual(4, objectSet.size());
079: // wait for other threads
080: Thread.sleep(500);
081: while (objectSet.hasNext()) {
082: IndexedUpdatesWithNullTestCase iuwn = (IndexedUpdatesWithNullTestCase) objectSet
083: .next();
084: iuwn.str = "hi";
085: oc.set(iuwn);
086: Thread.sleep(100);
087: }
088: }
089:
090: public void check2(ExtObjectContainer oc) {
091: Query q1 = oc.query();
092: q1.constrain(IndexedUpdatesWithNullTestCase.class);
093: q1.descend("str").constrain(null);
094: ObjectSet objectSet1 = q1.execute();
095: Assert.areEqual(0, objectSet1.size());
096:
097: Query q2 = oc.query();
098: q2.constrain(IndexedUpdatesWithNullTestCase.class);
099: q2.descend("str").constrain("hi");
100: ObjectSet objectSet2 = q2.execute();
101: Assert.areEqual(4, objectSet2.size());
102: }
103:
104: }
|