001: /**
002: *
003: * Bonita
004: * Copyright (C) 1999 Bull S.A.
005: * Bull 68 route de versailles 78434 Louveciennes Cedex France
006: * Further information: bonita@objectweb.org
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
021: * USA
022: *
023: *
024: --------------------------------------------------------------------------
025: * $Id: ModelCreationPerfTest.java,v 1.2 2005/03/18 14:51:23 mvaldes Exp $
026: *
027: --------------------------------------------------------------------------
028: */package hero.client.test.perf;
029:
030: import javax.security.auth.login.LoginContext;
031: import hero.client.test.SimpleCallbackHandler;
032:
033: import hero.interfaces.ProjectSession;
034: import hero.interfaces.ProjectSessionHome;
035: import hero.interfaces.ProjectSessionUtil;
036: import hero.interfaces.UserSession;
037: import hero.interfaces.UserSessionHome;
038: import hero.interfaces.UserSessionUtil;
039: import hero.interfaces.UserRegistration;
040: import hero.interfaces.UserRegistrationHome;
041: import hero.interfaces.UserRegistrationUtil;
042: import junit.framework.TestCase;
043: import junit.framework.TestSuite;
044: import hero.interfaces.Constants;
045: import java.util.Collection;
046: import java.util.Iterator;
047: import java.util.Timer;
048:
049: public class ModelCreationPerfTest {
050:
051: static public void main(String[] args) throws Exception {
052:
053: long startTime = System.currentTimeMillis();
054:
055: char[] password = { 't', 'o', 't', 'o' };
056: SimpleCallbackHandler handler = new SimpleCallbackHandler(
057: "admin", password);
058: LoginContext lc = new LoginContext("TestClient", handler);
059: lc.login();
060:
061: ProjectSessionHome pHome = ProjectSessionUtil.getHome();
062: try {
063:
064: System.out.println(" --> Model Creation ");
065: ProjectSession psSub = pHome.create();
066: psSub.initModel("node5Sub");
067: psSub.addNode("subNode1", Constants.Nd.AND_JOIN_NODE);
068: psSub.addNode("subNode2", Constants.Nd.AND_JOIN_NODE);
069: psSub.setNodeRole("subNode1", "admin");
070: psSub.setNodeRole("subNode2", "admin");
071: psSub.addEdge("subNode1", "subNode2");
072: String script = "import hero.interfaces.BnInstanceLocal;\n"
073: + "import hero.interfaces.BnNodeLocal;\n"
074: + "afterStart (Object b,Object n) {\n\n\n"
075: + "System.out.println(\"SPInstantiation test, SubProcess: \"+n.getName()+\" project: \"+(n.getBnProject()).getName());"
076: + "}";
077: psSub.addNodeInterHook("subNode2", "subNode2",
078: hero.interfaces.Constants.Nd.AFTERSTART,
079: Constants.Hook.BSINTERACTIVE, script);
080: psSub.addUser("admin2");
081: psSub.setNodeRole("subNode1", "admin");
082: psSub.setNodeRole("subNode2", "admin");
083:
084: ProjectSession pss = pHome.create();
085: pss.initModel("Stress");
086: pss.addNode("node1", Constants.Nd.AND_JOIN_NODE);
087: pss.addNode("node2", Constants.Nd.AND_JOIN_NODE);
088: pss.addNode("node3", Constants.Nd.AND_JOIN_NODE);
089: pss.addNode("node4", Constants.Nd.AND_JOIN_AUTOMATIC_NODE);
090: //pss.addNodeSubProcess("node5Sub","Stress");
091: pss.addNode("node5Sub", Constants.Nd.AND_JOIN_NODE);
092: pss.addEdge("node1", "node2");
093: pss.addEdge("node2", "node3");
094: pss.addEdge("node2", "node4");
095: pss.addEdge("node3", "node5Sub");
096: script = "import hero.interfaces.BnInstanceLocal;\n"
097: + "import hero.interfaces.BnNodeLocal;\n"
098: + "afterStart (Object b,Object n) {\n\n\n"
099: + "System.out.println(\"Stress test, node: \"+n.getName()+\" project: \"+(n.getBnProject()).getName());"
100: + "}";
101: pss.addNodeInterHook("node2", "node2",
102: hero.interfaces.Constants.Nd.AFTERSTART,
103: Constants.Hook.BSINTERACTIVE, script);
104: pss.addUser("admin2");
105: pss.setUserRole("admin2", "InitialRole");
106: pss.setNodeRole("node1", "admin");
107: pss.setNodeRole("node2", "admin");
108: pss.setNodeRole("node3", "admin");
109: pss.setNodeRole("node4", "admin");
110: pss.setNodeRole("node5Sub", "admin");
111: System.out.println(" --> Stress Model totally created ");
112: psSub.remove();
113: pss.remove();
114: } catch (Exception e) {
115: System.out.println(" --> " + e);
116: }
117:
118: long time = System.currentTimeMillis();
119: long tmp = (time - startTime) / 1000;
120: long h = tmp / 3600;
121: long m = (tmp - 3600 * h) / 60;
122: long s = tmp - 3600 * h - 60 * m;
123: System.out.println(" --> Stress Model system time elapsed : "
124: + h + ":" + m + ":" + s);
125: } // End Main/
126: } // End Class
|