KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.tools.ij.mtTester
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.io.IOException JavaDoc;
26 import java.io.FileNotFoundException JavaDoc;
27 import java.io.BufferedInputStream JavaDoc;
28 import java.util.Date JavaDoc;
29
30 import org.apache.derby.iapi.tools.i18n.LocalizedOutput;
31
32 /**
33  * mtTester grabs test and runs them forever.
34  * The spawner of tester is responsible for
35  * killing it.
36  */

37 public class mtTester implements Runnable JavaDoc
38 {
39     private mtTestSuite suite;
40     private String JavaDoc name;
41     private LocalizedOutput log;
42     private LocalizedOutput out;
43     private boolean stop = false;
44     private boolean testOK = false;
45                             
46     public mtTester(String JavaDoc name, mtTestSuite suite, LocalizedOutput out, LocalizedOutput log)
47     {
48         this.name = name;
49         this.suite = suite;
50         this.log = log;
51         this.out = out;
52         log.println("...initialized "+ name + " at " + new Date JavaDoc());
53     }
54
55     /**
56     ** Run until killed or until there is a problem.
57     ** If we get other than 'connection closed' we'll
58     ** signal that we recieved a fatal error before
59     ** quittiing; otherwise, we are silent.
60     */

61     public void run()
62     {
63         int numIterations = 0;
64
65         try
66         {
67             mtTestCase testCase;
68             BufferedInputStream JavaDoc in;
69
70             // loop until we get an error or
71
// are killed.
72
while (!stop)
73             {
74                 numIterations++;
75                 testCase = suite.grabTestCase();
76                 try
77                 {
78                     in = testCase.initialize(suite.getRoot());
79                 } catch (FileNotFoundException JavaDoc e)
80                 {
81                     System.out.println(e);
82                     return;
83                 }
84                 catch (IOException JavaDoc e)
85                 {
86                     System.out.println(e);
87                     return;
88                 }
89     
90                 log.println(name + ": "+ testCase.getName() + " " + new Date JavaDoc());
91                 testCase.runMe(log, out, in);
92             }
93         }
94         catch (ijFatalException e)
95         {
96
97             /*
98             ** If we got connection closed (XJ010), we'll
99             ** assume that we were deliberately killed
100             ** via a Thread.stop() and it was caught by
101             ** jbms. Otherwise, we'll print out an
102             ** error message.
103             */

104             if (e.getSQLState() == null || !(e.getSQLState().equals("XJ010")))
105             {
106                 log.println(name + ": TERMINATING due to unexpected error:\n"+e);
107                 throw new ThreadDeath JavaDoc();
108             }
109         }
110         if (stop)
111         {
112             log.println(name + ": stopping on request after " + numIterations +
113                         " iterations");
114             testOK = true;
115         }
116     }
117
118     public void stop()
119     {
120         stop = true;
121     }
122     public boolean noFailure()
123     {
124         return testOK;
125     }
126 }
127
Popular Tags