KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > legacy > soda > SodaTestThreadedRegression


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.test.legacy.soda;
22
23 import com.db4o.*;
24 import com.db4o.foundation.*;
25 import com.db4o.query.*;
26 import com.db4o.test.legacy.soda.classes.simple.*;
27 import com.db4o.test.legacy.soda.engines.db4o.*;
28 import com.db4o.test.legacy.soda.wrapper.untyped.*;
29
30 public class SodaTestThreadedRegression extends SodaTest implements Runnable JavaDoc{
31     
32     private static final Object JavaDoc lock = new Object JavaDoc();
33     private static int RUNS = 300;
34     
35     private final STClass[] classes;
36     private static volatile int runningThreads;
37     
38     
39     public SodaTestThreadedRegression(STClass[] classes){
40         this.classes = classes;
41         setSodaTestOn(classes);
42     }
43     
44     public static void main(String JavaDoc[] args) {
45         
46         
47         begin();
48         
49         time = System.currentTimeMillis();
50         
51         engine = new STDb4o();
52         // engine = new STDb4oClientServer();
53

54         engine.reset();
55         engine.open();
56         
57         startThread(new STClass[] {new STInteger()});
58         startThread(new STClass[] {new STByte()});
59         startThread(new STClass[] {new STShort()});
60         startThread(new STClass[] {new STBooleanWU()});
61         
62         // We don't want to run out of main to allow sequential
63
// execution of Ant tasks.
64
do{
65             Cool.sleepIgnoringInterruption(300);
66         }while(runningThreads > 0);
67     }
68     
69     private static void startThread(STClass[] classes){
70         for (int i = 0; i < classes.length; i++) {
71             if(! jdkOK(classes[i])){
72                 System.out.println("Test case can't run on this JDK: " + classes[i].getClass().getName());
73                 return;
74             }
75         }
76         new Thread JavaDoc(new SodaTestThreadedRegression(classes)).start();
77     }
78     
79     protected String JavaDoc name(){
80         return "S.O.D.A. threaded test";
81     }
82     
83     public void run(){
84         String JavaDoc name;
85         synchronized(lock){
86             runningThreads ++;
87             name = "R " + runningThreads + " ";
88         }
89         Thread.currentThread().setName(name);
90         
91         for (int i = 0; i < RUNS; i++) {
92             if(! quiet){
93                 System.out.println(name + i);
94             }
95             store(classes);
96             engine.commit();
97             test(classes);
98             for (int j = 0; j < classes.length; j++) {
99                 Query q = engine.query();
100                 q.constrain(classes[j].getClass());
101                 ObjectSet os = q.execute();
102                 while(os.hasNext()){
103                     engine.delete(os.next());
104                 }
105             }
106         }
107         
108         synchronized(lock){
109             runningThreads --;
110             if(runningThreads < 1){
111                 engine.close();
112                 completed();
113             }
114         }
115     }
116     
117     public static void cascadeOnDelete(Object JavaDoc obj){
118         Db4o.configure().objectClass(obj.getClass().getName()).cascadeOnDelete(true);
119     }
120     
121 }
122
123
Popular Tags