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.FileInputStream ; 28 import java.io.FileOutputStream ; 29 import java.io.BufferedOutputStream ; 30 import java.io.InputStream ; 31 import java.io.OutputStream ; 32 import java.io.ByteArrayInputStream ; 33 import java.io.FileNotFoundException ; 34 35 import org.apache.derbyTesting.functionTests.harness.jvm; 36 import org.apache.derbyTesting.functionTests.harness.Sed; 37 import org.apache.derbyTesting.functionTests.util.TestUtil; 38 import org.apache.derbyTesting.functionTests.util.ExecProcUtil; 39 40 import org.apache.derby.drda.NetworkServerControl; 41 42 43 public class testij 44 { 45 46 47 private static Properties properties = new java.util.Properties (); 48 private static jvm jvm; 49 private static Vector vCmd; 50 51 private static String IjCmd="org.apache.derby.tools.ij"; 52 private static String SqlDir="extin"; 53 private static String jccSqlFile="testij.sql"; 54 private static String sep; 55 private static String clientSqlFile="testclientij.sql"; 56 private static String altExtinDir; 57 private static boolean useAltExtinDir=false; 58 59 private static void execCmd (String [] args) throws Exception 60 { 61 int totalSize = vCmd.size() + args.length; 62 String serverCmd[] = new String [totalSize]; 63 int i; 64 for (i = 0; i < vCmd.size(); i++) 65 { 66 serverCmd[i] = (String )vCmd.elementAt(i); 67 } 69 int j = 0; 70 for (; i < totalSize; i++) 71 { 72 serverCmd[i] = args[j++]; 73 } 75 76 Process pr = Runtime.getRuntime().exec(serverCmd); 78 pr.waitFor(); } 80 81 public static void massageSqlFile (String hostName, String fileName) throws Exception { 82 File tmpFile = new File ("extin", "tmpFile.sql"); 86 File orgFile = new File ("extin", fileName); 87 InputStream original; 89 OutputStream copy; 90 try { 91 fileName = SqlDir + sep + fileName; 92 original = new FileInputStream (fileName); 93 copy = new FileOutputStream (tmpFile); 94 } 95 catch (FileNotFoundException fnfe) { 96 useAltExtinDir = true; 98 String userdir = System.getProperty("user.dir"); 99 altExtinDir = userdir + sep + ".."; 100 tmpFile = new File (altExtinDir, "tmpFile.sql"); 101 orgFile = new File (altExtinDir, fileName); 102 fileName = altExtinDir + sep + fileName; 103 original = new FileInputStream (fileName); 104 copy = new FileOutputStream (tmpFile); 105 } 106 int content; 107 while ((content = original.read())> 0 ) { 108 copy.write(content); 109 } 110 copy.close(); 111 original.close(); 112 Sed hostSed = new Sed(); 113 InputStream sedIs = new ByteArrayInputStream (("substitute=localhost;" + hostName).getBytes("UTF-8")); 114 hostSed.exec(tmpFile, orgFile, sedIs, false, false, false); 115 } 116 117 public static void main (String args[]) throws Exception 118 { 119 if ((System.getProperty("java.vm.name") != null) && System.getProperty("java.vm.name").equals("J9")) 120 jvm = jvm.getJvm("j9_13"); 121 else 122 jvm = jvm.getJvm("currentjvm"); vCmd = jvm.getCommandLine(); 124 sep = System.getProperty("file.separator"); 125 try 126 { 127 BufferedOutputStream bos = new BufferedOutputStream (System.out, 1024); 128 131 NetworkServerControl server = new NetworkServerControl(); 133 System.out.println("Testing various ij connections and comments in front of selects"); 134 135 138 String hostName=TestUtil.getHostName(); 139 if (TestUtil.isJCCFramework()){ 140 if (!hostName.equals("localhost")) 142 massageSqlFile(hostName,jccSqlFile); 143 if (useAltExtinDir) 144 ExecProcUtil.execCmdDumpResults(new String []{IjCmd,(altExtinDir + sep + SqlDir + sep + jccSqlFile)},vCmd,bos); 145 ExecProcUtil.execCmdDumpResults(new String []{IjCmd,(SqlDir + sep + jccSqlFile)},vCmd,bos); 146 } else { if(!hostName.equals("localhost")) { 149 massageSqlFile(hostName,clientSqlFile); 150 if (useAltExtinDir) 151 ExecProcUtil.execCmdDumpResults(new String []{IjCmd,(altExtinDir + sep + SqlDir + sep + clientSqlFile)},vCmd,bos); 152 } 153 ExecProcUtil.execCmdDumpResults(new String []{IjCmd,(SqlDir + sep + clientSqlFile)},vCmd,bos); 154 } 155 System.out.println("End test"); 156 } 157 catch (Exception e) 158 { 159 e.printStackTrace(); 160 } 161 } 162 163 } 164 165 166 | Popular Tags |