1 21 22 package org.apache.derby.impl.tools.ij; 23 24 import java.util.Hashtable ; 25 import java.util.Properties ; 26 import java.lang.Math ; 27 import java.io.FileNotFoundException ; 28 import java.io.BufferedInputStream ; 29 30 import java.io.FileInputStream ; 31 import java.io.IOException ; 32 33 import org.apache.derby.iapi.tools.i18n.*; 34 35 37 public class mtTestCase 38 { 39 public String name = null; 40 public String file = null; 41 public String propFile = null; 42 public float weight = (float).5; 43 public Hashtable ignoreErrors = null; 44 public String description = null; 45 46 47 private int iterations; 48 private int attempts; 49 50 public void mtTestCase() 51 { }; 52 53 public void setName(String name) 54 { 55 this.name = name; 56 } 57 public String getName() 58 { 59 return name; 60 } 61 62 public void setFile(String name) 63 { 64 this.file = name; 65 } 66 67 public void setInputDir(String dir) 68 { 69 file = dir + "/" + file; 70 } 71 72 public String getFile() 73 { 74 return file; 75 } 76 77 public void setPropFile(String name) 78 { 79 this.propFile = name; 80 } 81 82 public String getPropFile() 83 { 84 return propFile; 85 } 86 87 public void setWeight(int weight) 88 { 89 this.weight = (float)(weight/100.0); 90 } 91 92 public void setIgnoreErrors(Hashtable t) 93 { 94 this.ignoreErrors = t; 95 } 96 97 public void setDescription(String description) 98 { 99 this.description = description; 100 } 101 102 105 public synchronized BufferedInputStream initialize() 106 throws FileNotFoundException , IOException 107 { 108 return initialize(null); 109 } 110 111 116 public synchronized BufferedInputStream initialize(String inputDir) 117 throws FileNotFoundException , IOException 118 { 119 String filePath; 120 BufferedInputStream inStream = null; 121 122 if (propFile != null) 124 { 125 BufferedInputStream propStream; 126 Properties p; 127 String propPath = (inputDir == null) ? 128 propFile : 129 (inputDir + "/" + propFile); 130 131 try 132 { 133 propStream = new BufferedInputStream (new FileInputStream (propPath)); 134 } catch (FileNotFoundException e) 135 { 136 System.out.println(name+": unable to find properties file "+propPath); 137 throw e; 138 } 139 140 p = System.getProperties(); 141 p.load(propStream); 142 String framework = p.getProperty("framework"); 144 145 if (framework != null) 146 { 147 String newURLPrefix = null; 148 framework = framework.toUpperCase(java.util.Locale.ENGLISH); 149 if (framework.equals("DB2JNET") || framework.equals("DERBYNET")) 150 newURLPrefix= "jdbc:derby:net://localhost:1527/"; 151 else if (framework.equals("DERBYNETCLIENT")) 152 newURLPrefix= "jdbc:derby://localhost:1527/"; 153 if (newURLPrefix != null) 154 { 155 updateURLProperties(p,newURLPrefix); 156 p.setProperty("ij.user","APP"); 157 p.setProperty("ij.password","PWD"); 158 } 159 } 160 if (("true").equalsIgnoreCase(p.getProperty("encryption"))) 164 { 165 String encryptUrl = "dataEncryption=true;bootPassword=Thursday"; 166 String dbUrl = p.getProperty("ij.database"); 167 String encryptionAlgorithm = p.getProperty("encryptionAlgorithm"); 168 if (encryptionAlgorithm != null) 169 { 170 p.setProperty( 171 "ij.database", 172 dbUrl + ";" + encryptUrl + ";" + encryptionAlgorithm); 173 } 174 else 175 { 176 p.setProperty("ij.database",dbUrl + ";"+encryptUrl); 177 } 178 } 179 180 if (System.getProperty("ij.dataSource") != null) 186 { 187 p.remove("ij.database"); 188 p.remove("ij.protocol"); 189 } 190 191 System.setProperties(p); 192 } 193 filePath = (inputDir == null) ? 195 file : (inputDir + "/" + file); 196 197 try 198 { 199 inStream = new BufferedInputStream (new FileInputStream (filePath), 200 utilMain.BUFFEREDFILESIZE); 201 } catch (FileNotFoundException e) 202 { 203 System.out.println("unable to find properties file "+filePath); 204 throw e; 205 } 206 return inStream; 207 } 208 209 216 public synchronized boolean grab() 217 { 218 attempts++; 219 if (java.lang.Math.random() < weight) 220 { 221 iterations++; 222 return true; 223 } 224 else 225 { 226 return false; 227 } 228 } 229 230 234 public void runMe(LocalizedOutput log, LocalizedOutput out, BufferedInputStream infile) 235 { 236 utilMain utilInstance; 237 LocalizedInput is; 238 is = LocalizedResource.getInstance().getNewInput(infile); 239 240 LocalizedInput [] in = { is }; 241 242 out.println("--------------"+file+"-----------------"); 243 utilInstance = new utilMain(1, out, ignoreErrors); 244 utilInstance.initFromEnvironment(); 245 utilInstance.setMtUse(true); 246 utilInstance.go(in, out, (java.util.Properties ) null); 247 log.flush(); 248 out.flush(); 249 } 250 251 public void updateURLProperties(Properties p, String newURLPrefix) 252 { 253 String [] propsToUpdate = {"ij.database", "ij.protocol", 254 "database"}; 255 for (int i = 0; i < propsToUpdate.length; i++) 256 { 257 String key = propsToUpdate[i]; 258 String val = p.getProperty(key); 259 if (val != null) 260 p.setProperty(key,alterURL(val,newURLPrefix)); 261 } 262 } 263 264 265 public String alterURL(String url, String newURLPrefix) 266 { 267 String urlPrefix = "jdbc:derby:"; 268 269 if (url.startsWith(newURLPrefix)) 270 return url; 271 272 if (newURLPrefix == null) 275 return url; 276 277 if (url.equals(urlPrefix)) return newURLPrefix; 279 280 if (url.startsWith(urlPrefix)) 281 { 282 url = newURLPrefix + 284 url.substring(urlPrefix.length()); 285 286 } 287 else 288 { 289 if (! (url.startsWith("jdbc:"))) 290 { 291 url = newURLPrefix + url; 292 } 293 } 294 return url; 296 } 297 298 299 320 323 public String toString() 324 { 325 return "name: "+name+ 326 "\n\tfile: "+file+ 327 "\n\tproperties: "+propFile+ 328 "\n\tweight: "+weight+ 329 "\n\tignoreErrors: "+ignoreErrors+ 330 "\n\tdescription: "+description; 331 } 332 333 334 } 335 | Popular Tags |