1 21 package org.apache.derbyTesting.functionTests.tests.derbynet; 22 23 import java.sql.*; 24 import java.util.Vector ; 25 import java.util.Properties ; 26 import java.io.File ; 27 import java.io.FileOutputStream ; 28 import java.io.BufferedOutputStream ; 29 30 import org.apache.derbyTesting.functionTests.harness.jvm; 31 import org.apache.derbyTesting.functionTests.harness.ProcessStreamResult; 32 import org.apache.derbyTesting.functionTests.util.TestUtil; 33 import org.apache.derby.tools.ij; 34 35 38 39 public class testconnection 40 { 41 42 private static jvm jvm; 43 private static Vector vCmd; 44 private static String hostName; 45 private static String [] TestConnectionCmd1 = new String [] {"org.apache.derby.drda.NetworkServerControl", 46 "ping"}; 47 private static String [] TestConnectionCmd2 = new String [] {"org.apache.derby.drda.NetworkServerControl", 48 "ping", "-h", "localhost", "-p", "1527"}; 49 private static String [] TestConnectionCmd3 = new String [] {"org.apache.derby.drda.NetworkServerControl", 50 "ping", "-h", "notthere", "-p", "1527"}; 51 private static String [] TestConnectionCmd3a = new String [] {"org.apache.derby.drda.NetworkServerControl", "ping", "-h", "ihave-inmyname.com", "-p", "1527"}; 52 private static String [] TestConnectionCmd4 = new String [] {"org.apache.derby.drda.NetworkServerControl", 53 "ping", "-h", "localhost"}; 54 private static String [] TestConnectionCmd5 = new String [] {"org.apache.derby.drda.NetworkServerControl", 55 "ping", "-h", "localhost", "-p", "9393"}; 56 private static String [] TestConnectionCmd6 = new String [] {"org.apache.derby.drda.NetworkServerControl", 57 "ping", "-h", "localhost", "-p", "1527"}; 58 private static String [] TestConnectionCmd6b = new String [] {"org.apache.derby.drda.NetworkServerControl", 59 "ping", "-h", "localhost", "-p", "1527"}; 60 private static String [] TestConnectionCmd7 = new String [] {"org.apache.derby.drda.NetworkServerControl", 61 "ping", "-h", "localhost", "-p", "9393"}; 62 private static String [] TestConnectionCmd7b = new String [] {"org.apache.derby.drda.NetworkServerControl", 63 "ping", "-h", "localhost", "-p", "9393"}; 64 65 private static BufferedOutputStream bos = null; 66 67 74 private static String timeoutMinutes = "2"; 75 76 83 private static void execCmdDumpResults (String [] args, boolean printcmd) 84 throws Exception 85 { 86 execCmdDumpResults(args, 0, printcmd); 87 } 88 89 95 private static void execCmdDumpResults (String [] args) 96 throws Exception 97 { 98 execCmdDumpResults(args, 0, true); 99 } 100 101 102 108 private static void execCmdDumpResults (String [] args, int expectedExitCode) 109 throws Exception 110 { 111 execCmdDumpResults(args, expectedExitCode, true); 112 } 113 114 122 private static void execCmdDumpResults (String [] args, int expectedExitCode, boolean printcmd) 123 throws Exception 124 { 125 ProcessStreamResult prout = null; 127 ProcessStreamResult prerr = null; 128 129 StringBuffer sb = new StringBuffer (); 130 131 for (int i = 0; i < args.length; i++) 132 { 133 sb.append(args[i] + " "); 134 } 135 if (printcmd) 136 System.out.println(sb.toString()); 137 else 138 System.out.println("org.apache.derby.drda.NetworkServerControl ping..."); 139 int totalSize = vCmd.size() + args.length; 140 String serverCmd[] = new String [totalSize]; 141 int i; 142 for (i = 0; i < vCmd.size(); i++) 143 { 144 serverCmd[i] = (String )vCmd.elementAt(i); 145 } 147 int j = 0; 148 for (; i < totalSize; i++) 149 { 150 serverCmd[i] = args[j++]; 151 } 153 154 Process pr = Runtime.getRuntime().exec(serverCmd); 156 prout = new ProcessStreamResult(pr.getInputStream(), bos, timeoutMinutes); 157 prerr = new ProcessStreamResult(pr.getErrorStream(), bos, timeoutMinutes); 158 159 prout.Wait(); 161 prerr.Wait(); 162 163 pr.waitFor(); 165 166 if ( pr.exitValue() != expectedExitCode ) 168 { 169 System.out.println("FAIL: expected exit code of " + 170 expectedExitCode + ", got exit code of " + pr.exitValue()); 171 } 172 173 } 174 175 176 public static void main (String args[]) throws Exception 177 { 178 hostName = TestUtil.getHostName(); 179 TestConnectionCmd2[3] = hostName; 180 TestConnectionCmd4[3] = hostName; 181 TestConnectionCmd5[3] = hostName; 182 TestConnectionCmd6b[3] = hostName; 183 TestConnectionCmd7b[3] = hostName; 184 185 186 187 if ((System.getProperty("java.vm.name") != null) && System.getProperty("java.vm.name").equals("J9")) 188 jvm = jvm.getJvm("j9_13"); 189 else 190 jvm = jvm.getJvm("currentjvm"); vCmd = jvm.getCommandLine(); 192 try 193 { 194 Connection conn1 = ij.startJBMS(); 195 bos = new BufferedOutputStream (System.out, 1024); 196 197 200 System.out.println("Testing testconnection"); 201 if (!hostName.equals("localhost")) { 204 execCmdDumpResults(TestConnectionCmd4, 0, false); 205 } 206 else 207 execCmdDumpResults(TestConnectionCmd1, false); 208 execCmdDumpResults(TestConnectionCmd2); 210 execCmdDumpResults(TestConnectionCmd3, 1); 212 execCmdDumpResults(TestConnectionCmd3a, 1); 214 execCmdDumpResults(TestConnectionCmd4); 216 execCmdDumpResults(TestConnectionCmd5, 1); 218 if (!hostName.equals("localhost")) execCmdDumpResults(TestConnectionCmd6b, false); 221 else 222 execCmdDumpResults(TestConnectionCmd6, false); 223 if (!hostName.equals("localhost")) execCmdDumpResults(TestConnectionCmd7b, 1, false); 226 else 227 execCmdDumpResults(TestConnectionCmd7, 1, false); 228 229 System.out.println("End test"); 230 bos.close(); 231 } 232 catch (Exception e) 233 { 234 e.printStackTrace(); 235 } 236 } 237 } 238 | Popular Tags |