001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.runtimeinfo
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: package org.apache.derbyTesting.functionTests.tests.derbynet;
022:
023: import java.net.InetAddress;
024: import java.sql.*;
025: import java.util.Vector;
026: import java.util.Properties;
027: import java.io.File;
028: import java.io.FileOutputStream;
029: import java.io.BufferedOutputStream;
030:
031: import org.apache.derbyTesting.functionTests.harness.jvm;
032: import org.apache.derby.drda.NetworkServerControl;
033: import org.apache.derby.tools.ij;
034: import org.apache.derbyTesting.functionTests.util.TestUtil;
035: import org.apache.derbyTesting.functionTests.util.ExecProcUtil;
036: import org.apache.derby.tools.JDBCDisplayUtil;
037:
038: /**
039: This tests the runtimeinfo command
040: */
041:
042: public class runtimeinfo {
043:
044: private static Properties properties = new java.util.Properties();
045: private static jvm jvm;
046: private static Vector vCmd;
047: private static BufferedOutputStream bos;
048: private static String[] RuntimeinfoCmd = new String[] {
049: "org.apache.derby.drda.NetworkServerControl", "runtimeinfo" };
050: private static String[] RuntimeinfoLocaleCmd = new String[] {
051: "-Duser.language=err", "-Duser.country=DE",
052: "org.apache.derby.drda.NetworkServerControl", "runtimeinfo" };
053:
054: public static void main(String args[]) throws Exception {
055: if ((System.getProperty("java.vm.name") != null)
056: && System.getProperty("java.vm.name").equals("J9"))
057: jvm = jvm.getJvm("j9_13");
058: else
059: jvm = jvm.getJvm("currentjvm"); // ensure compatibility
060: vCmd = jvm.getCommandLine();
061: try {
062: ij.getPropertyArg(args);
063: Connection conn1 = ij.startJBMS();
064: bos = new BufferedOutputStream(System.out, 1024);
065:
066: /************************************************************
067: * Test runtimeinfo
068: ************************************************************/
069: System.out.println("Testing Runtimeinfo");
070: ExecProcUtil.execCmdDumpResults(RuntimeinfoCmd, vCmd, bos);
071: System.out.println("End test");
072:
073: // Now get a couple of connections with some prepared statements
074: Connection conn2 = ij.startJBMS();
075: PreparedStatement ps = prepareAndExecuteQuery(conn1,
076: "SELECT count(*) from sys.systables");
077: PreparedStatement ps2 = prepareAndExecuteQuery(conn1,
078: "VALUES(1)");
079:
080: Connection conn3 = ij.startJBMS();
081: PreparedStatement ps3 = prepareAndExecuteQuery(conn2,
082: "SELECT count(*) from sys.systables");
083: PreparedStatement ps4 = prepareAndExecuteQuery(conn2,
084: "VALUES(2)");
085:
086: /************************************************************
087: * Test runtimeinfo w/ foreign (non-English) locale
088: ************************************************************/
089: System.out.println("Testing Runtimeinfo (locale)");
090: ExecProcUtil.execCmdDumpResults(RuntimeinfoLocaleCmd, vCmd,
091: bos);
092: System.out.println("End test (locale)");
093: ps.close();
094: ps2.close();
095: ps3.close();
096: ps4.close();
097: conn1.close();
098: conn2.close();
099: conn3.close();
100: /** once more after closing the connections
101: * - by calling NetworkServerControl.getRuntimeInfo
102: */
103: System.out
104: .println("Testing Runtimeinfo after closing connectiosn");
105: // give the network server a second to clean up (DERBY-1455)
106: Thread.sleep(1000);
107: NetworkServerControl derbyServer = new NetworkServerControl(
108: InetAddress.getByName("localhost"),
109: NetworkServerControl.DEFAULT_PORTNUMBER);
110: System.out.println(derbyServer.getRuntimeInfo());
111: System.out.println("End test");
112:
113: bos.close();
114: } catch (Exception e) {
115: e.printStackTrace();
116: }
117: }
118:
119: public static PreparedStatement prepareAndExecuteQuery(
120: Connection conn, String sql) throws SQLException {
121: PreparedStatement ps = conn.prepareStatement(sql);
122: ResultSet rs = ps.executeQuery();
123: rs.next();
124: return ps;
125: }
126: }
|