KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > derbynet > runtimeinfo


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.runtimeinfo
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 package org.apache.derbyTesting.functionTests.tests.derbynet;
22
23 import java.net.InetAddress JavaDoc;
24 import java.sql.*;
25 import java.util.Vector JavaDoc;
26 import java.util.Properties JavaDoc;
27 import java.io.File JavaDoc;
28 import java.io.FileOutputStream JavaDoc;
29 import java.io.BufferedOutputStream JavaDoc;
30
31 import org.apache.derbyTesting.functionTests.harness.jvm;
32 import org.apache.derby.drda.NetworkServerControl;
33 import org.apache.derby.tools.ij;
34 import org.apache.derbyTesting.functionTests.util.TestUtil;
35 import org.apache.derbyTesting.functionTests.util.ExecProcUtil;
36 import org.apache.derby.tools.JDBCDisplayUtil;
37
38 /**
39     This tests the runtimeinfo command
40 */

41
42 public class runtimeinfo
43 {
44
45     private static Properties JavaDoc properties = new java.util.Properties JavaDoc();
46     private static jvm jvm;
47     private static Vector JavaDoc vCmd;
48     private static BufferedOutputStream JavaDoc bos;
49     private static String JavaDoc[] RuntimeinfoCmd = new String JavaDoc[] {"org.apache.derby.drda.NetworkServerControl",
50         "runtimeinfo"};
51     private static String JavaDoc[] RuntimeinfoLocaleCmd = new String JavaDoc[] {"-Duser.language=err",
52         "-Duser.country=DE", "org.apache.derby.drda.NetworkServerControl", "runtimeinfo"};
53     
54
55
56     public static void main (String JavaDoc args[]) throws Exception JavaDoc
57     {
58         if ((System.getProperty("java.vm.name") != null) && System.getProperty("java.vm.name").equals("J9"))
59             jvm = jvm.getJvm("j9_13");
60         else
61             jvm = jvm.getJvm("currentjvm"); // ensure compatibility
62
vCmd = jvm.getCommandLine();
63         try
64         {
65             ij.getPropertyArg(args);
66             Connection conn1 = ij.startJBMS();
67             bos = new BufferedOutputStream JavaDoc(System.out, 1024);
68
69             
70             /************************************************************
71              * Test runtimeinfo
72              ************************************************************/

73             System.out.println("Testing Runtimeinfo");
74             ExecProcUtil.execCmdDumpResults(RuntimeinfoCmd,vCmd,bos);
75             System.out.println("End test");
76             
77             // Now get a couple of connections with some prepared statements
78
Connection conn2 = ij.startJBMS();
79             PreparedStatement ps = prepareAndExecuteQuery(conn1,"SELECT count(*) from sys.systables");
80             PreparedStatement ps2 = prepareAndExecuteQuery(conn1,"VALUES(1)");
81
82             Connection conn3 = ij.startJBMS();
83             PreparedStatement ps3 = prepareAndExecuteQuery(conn2,"SELECT count(*) from sys.systables");
84             PreparedStatement ps4 = prepareAndExecuteQuery(conn2,"VALUES(2)");
85
86
87             /************************************************************
88              * Test runtimeinfo w/ foreign (non-English) locale
89              ************************************************************/

90             System.out.println("Testing Runtimeinfo (locale)");
91             ExecProcUtil.execCmdDumpResults(RuntimeinfoLocaleCmd,vCmd,bos);
92             System.out.println("End test (locale)");
93             ps.close();
94             ps2.close();
95             ps3.close();
96             ps4.close();
97             conn1.close();
98             conn2.close();
99             conn3.close();
100             /** once more after closing the connections
101              * - by calling NetworkServerControl.getRuntimeInfo
102              */

103             System.out.println("Testing Runtimeinfo after closing connectiosn");
104             // give the network server a second to clean up (DERBY-1455)
105
Thread.sleep(1000);
106             NetworkServerControl derbyServer =
107                 new NetworkServerControl( InetAddress.getByName("localhost"),
108                                         NetworkServerControl.DEFAULT_PORTNUMBER);
109             System.out.println(derbyServer.getRuntimeInfo());
110             System.out.println("End test");
111
112             bos.close();
113         }
114         catch (Exception JavaDoc e)
115         {
116             e.printStackTrace();
117         }
118     }
119
120
121     public static PreparedStatement prepareAndExecuteQuery(Connection conn,
122                                                            String JavaDoc sql)
123         throws SQLException
124     {
125         PreparedStatement ps = conn.prepareStatement(sql);
126         ResultSet rs = ps.executeQuery();
127         rs.next();
128         return ps;
129     }
130 }
131
132
133
134
135
136
137
138
139
140
141
Popular Tags