KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > client > test > perf > ModelCreationPerfTest


1 /**
2  *
3  * Bonita
4  * Copyright (C) 1999 Bull S.A.
5  * Bull 68 route de versailles 78434 Louveciennes Cedex France
6  * Further information: bonita@objectweb.org
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  * USA
22  *
23  *
24 --------------------------------------------------------------------------
25  * $Id: ModelCreationPerfTest.java,v 1.2 2005/03/18 14:51:23 mvaldes Exp $
26  *
27 --------------------------------------------------------------------------
28  */

29
30 package hero.client.test.perf;
31
32 import javax.security.auth.login.LoginContext JavaDoc;
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 JavaDoc;
48 import java.util.Iterator JavaDoc;
49 import java.util.Timer JavaDoc;
50
51 public class ModelCreationPerfTest {
52     
53     static public void main(String JavaDoc[] args) throws Exception JavaDoc{
54
55     long startTime = System.currentTimeMillis();
56     
57       char[] password={'t','o','t','o'};
58       SimpleCallbackHandler handler = new SimpleCallbackHandler("admin",password);
59       LoginContext JavaDoc lc = new LoginContext JavaDoc("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 JavaDoc 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.addNodeSubProcess("node5Sub","Stress");
91
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 JavaDoc 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     } // End Main/
122
} // End Class
123
Popular Tags