01: /*
02:
03: Derby - Class org.apache.derbyTesting.functionTests.harness.shutdown
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to You under the Apache License, Version 2.0
09: (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.derbyTesting.functionTests.harness;
23:
24: import java.sql.Connection;
25: import java.sql.DriverManager;
26: import java.sql.SQLException;
27: import java.sql.SQLWarning;
28: import java.util.*;
29: import java.io.*;
30:
31: import org.apache.derby.tools.JDBCDisplayUtil;
32:
33: /*
34: **
35: ** shutdown
36: **
37: ** force a shutdown after a test complete to guarantee shutdown
38: ** which doesn't always seem to happen with useprocess=false
39: **
40: */
41: public class shutdown {
42:
43: static String shutdownurl;
44: static String driver = "org.apache.derby.jdbc.EmbeddedDriver";
45: static String systemHome;
46:
47: public static void main(String[] args) throws SQLException,
48: InterruptedException, Exception {
49: systemHome = args[0];
50: shutdownurl = args[1];
51: try {
52: doit();
53: } catch (Exception e) {
54: System.out.println("Exception in shutdown: " + e);
55: }
56: }
57:
58: public static void doit() throws SQLException,
59: InterruptedException, Exception {
60: Connection conn = null;
61: boolean finished = false;
62: Date d = new Date();
63:
64: Properties sp = System.getProperties();
65: if (systemHome == null) {
66: systemHome = sp.getProperty("user.dir")
67: + File.separatorChar + "testCSHome";
68: sp.put("derby.system.home", systemHome);
69: System.setProperties(sp);
70: }
71: boolean useprocess = true;
72: String up = sp.getProperty("useprocess");
73: if (up != null && up.equals("false"))
74: useprocess = false;
75:
76: PrintStream stdout = System.out;
77: PrintStream stderr = System.err;
78:
79: Class.forName(driver).newInstance();
80:
81: try {
82: conn = DriverManager.getConnection(shutdownurl);
83: } catch (SQLException se) {
84: if (se.getSQLState().equals("08006")) {
85: // It was already shutdown
86: //System.out.println("Shutdown with: " + shutdownurl);
87: } else {
88: System.out
89: .println("shutdown failed for " + shutdownurl);
90: JDBCDisplayUtil.ShowException(System.out, se);
91: System.exit(1);
92: }
93: }
94: }
95: }
|