001: /*
002:
003: Derby - Class org.apache.derby.impl.tools.ij.mtTestSuite
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.tools.ij;
023:
024: import java.util.Vector;
025: import java.util.Enumeration;
026: import java.util.Properties;
027: import java.io.FileNotFoundException;
028: import java.io.IOException;
029: import java.lang.Math;
030:
031: /**
032: */
033: public class mtTestSuite {
034: private Vector cases;
035: private Vector last;
036: private Vector init;
037: private mtTime time;
038: private int numThreads;
039: private String rootDir = null;
040:
041: mtTestSuite(int numThreads, mtTime time, Vector initCases,
042: Vector testCases, Vector finalCases) {
043: this .numThreads = numThreads;
044: this .time = time;
045: this .cases = testCases;
046: this .init = initCases;
047: this .last = finalCases;
048: }
049:
050: public void init() {
051: boolean loadInitFailed = loadCases(init);
052: boolean loadTestsFailed = loadCases(cases);
053: boolean loadLastFailed = loadCases(last);
054:
055: if ((loadInitFailed == true) || (loadTestsFailed == true)
056: || (loadLastFailed == true)) {
057: throw new Error("Initialization Error");
058: }
059: }
060:
061: /**
062: ** @return boolean indicates if there was a problem loading
063: ** the file
064: */
065: private boolean loadCases(Vector cases) {
066: if (cases == null)
067: return false;
068:
069: boolean gotError = false;
070: Enumeration e = cases.elements();
071: mtTestCase tcase;
072:
073: while (e.hasMoreElements()) {
074: tcase = (mtTestCase) e.nextElement();
075: try {
076: tcase.initialize(rootDir);
077: } catch (Throwable t) {
078: gotError = true;
079: }
080: }
081:
082: return gotError;
083: }
084:
085: public void setRoot(String rootDir) {
086: this .rootDir = rootDir;
087: }
088:
089: public String getRoot() {
090: return rootDir;
091: }
092:
093: public int getNumThreads() {
094: return numThreads;
095: }
096:
097: public Vector getCases() {
098: return cases;
099: }
100:
101: public Vector getInitCases() {
102: return init;
103: }
104:
105: public Vector getFinalCases() {
106: return last;
107: }
108:
109: public mtTime getTime() {
110: return time;
111: }
112:
113: public long getTimeMillis() {
114: return ((time.hours * 360) + (time.minutes * 60) + (time.seconds)) * 1000;
115: }
116:
117: public String toString() {
118: String str;
119: int len;
120: int i;
121:
122: str = "TEST CASES\nNumber of Threads: " + numThreads;
123: str += "\nTime: " + time;
124: str += "\nNumber of Initializers: " + init.size() + "\n";
125: for (i = 0, len = init.size(); i < len; i++) {
126: str += init.elementAt(i).toString() + "\n";
127: }
128:
129: str += "\nNumber of Cases: " + cases.size() + "\n";
130: for (i = 0, len = cases.size(); i < len; i++) {
131: str += cases.elementAt(i).toString() + "\n";
132: }
133:
134: str += "\nNumber of Final Cases: " + last.size() + "\n";
135: for (i = 0, len = last.size(); i < len; i++) {
136: str += last.elementAt(i).toString() + "\n";
137: }
138:
139: return str;
140: }
141:
142: /*
143: ** Grab a test case. Pick one randomly and
144: ** try to grab that case. If we get it we are
145: ** done. Otherwise, try try again.
146: */
147: public mtTestCase grabTestCase() {
148: int numCases = cases.size();
149: int caseNum;
150: mtTestCase testCase;
151:
152: do {
153: caseNum = (int) ((java.lang.Math.random() * 1311) % numCases);
154: testCase = (mtTestCase) cases.elementAt(caseNum);
155: } while (testCase.grab() == false);
156:
157: return testCase;
158: }
159: }
|