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.db4ounit.common.persistent.*;
025: import com.db4o.ext.*;
026: import com.db4o.query.*;
027:
028: import db4ounit.*;
029: import db4ounit.extensions.*;
030:
031: public class UpdateObjectTestCase extends Db4oClientServerTestCase {
032:
033: public static void main(String[] args) {
034: new UpdateObjectTestCase().runConcurrency();
035: }
036:
037: private static String testString = "simple test string";
038:
039: private static int COUNT = 100;
040:
041: protected void store() throws Exception {
042: for (int i = 0; i < COUNT; i++) {
043: store(new SimpleObject(testString + i, i));
044: }
045:
046: }
047:
048: public void concUpdateSameObject(ExtObjectContainer oc, int seq)
049: throws Exception {
050: Query query = oc.query();
051: query.descend("_s").constrain(testString + COUNT / 2);
052: ObjectSet result = query.execute();
053: Assert.areEqual(1, result.size());
054: SimpleObject o = (SimpleObject) result.next();
055: o.setI(COUNT + seq);
056: oc.set(o);
057:
058: }
059:
060: public void checkUpdateSameObject(ExtObjectContainer oc)
061: throws Exception {
062: Query query = oc.query();
063: query.descend("_s").constrain(testString + COUNT / 2);
064: ObjectSet result = query.execute();
065: Assert.areEqual(1, result.size());
066: SimpleObject o = (SimpleObject) result.next();
067: int i = o.getI();
068: Assert.isTrue(COUNT <= i && i < COUNT + threadCount());
069:
070: }
071:
072: public void concUpdateDifferentObject(ExtObjectContainer oc, int seq)
073: throws Exception {
074: Query query = oc.query();
075: query.descend("_s").constrain(testString + seq).and(
076: query.descend("_i").constrain(new Integer(seq)));
077: ObjectSet result = query.execute();
078: Assert.areEqual(1, result.size());
079: SimpleObject o = (SimpleObject) result.next();
080: o.setI(seq + COUNT);
081: oc.set(o);
082: }
083:
084: public void checkUpdateDifferentObject(ExtObjectContainer oc)
085: throws Exception {
086:
087: ObjectSet result = oc.query(SimpleObject.class);
088: Assert.areEqual(COUNT, result.size());
089: while (result.hasNext()) {
090: SimpleObject o = (SimpleObject) result.next();
091: int i = o.getI();
092: if (i >= COUNT) {
093: i -= COUNT;
094: }
095: Assert.areEqual(testString + i, o.getS());
096: }
097:
098: }
099:
100: }
|