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 import java.util.Timer ; 50 51 public class ModelCreationPerfTest { 52 53 static public void main(String [] args) throws Exception { 54 55 long startTime = System.currentTimeMillis(); 56 57 char[] password={'t','o','t','o'}; 58 SimpleCallbackHandler handler = new SimpleCallbackHandler("admin",password); 59 LoginContext lc = new LoginContext ("TestClient", handler); 60 lc.login(); 61 62 ProjectSessionHome pHome = ProjectSessionUtil.getHome(); 63 try{ 64 65 System.out.println(" --> Model Creation "); 66 ProjectSession psSub = pHome.create(); 67 psSub.initModel("node5Sub"); 68 psSub.addNode("subNode1", Constants.Nd.AND_JOIN_NODE); 69 psSub.addNode("subNode2", Constants.Nd.AND_JOIN_NODE); 70 psSub.setNodeRole("subNode1", "admin"); 71 psSub.setNodeRole("subNode2", "admin"); 72 psSub.addEdge("subNode1", "subNode2"); 73 String script = 74 "import hero.interfaces.BnInstanceLocal;\n" 75 + "import hero.interfaces.BnNodeLocal;\n" 76 + "afterStart (Object b,Object n) {\n\n\n" 77 + "System.out.println(\"SPInstantiation test, SubProcess: \"+n.getName()+\" project: \"+(n.getBnProject()).getName());" 78 + "}"; 79 psSub.addNodeInterHook("subNode2","subNode2",hero.interfaces.Constants.Nd.AFTERSTART,Constants.Hook.BSINTERACTIVE,script); 80 psSub.addUser("admin2"); 81 psSub.setNodeRole("subNode1", "admin"); 82 psSub.setNodeRole("subNode2", "admin"); 83 84 ProjectSession pss = pHome.create(); 85 pss.initModel("Stress"); 86 pss.addNode("node1", Constants.Nd.AND_JOIN_NODE); 87 pss.addNode("node2", Constants.Nd.AND_JOIN_NODE); 88 pss.addNode("node3", Constants.Nd.AND_JOIN_NODE); 89 pss.addNode("node4", Constants.Nd.AND_JOIN_AUTOMATIC_NODE); 90 pss.addNode("node5Sub",Constants.Nd.AND_JOIN_NODE); 92 pss.addEdge("node1", "node2"); 93 pss.addEdge("node2", "node3"); 94 pss.addEdge("node2", "node4"); 95 pss.addEdge("node3", "node5Sub"); 96 script = 97 "import hero.interfaces.BnInstanceLocal;\n" 98 + "import hero.interfaces.BnNodeLocal;\n" 99 + "afterStart (Object b,Object n) {\n\n\n" 100 + "System.out.println(\"Stress test, node: \"+n.getName()+\" project: \"+(n.getBnProject()).getName());" 101 + "}"; 102 pss.addNodeInterHook("node2","node2",hero.interfaces.Constants.Nd.AFTERSTART,Constants.Hook.BSINTERACTIVE,script); 103 pss.addUser("admin2"); 104 pss.setUserRole("admin2", "InitialRole"); 105 pss.setNodeRole("node1", "admin"); 106 pss.setNodeRole("node2", "admin"); 107 pss.setNodeRole("node3", "admin"); 108 pss.setNodeRole("node4", "admin"); 109 pss.setNodeRole("node5Sub", "admin"); 110 System.out.println(" --> Stress Model totally created "); 111 psSub.remove(); 112 pss.remove() ; 113 }catch(Exception e){System.out.println(" --> " + e);} 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 } } | Popular Tags |