001: /*
002:
003: Derby - Class org.apache.derby.impl.tools.ij.mtTester
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.io.IOException;
026: import java.io.FileNotFoundException;
027: import java.io.BufferedInputStream;
028: import java.util.Date;
029:
030: import org.apache.derby.iapi.tools.i18n.LocalizedOutput;
031:
032: /**
033: * mtTester grabs test and runs them forever.
034: * The spawner of tester is responsible for
035: * killing it.
036: */
037: public class mtTester implements Runnable {
038: private mtTestSuite suite;
039: private String name;
040: private LocalizedOutput log;
041: private LocalizedOutput out;
042: private boolean stop = false;
043: private boolean testOK = false;
044:
045: public mtTester(String name, mtTestSuite suite,
046: LocalizedOutput out, LocalizedOutput log) {
047: this .name = name;
048: this .suite = suite;
049: this .log = log;
050: this .out = out;
051: log.println("...initialized " + name + " at " + new Date());
052: }
053:
054: /**
055: ** Run until killed or until there is a problem.
056: ** If we get other than 'connection closed' we'll
057: ** signal that we recieved a fatal error before
058: ** quittiing; otherwise, we are silent.
059: */
060: public void run() {
061: int numIterations = 0;
062:
063: try {
064: mtTestCase testCase;
065: BufferedInputStream in;
066:
067: // loop until we get an error or
068: // are killed.
069: while (!stop) {
070: numIterations++;
071: testCase = suite.grabTestCase();
072: try {
073: in = testCase.initialize(suite.getRoot());
074: } catch (FileNotFoundException e) {
075: System.out.println(e);
076: return;
077: } catch (IOException e) {
078: System.out.println(e);
079: return;
080: }
081:
082: log.println(name + ": " + testCase.getName() + " "
083: + new Date());
084: testCase.runMe(log, out, in);
085: }
086: } catch (ijFatalException e) {
087:
088: /*
089: ** If we got connection closed (XJ010), we'll
090: ** assume that we were deliberately killed
091: ** via a Thread.stop() and it was caught by
092: ** jbms. Otherwise, we'll print out an
093: ** error message.
094: */
095: if (e.getSQLState() == null
096: || !(e.getSQLState().equals("XJ010"))) {
097: log.println(name
098: + ": TERMINATING due to unexpected error:\n"
099: + e);
100: throw new ThreadDeath();
101: }
102: }
103: if (stop) {
104: log.println(name + ": stopping on request after "
105: + numIterations + " iterations");
106: testOK = true;
107: }
108: }
109:
110: public void stop() {
111: stop = true;
112: }
113:
114: public boolean noFailure() {
115: return testOK;
116: }
117: }
|