1 29 30 package hero.client.test.perf; 31 32 import javax.security.auth.login.LoginContext ; 33 import hero.client.test.SimpleCallbackHandler; 34 35 import hero.interfaces.ProjectSession; 36 import hero.interfaces.ProjectSessionHome; 37 import hero.interfaces.ProjectSessionUtil; 38 import hero.interfaces.UserSession; 39 import hero.interfaces.UserSessionHome; 40 import hero.interfaces.UserSessionUtil; 41 import hero.interfaces.UserRegistration; 42 import hero.interfaces.UserRegistrationHome; 43 import hero.interfaces.UserRegistrationUtil; 44 import junit.framework.TestCase; 45 import junit.framework.TestSuite; 46 import hero.interfaces.Constants; 47 import java.util.Collection ; 48 import java.util.Iterator ; 49 50 public class InstancesPerfTest { 51 52 53 static public void main(String [] args) throws Exception { 54 55 int argNb = 2; 56 if (args.length != argNb) { 57 System.out.println("Number of arguments needed : "+argNb); 58 System.out.println("Args : userId nbInstances"); 59 } else { 60 61 String uNb="0" ; 62 int instNb = 10 ; 63 64 long startTime = System.currentTimeMillis(); 65 66 try { 67 uNb = new String (args[0]); 68 String instanceNum = new String (args[1]); 69 System.out.println("Parametres : uNb: "+ uNb+" - instanceNum: "+instanceNum) ; 70 instNb = Integer.valueOf(instanceNum).intValue() ; 71 }catch(Exception e){System.out.println(" --> " + e);} 72 73 String uName= "user"+uNb; 74 char[] password=uName.toCharArray(); 75 SimpleCallbackHandler handler = new SimpleCallbackHandler(uName,password); 76 LoginContext lc = new LoginContext ("TestClient", handler); 77 lc.login(); 78 79 ProjectSessionHome pHome = ProjectSessionUtil.getHome(); 80 int i=0; 81 for (i=0;i<instNb;i++) { 82 ProjectSession ps = pHome.create(); 83 ps.instantiateProject("Stress"); 84 System.out.println(" --> User: " + uName +" -- Instanciate Stress Model"); 85 Thread.sleep(100); 86 ps.remove(); 87 } 88 89 UserSessionHome uHome = UserSessionUtil.getHome(); 90 UserSession us = uHome.create(); 91 Collection instances = us.getInstancesListNames(); 92 Iterator index = instances.iterator(); 93 UserSession usUser = uHome.create(); 94 while (index.hasNext()) 95 { 96 String name = (String )index.next(); 97 Collection task = usUser.getToDoList(name); 98 Iterator it = task.iterator(); 99 while (it.hasNext()) 100 { 101 String activity = (String )it.next(); 102 usUser.startActivity(name,activity); 103 System.out.println(" --> User: " + uName +" Instance: "+name+" -- Start Act: " + activity); 104 if (activity.matches(".*_instance.*")) 105 executeSubProcess(activity); 106 107 Thread.sleep(100); 108 usUser.terminateActivity(name,activity); 109 System.out.println(" --> User: " + uName +" -- Stop Act: " + activity); 110 task = usUser.getToDoList(name); 111 it = task.iterator(); 112 } 113 } 114 115 long time = System.currentTimeMillis(); 116 long tmp = (time - startTime)/1000; 117 long h = tmp/3600; 118 long m = (tmp-3600*h)/60; 119 long s = tmp-3600*h-60*m; 120 System.out.println(" --> Stress Model system time elapsed : " + h + ":"+ m + ":" + s ); 121 } 122 123 } 124 125 public static void executeSubProcess(String subProcess) throws Exception { 126 UserSessionHome uHome = UserSessionUtil.getHome(); 127 UserSession us = uHome.create(); 128 us.startActivity(subProcess,"subNode1"); 129 us.terminateActivity(subProcess,"subNode1"); 130 us.startActivity(subProcess,"subNode2"); 131 us.terminateActivity(subProcess,"subNode2"); 132 } 133 134 } 135 | Popular Tags |