1 21 22 package org.apache.derby.impl.tools.ij; 23 24 import java.util.Vector ; 25 import java.util.Enumeration ; 26 import java.util.Properties ; 27 import java.io.FileNotFoundException ; 28 import java.io.IOException ; 29 import java.lang.Math ; 30 31 33 public class mtTestSuite 34 { 35 private Vector cases; 36 private Vector last; 37 private Vector init; 38 private mtTime time; 39 private int numThreads; 40 private String rootDir = null; 41 42 43 mtTestSuite(int numThreads, mtTime time, 44 Vector initCases, Vector testCases, Vector finalCases) 45 { 46 this.numThreads = numThreads; 47 this.time = time; 48 this.cases = testCases; 49 this.init = initCases; 50 this.last = finalCases; 51 } 52 53 public void init() 54 { 55 boolean loadInitFailed = loadCases(init); 56 boolean loadTestsFailed = loadCases(cases); 57 boolean loadLastFailed = loadCases(last); 58 59 if ((loadInitFailed == true) || 60 (loadTestsFailed == true) || 61 (loadLastFailed == true)) 62 { 63 throw new Error ("Initialization Error"); 64 } 65 } 66 67 71 private boolean loadCases(Vector cases) 72 { 73 if (cases == null) 74 return false; 75 76 boolean gotError = false; 77 Enumeration e = cases.elements(); 78 mtTestCase tcase; 79 80 while (e.hasMoreElements()) 81 { 82 tcase = (mtTestCase)e.nextElement(); 83 try 84 { 85 tcase.initialize(rootDir); 86 } 87 catch (Throwable t) 88 { 89 gotError = true; 90 } 91 } 92 93 return gotError; 94 } 95 96 public void setRoot(String rootDir) 97 { 98 this.rootDir = rootDir; 99 } 100 101 public String getRoot() 102 { 103 return rootDir; 104 } 105 106 public int getNumThreads() 107 { 108 return numThreads; 109 } 110 111 public Vector getCases() 112 { 113 return cases; 114 } 115 116 public Vector getInitCases() 117 { 118 return init; 119 } 120 121 public Vector getFinalCases() 122 { 123 return last; 124 } 125 126 public mtTime getTime() 127 { 128 return time; 129 } 130 131 public long getTimeMillis() 132 { 133 return ((time.hours * 360) + 134 (time.minutes * 60) + 135 (time.seconds)) * 1000; 136 } 137 138 public String toString() 139 { 140 String str; 141 int len; 142 int i; 143 144 str = "TEST CASES\nNumber of Threads: "+numThreads; 145 str +="\nTime: "+time; 146 str +="\nNumber of Initializers: "+init.size()+"\n"; 147 for (i = 0, len = init.size(); i < len; i++) 148 { 149 str += init.elementAt(i).toString() + "\n"; 150 } 151 152 str +="\nNumber of Cases: "+cases.size()+"\n"; 153 for (i = 0, len = cases.size(); i < len; i++) 154 { 155 str += cases.elementAt(i).toString() + "\n"; 156 } 157 158 str +="\nNumber of Final Cases: "+last.size()+"\n"; 159 for (i = 0, len = last.size(); i < len; i++) 160 { 161 str += last.elementAt(i).toString() + "\n"; 162 } 163 164 return str; 165 } 166 167 172 public mtTestCase grabTestCase() 173 { 174 int numCases = cases.size(); 175 int caseNum; 176 mtTestCase testCase; 177 178 do 179 { 180 caseNum = (int)((java.lang.Math.random() * 1311) % numCases); 181 testCase = (mtTestCase)cases.elementAt(caseNum); 182 } 183 while (testCase.grab() == false); 184 185 return testCase; 186 } 187 } 188 | Popular Tags |