--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.tools.ij.mtTestSuite\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.tools.ij;\r
+\r
+import java.util.Vector;\r
+import java.util.Enumeration;\r
+import java.util.Properties;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.lang.Math;\r
+\r
+/**\r
+ */\r
+public class mtTestSuite\r
+{\r
+ private Vector cases;\r
+ private Vector last;\r
+ private Vector init;\r
+ private mtTime time;\r
+ private int numThreads;\r
+ private String rootDir = null;\r
+\r
+\r
+ mtTestSuite(int numThreads, mtTime time, \r
+ Vector initCases, Vector testCases, Vector finalCases)\r
+ {\r
+ this.numThreads = numThreads;\r
+ this.time = time;\r
+ this.cases = testCases;\r
+ this.init = initCases;\r
+ this.last = finalCases;\r
+ }\r
+\r
+ public void init()\r
+ {\r
+ boolean loadInitFailed = loadCases(init);\r
+ boolean loadTestsFailed = loadCases(cases);\r
+ boolean loadLastFailed = loadCases(last);\r
+\r
+ if ((loadInitFailed == true) ||\r
+ (loadTestsFailed == true) ||\r
+ (loadLastFailed == true))\r
+ {\r
+ throw new Error("Initialization Error");\r
+ }\r
+ }\r
+\r
+ /**\r
+ ** @return boolean indicates if there was a problem loading\r
+ ** the file\r
+ */\r
+ private boolean loadCases(Vector cases)\r
+ {\r
+ if (cases == null)\r
+ return false;\r
+\r
+ boolean gotError = false;\r
+ Enumeration e = cases.elements();\r
+ mtTestCase tcase;\r
+ \r
+ while (e.hasMoreElements())\r
+ {\r
+ tcase = (mtTestCase)e.nextElement();\r
+ try\r
+ {\r
+ tcase.initialize(rootDir);\r
+ }\r
+ catch (Throwable t)\r
+ {\r
+ gotError = true;\r
+ }\r
+ }\r
+\r
+ return gotError;\r
+ }\r
+\r
+ public void setRoot(String rootDir)\r
+ {\r
+ this.rootDir = rootDir;\r
+ }\r
+\r
+ public String getRoot()\r
+ {\r
+ return rootDir;\r
+ }\r
+\r
+ public int getNumThreads()\r
+ {\r
+ return numThreads;\r
+ }\r
+\r
+ public Vector getCases()\r
+ {\r
+ return cases;\r
+ }\r
+\r
+ public Vector getInitCases()\r
+ {\r
+ return init;\r
+ }\r
+\r
+ public Vector getFinalCases()\r
+ {\r
+ return last;\r
+ }\r
+\r
+ public mtTime getTime()\r
+ {\r
+ return time;\r
+ }\r
+\r
+ public long getTimeMillis()\r
+ {\r
+ return ((time.hours * 360) +\r
+ (time.minutes * 60) +\r
+ (time.seconds)) * 1000;\r
+ }\r
+\r
+ public String toString()\r
+ {\r
+ String str;\r
+ int len;\r
+ int i;\r
+ \r
+ str = "TEST CASES\nNumber of Threads: "+numThreads;\r
+ str +="\nTime: "+time;\r
+ str +="\nNumber of Initializers: "+init.size()+"\n";\r
+ for (i = 0, len = init.size(); i < len; i++)\r
+ {\r
+ str += init.elementAt(i).toString() + "\n";\r
+ }\r
+\r
+ str +="\nNumber of Cases: "+cases.size()+"\n";\r
+ for (i = 0, len = cases.size(); i < len; i++)\r
+ {\r
+ str += cases.elementAt(i).toString() + "\n";\r
+ }\r
+\r
+ str +="\nNumber of Final Cases: "+last.size()+"\n";\r
+ for (i = 0, len = last.size(); i < len; i++)\r
+ {\r
+ str += last.elementAt(i).toString() + "\n";\r
+ }\r
+\r
+ return str;\r
+ }\r
+\r
+ /*\r
+ ** Grab a test case. Pick one randomly and\r
+ ** try to grab that case. If we get it we are\r
+ ** done. Otherwise, try try again.\r
+ */\r
+ public mtTestCase grabTestCase() \r
+ {\r
+ int numCases = cases.size();\r
+ int caseNum;\r
+ mtTestCase testCase;\r
+\r
+ do\r
+ {\r
+ caseNum = (int)((java.lang.Math.random() * 1311) % numCases);\r
+ testCase = (mtTestCase)cases.elementAt(caseNum);\r
+ }\r
+ while (testCase.grab() == false);\r
+ \r
+ return testCase; \r
+ }\r
+}\r