KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > tools > ij > mtTestSuite


1 /*
2
3    Derby - Class org.apache.derby.impl.tools.ij.mtTestSuite
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.tools.ij;
23
24 import java.util.Vector JavaDoc;
25 import java.util.Enumeration JavaDoc;
26 import java.util.Properties JavaDoc;
27 import java.io.FileNotFoundException JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.lang.Math JavaDoc;
30
31 /**
32  */

33 public class mtTestSuite
34 {
35     private Vector JavaDoc cases;
36     private Vector JavaDoc last;
37     private Vector JavaDoc init;
38     private mtTime time;
39     private int numThreads;
40     private String JavaDoc rootDir = null;
41
42
43     mtTestSuite(int numThreads, mtTime time,
44             Vector JavaDoc initCases, Vector JavaDoc testCases, Vector JavaDoc 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 JavaDoc("Initialization Error");
64         }
65     }
66
67     /**
68     ** @return boolean indicates if there was a problem loading
69     ** the file
70     */

71     private boolean loadCases(Vector JavaDoc cases)
72     {
73         if (cases == null)
74             return false;
75
76         boolean gotError = false;
77         Enumeration JavaDoc 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 JavaDoc t)
88             {
89                 gotError = true;
90             }
91         }
92
93         return gotError;
94     }
95
96     public void setRoot(String JavaDoc rootDir)
97     {
98         this.rootDir = rootDir;
99     }
100
101     public String JavaDoc getRoot()
102     {
103         return rootDir;
104     }
105
106     public int getNumThreads()
107     {
108         return numThreads;
109     }
110
111     public Vector JavaDoc getCases()
112     {
113         return cases;
114     }
115
116     public Vector JavaDoc getInitCases()
117     {
118         return init;
119     }
120
121     public Vector JavaDoc 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 JavaDoc toString()
139     {
140         String JavaDoc 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     /*
168     ** Grab a test case. Pick one randomly and
169     ** try to grab that case. If we get it we are
170     ** done. Otherwise, try try again.
171     */

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