1 package com.ca.commons.jndi; 2 3 4 import java.util.*; 5 import java.util.logging.*; 6 7 import javax.naming.NamingException ; 8 9 import com.ca.commons.cbutil.*; 10 import com.ca.commons.naming.DXEntry; 11 12 13 14 29 30 public class TestJNDIBulkOps 31 { 32 35 36 final static String FILENAME = "BulkJndiTest.txt"; 37 38 private final static Logger log = Logger.getLogger(TestJNDIBulkOps.class.getName()); 39 40 41 57 58 public static void main (String args[]) 59 { 60 log.addHandler(new ConsoleHandler()); 61 log.setLevel(Level.FINE); 62 63 Properties properties = new Properties(); 64 65 properties = CBUtility.readPropertyFile(FILENAME); 66 if (properties.size()==0) { log.warning("Can't find: " + FILENAME); return;} 67 68 new TestJNDIBulkOps(args, properties); 69 } 70 71 72 73 96 97 public TestJNDIBulkOps(String args[], Properties properties) 98 { 99 String url = null; 100 String user = null; 101 String pwd = null; 102 String version = "3"; 103 String referral = "follow"; 104 boolean useSSL = false; 105 boolean tracing = false; 106 boolean debugFlag = false; 107 boolean terminateFlag = false; 108 boolean printstackFlag = false; 109 110 try 111 { 112 int i=0; 113 114 while (i<args.length) 115 { 116 String arg = (args[i].charAt(0) != '-')?args[i]:args[i].substring(1); 117 switch(arg.charAt(0)) 118 { 119 case '?': 120 case 'H': 121 case 'h': if (args.length>i+1) 122 System.out.println(args[i+1]); 123 else 124 return; 125 case 'D': 126 case 'd': debugFlag = true; break; 127 case 'E': 128 case 'e': terminateFlag = true; break; 129 case 'P': 130 case 'p': pwd = args[++i]; break; 131 case 'R': 132 case 'r': referral = args[++i]; break; 133 case 'S': 134 case 's': useSSL = true; break; 135 case 'T': 136 case 't': tracing = true; break; 137 case 'U': 138 case 'u': user = args[++i]; break; 139 case 'V': 140 case 'v': version = args[++i]; break; 141 case 'X': 142 case 'x': printstackFlag = true; break; 143 144 default : System.out.println("\n\nInvalid command line argument: -" + arg); 145 return; 146 } 147 i++; 148 } 149 } 150 catch (Exception e) 151 { 152 System.out.println("Error reading command line arguments."); 153 System.exit(-1); 154 } 155 156 157 int numberOfThreads = -1; int numberOfIterations = -1; 160 try 161 { 162 numberOfThreads = Integer.parseInt(properties.getProperty("NumberOfThreads").toString()); 164 165 numberOfIterations = Integer.parseInt(properties.getProperty("NumberOfIterations").toString()); 167 168 if(numberOfThreads <=0 || numberOfThreads > 20) 170 { 171 System.out.println("Problem accessing the number of threads you wish to run." + 172 " Check the property file 'BulkJndiTest.txt' and make sure the" + 173 " 'NumberOfThreads' entry contains a valid integer between 1 and 10."); 174 System.exit(-1); 175 } 176 } 177 catch(NumberFormatException e) 178 { 179 System.out.println("Problem accessing the number of threads you wish to run." + 180 " Check the property file 'BulkJndiTest.txt' and make sure the" + 181 " 'NumberOfThreads' entry contains a valid integer between 1 and 10." + 182 " Also check that the 'NumberOfIterations' contains a valid integer."); 183 System.exit(-1); 184 } 185 186 url = properties.getProperty("ComputerName").toString()+":"+properties.getProperty("Port").toString(); 187 188 if (url==null) 189 { 190 System.out.println("Problem accessing the computer name from the property file 'BulkJndiTest.txt'."+ 191 "Please check that a valid name is supplied in the 'ComputerName' entry."); 192 System.exit(-1); 193 } 194 195 Thread [] threads = new Thread [] {new Thread (new Test(properties.getProperty("ThreadOneLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread ONE"), 196 new Thread (new Test(properties.getProperty("ThreadTwoLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread TWO"), 197 new Thread (new Test(properties.getProperty("ThreadThreeLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread THREE"), 198 new Thread (new Test(properties.getProperty("ThreadFourLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread FOUR"), 199 new Thread (new Test(properties.getProperty("ThreadFiveLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread FIVE"), 200 new Thread (new Test(properties.getProperty("ThreadSixLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread SIX"), 201 new Thread (new Test(properties.getProperty("ThreadSevenLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread SEVEN"), 202 new Thread (new Test(properties.getProperty("ThreadEightLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread EIGHT"), 203 new Thread (new Test(properties.getProperty("ThreadNineLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread NINE"), 204 new Thread (new Test(properties.getProperty("ThreadTenLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread TEN"), 205 new Thread (new Test(properties.getProperty("ThreadElevenLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread ELEVEN"), 206 new Thread (new Test(properties.getProperty("ThreadTwelveLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread TWELVE"), 207 new Thread (new Test(properties.getProperty("ThreadThreeteenLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread THIRTEEN"), 208 new Thread (new Test(properties.getProperty("ThreadFourteenLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread FOURTEEN"), 209 new Thread (new Test(properties.getProperty("ThreadFifteenLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread FIFTTEEN"), 210 new Thread (new Test(properties.getProperty("ThreadSixteenLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread SIXTEEN"), 211 new Thread (new Test(properties.getProperty("ThreadSeventeenLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread SEVENTEEN"), 212 new Thread (new Test(properties.getProperty("ThreadEighteenLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread EIGHTEEN"), 213 new Thread (new Test(properties.getProperty("ThreadNineteenLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread NINETEEN"), 214 new Thread (new Test(properties.getProperty("ThreadTwentyLDIFFileName").toString(), url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag, numberOfIterations), "Test Thread TWENTY")}; 215 216 for(int i=0; i<numberOfThreads; i++) 217 { 218 try 219 { 220 threads[i].start(); 221 System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"+ 222 "Starting Thread: " + threads[i].getName() + 223 "\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); 224 } 225 catch(IllegalThreadStateException e) 226 { 227 System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"+ 228 "Error Starting Thread: " + threads[i].getName() + 229 "\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +e); 230 } 231 } 232 } 233 234 235 236 242 243 class Test implements Runnable 244 { 245 String fileName = null; 246 String url = null; 247 String user = null; 248 String pwd = null; 249 String version = "3"; 250 String referral = "follow"; 251 boolean useSSL = false; 252 boolean tracing = false; 253 boolean debugFlag = false; 254 boolean terminateFlag = false; 255 boolean printstackFlag = false; 256 int numberOfIterations = -1; 257 258 273 274 public Test(String fileName, String url, String user, String pwd, boolean tracing, String version, boolean debugFlag, boolean terminateFlag, String referral, boolean useSSL, boolean printstackFlag, int numberOfIterations) 275 { 276 this.fileName = fileName; 277 this.url = url; 278 this.user = user; 279 this.pwd = pwd; 280 this.version = version; 281 this.referral = referral; 282 this.useSSL = useSSL; 283 this.tracing = tracing; 284 this.debugFlag = debugFlag; 285 this.terminateFlag = terminateFlag; 286 this.printstackFlag = printstackFlag; 287 this.numberOfIterations = numberOfIterations; 288 } 289 290 291 292 296 297 public void run() 298 { 299 for(int i=1;i<=numberOfIterations;i++) 300 { 301 myJndiTest tester = new myJndiTest(fileName, url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag); 302 tester.processInput(); 303 304 tester.out.println("\n*****************************************************************************************" + 305 "\n* FINISHED TESTING OF THREAD: '"+Thread.currentThread().toString()+ "' ITERATION: "+i+ 306 "\n*****************************************************************************************"); 307 } 308 } 309 310 } 311 312 313 314 320 321 class myJndiTest extends TestJNDIOps 322 { 323 String myUrl; 324 325 public myJndiTest(String fileName, String url, String user, String pwd, boolean tracing, String version, boolean debugFlag, boolean terminateFlag, String referral, boolean useSSL, boolean printstackFlag) 326 { 327 super(fileName, url, user, pwd, tracing, version, debugFlag, terminateFlag, referral, useSSL, printstackFlag); 328 this.myUrl = url; 329 } 330 331 332 337 338 public void connect(DXEntry entry) 339 { 340 if (debug) System.out.println("connect: " + entry); 341 if (myOps != null) 342 { 343 try 344 { 345 myOps.close(); 346 } 347 catch (NamingException e) 348 { 349 System.err.println("exception closing ops"); 350 e.printStackTrace(); 351 } 352 } 353 354 String url = ""; 355 356 if(myUrl!=null) 357 url = myUrl; 358 else 359 url = entry.getString("url"); 360 String user = entry.getString("user"); 361 String pwd = entry.getString("pwd"); 362 String tracing = entry.getString("tracing"); 363 String version = entry.getString("ldapVersion"); 364 String referral = entry.getString("referral"); 365 String useSSL = entry.getString("useSSL"); 366 367 boolean trace = ((tracing != null) && (tracing.equalsIgnoreCase("true"))); 368 boolean ssl = ((useSSL != null) && (useSSL.equalsIgnoreCase("true"))); 369 openConnection(url, user, pwd, trace, version, referral, ssl); 370 } 371 } 372 } | Popular Tags |