1 14 package org.wings.recorder; 15 16 import java.io.FileOutputStream ; 17 import java.io.PrintStream ; 18 import java.util.Iterator ; 19 import java.util.LinkedList ; 20 import java.util.List ; 21 22 public class Simulator { 23 public static void main(String [] args) { 24 int index = 0; 25 boolean fail = false; 26 27 float delay = 1.0f; 28 String auth = "BASIC"; 29 String userid = "user "; 30 String password = null; 31 int iterations = 1; 32 int ramp = 0; 33 34 try { 35 while (index < args.length) { 36 if ("-d".equals(args[index]) || "--delay".equals(args[index])) 37 delay = new Float (args[index + 1]).floatValue(); 38 else if ("-a".equals(args[index]) || "--auth".equals(args[index])) 39 auth = args[index + 1]; 40 else if ("-u".equals(args[index]) || "--userid".equals(args[index])) 41 userid = args[index + 1]; 42 else if ("-p".equals(args[index]) || "--password".equals(args[index])) 43 password = args[index + 1]; 44 else if ("-i".equals(args[index]) || "--iterations".equals(args[index])) 45 iterations = new Integer (args[index + 1]).intValue(); 46 else if ("-r".equals(args[index]) || "--ramp".equals(args[index])) 47 ramp = new Integer (args[index + 1]).intValue(); 48 else if ("-o".equals(args[index]) || "--output".equals(args[index])) 49 System.setOut(new PrintStream (new FileOutputStream (args[index + 1]))); 50 else 51 break; 52 53 index += 2; 54 } 55 } catch (Exception e) { fail = true; } 56 57 if (fail || args.length < index + 2) { 58 printUsage(); 59 System.exit(1); 60 } 61 62 String url = args[index]; 63 String scriptClassName = args[index + 1]; 64 65 int firstUser; 66 int lastUser; 67 int pos = args[index + 2].indexOf("-"); 68 if (pos > -1) { 69 String a = args[index + 2].substring(0, pos); 70 String b = args[index + 2].substring(pos + 1); 71 firstUser = Integer.valueOf(a).intValue(); 72 lastUser = Integer.valueOf(b).intValue(); 73 } else { 74 firstUser = 1; 75 lastUser = Integer.valueOf(args[index + 2]).intValue(); 76 } 77 78 try { 79 Class scriptClass = Class.forName(scriptClassName); 80 81 System.out.println("INFO: initializing clients for " + 82 userid + firstUser + " to " + userid + lastUser); 83 List clients = new LinkedList (); 84 for (int i = firstUser; i <= lastUser; i++) { 85 Script script = (Script) scriptClass.newInstance(); 86 script.setUrl(url); 87 script.setDelay(delay); 88 89 Client client = new Client(); 90 client.init(script); 91 client.setUserid(userid + i); 92 client.setPasswd(password); 93 client.setInitialDelay((i - firstUser) * ramp); 94 client.setIterations(iterations); 95 clients.add(client); 96 } 97 98 System.out.println("INFO: starting clients"); 99 Iterator it = clients.iterator(); 100 while (it.hasNext()) { 101 Client client = (Client) it.next(); 102 client.start(); 103 } 104 } catch (Exception e) { 105 System.err.println(e.getMessage()); 106 e.printStackTrace(System.err); 107 } 108 } 109 110 protected static void printUsage() { 111 System.err.println("usage: simulator [options] url script_class user_range"); 112 System.err.println("arguments:"); 113 System.err.println(" url url of application client jar with deployment descriptors"); 114 System.err.println(" script_class full qualified classname"); 115 System.err.println(" user_range 1-'lastUser' or 'firstUser'-'lastUser'"); 116 System.err.println("options:"); 117 System.err.println(" -d, --delay [0..t] factor, that is applied to the recorded delays"); 118 System.err.println(" 0.0 for no delays, 1.0 for same tempo as during recording (default)"); 119 System.err.println(" -a, --auth the auth type, one of HTTP, JBoss (more to follow), defaults to HTTP"); 120 System.err.println(" -u, --userid the base userid, to which firstUser .. lastUser will be appended, defaults to 'demo'"); 121 System.err.println(" -p, --password the password for all users"); 122 System.err.println(" -i, --iterations number of iterations a virtual user runs the script, defaults to 'start'"); 123 System.err.println(" -r, --ramp load ramp, n'th client is started after n times the delay in ms, default is 0"); 124 System.err.println(" -o, --output redirect output to a file"); 125 } 126 } 127 128 129 | Popular Tags |