--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.tools.ij.mtTester\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.io.IOException;\r
+import java.io.FileNotFoundException;\r
+import java.io.BufferedInputStream;\r
+import java.util.Date;\r
+\r
+import org.apache.derby.iapi.tools.i18n.LocalizedOutput;\r
+\r
+/**\r
+ * mtTester grabs test and runs them forever.\r
+ * The spawner of tester is responsible for \r
+ * killing it.\r
+ */\r
+public class mtTester implements Runnable\r
+{\r
+ private mtTestSuite suite;\r
+ private String name;\r
+ private LocalizedOutput log;\r
+ private LocalizedOutput out;\r
+ private boolean stop = false;\r
+ private boolean testOK = false;\r
+ \r
+ public mtTester(String name, mtTestSuite suite, LocalizedOutput out, LocalizedOutput log)\r
+ { \r
+ this.name = name;\r
+ this.suite = suite;\r
+ this.log = log;\r
+ this.out = out;\r
+ log.println("...initialized "+ name + " at " + new Date());\r
+ }\r
+\r
+ /**\r
+ ** Run until killed or until there is a problem.\r
+ ** If we get other than 'connection closed' we'll\r
+ ** signal that we recieved a fatal error before\r
+ ** quittiing; otherwise, we are silent.\r
+ */\r
+ public void run()\r
+ {\r
+ int numIterations = 0;\r
+\r
+ try \r
+ {\r
+ mtTestCase testCase;\r
+ BufferedInputStream in;\r
+\r
+ // loop until we get an error or\r
+ // are killed. \r
+ while (!stop)\r
+ {\r
+ numIterations++;\r
+ testCase = suite.grabTestCase();\r
+ try \r
+ {\r
+ in = testCase.initialize(suite.getRoot());\r
+ } catch (FileNotFoundException e) \r
+ {\r
+ System.out.println(e);\r
+ return;\r
+ }\r
+ catch (IOException e)\r
+ {\r
+ System.out.println(e);\r
+ return;\r
+ }\r
+ \r
+ log.println(name + ": "+ testCase.getName() + " " + new Date());\r
+ testCase.runMe(log, out, in);\r
+ }\r
+ } \r
+ catch (ijFatalException e)\r
+ {\r
+\r
+ /*\r
+ ** If we got connection closed (XJ010), we'll\r
+ ** assume that we were deliberately killed\r
+ ** via a Thread.stop() and it was caught by\r
+ ** jbms. Otherwise, we'll print out an\r
+ ** error message.\r
+ */\r
+ if (e.getSQLState() == null || !(e.getSQLState().equals("XJ010")))\r
+ {\r
+ log.println(name + ": TERMINATING due to unexpected error:\n"+e);\r
+ throw new ThreadDeath();\r
+ }\r
+ }\r
+ if (stop)\r
+ {\r
+ log.println(name + ": stopping on request after " + numIterations +\r
+ " iterations");\r
+ testOK = true;\r
+ }\r
+ }\r
+\r
+ public void stop()\r
+ {\r
+ stop = true;\r
+ }\r
+ public boolean noFailure()\r
+ {\r
+ return testOK;\r
+ }\r
+}\r