| 1 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 { 31 32 private static final Object lock = new Object (); 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 [] args) { 45 46 47 begin(); 48 49 time = System.currentTimeMillis(); 50 51 engine = new STDb4o(); 52 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 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 (new SodaTestThreadedRegression(classes)).start(); 77 } 78 79 protected String name(){ 80 return "S.O.D.A. threaded test"; 81 } 82 83 public void run(){ 84 String 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 obj){ 118 Db4o.configure().objectClass(obj.getClass().getName()).cascadeOnDelete(true); 119 } 120 121 } 122 123 | Popular Tags |