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.test.legacy.soda;
022:
023: import com.db4o.*;
024: import com.db4o.foundation.*;
025: import com.db4o.query.*;
026: import com.db4o.test.legacy.soda.*;
027: import com.db4o.test.legacy.soda.classes.simple.*;
028: import com.db4o.test.legacy.soda.collections.*;
029: import com.db4o.test.legacy.soda.engines.db4o.*;
030: import com.db4o.test.legacy.soda.wrapper.untyped.*;
031:
032: public class SodaTestThreadedRegression extends SodaTest implements
033: Runnable {
034:
035: private static final Object lock = new Object();
036: private static int RUNS = 300;
037:
038: private final STClass[] classes;
039: private static volatile int runningThreads;
040:
041: public SodaTestThreadedRegression(STClass[] classes) {
042: this .classes = classes;
043: setSodaTestOn(classes);
044: }
045:
046: public static void main(String[] args) {
047:
048: cascadeOnDelete(new STArrayListT());
049: cascadeOnDelete(new STOwnCollectionW());
050:
051: begin();
052:
053: time = System.currentTimeMillis();
054:
055: engine = new STDb4o();
056: // engine = new STDb4oClientServer();
057:
058: engine.reset();
059: engine.open();
060:
061: startThread(new STClass[] { new STString() });
062: startThread(new STClass[] { new STInteger() });
063: startThread(new STClass[] { new STByte() });
064: startThread(new STClass[] { new STShort() });
065: startThread(new STClass[] { new STBooleanWU() });
066: startThread(new STClass[] { new STOwnCollectionW() });
067: startThread(new STClass[] { new STArrayListT() });
068:
069: // We don't want to run out of main to allow sequential
070: // execution of Ant tasks.
071: do {
072: Cool.sleepIgnoringInterruption(300);
073: } while (runningThreads > 0);
074: }
075:
076: private static void startThread(STClass[] classes) {
077: for (int i = 0; i < classes.length; i++) {
078: if (!jdkOK(classes[i])) {
079: System.out.println("Test case can't run on this JDK: "
080: + classes[i].getClass().getName());
081: return;
082: }
083: }
084: new Thread(new SodaTestThreadedRegression(classes)).start();
085: }
086:
087: protected String name() {
088: return "S.O.D.A. threaded test";
089: }
090:
091: public void run() {
092: String name;
093: synchronized (lock) {
094: runningThreads++;
095: name = "R " + runningThreads + " ";
096: }
097: Thread.currentThread().setName(name);
098:
099: for (int i = 0; i < RUNS; i++) {
100: if (!quiet) {
101: System.out.println(name + i);
102: }
103: store(classes);
104: engine.commit();
105: test(classes);
106: for (int j = 0; j < classes.length; j++) {
107: Query q = engine.query();
108: q.constrain(classes[j].getClass());
109: ObjectSet os = q.execute();
110: while (os.hasNext()) {
111: engine.delete(os.next());
112: }
113: }
114: }
115:
116: synchronized (lock) {
117: runningThreads--;
118: if (runningThreads < 1) {
119: engine.close();
120: completed();
121: }
122: }
123: }
124:
125: public static void cascadeOnDelete(Object obj) {
126: Db4o.configure().objectClass(obj.getClass().getName())
127: .cascadeOnDelete(true);
128: }
129:
130: }
|