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: InstancesPerfTest.java,v 1.1 2005/01/06 10:58:37 anneg 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:
048: public class InstancesPerfTest {
049:
050: static public void main(String[] args) throws Exception {
051:
052: int argNb = 2;
053: if (args.length != argNb) {
054: System.out.println("Number of arguments needed : " + argNb);
055: System.out.println("Args : userId nbInstances");
056: } else {
057:
058: String uNb = "0";
059: int instNb = 10;
060:
061: long startTime = System.currentTimeMillis();
062:
063: try {
064: uNb = new String(args[0]);
065: String instanceNum = new String(args[1]);
066: System.out.println("Parametres : uNb: " + uNb
067: + " - instanceNum: " + instanceNum);
068: instNb = Integer.valueOf(instanceNum).intValue();
069: } catch (Exception e) {
070: System.out.println(" --> " + e);
071: }
072:
073: String uName = "user" + uNb;
074: char[] password = uName.toCharArray();
075: SimpleCallbackHandler handler = new SimpleCallbackHandler(
076: uName, password);
077: LoginContext lc = new LoginContext("TestClient", handler);
078: lc.login();
079:
080: ProjectSessionHome pHome = ProjectSessionUtil.getHome();
081: int i = 0;
082: for (i = 0; i < instNb; i++) {
083: ProjectSession ps = pHome.create();
084: ps.instantiateProject("Stress");
085: System.out.println(" --> User: " + uName
086: + " -- Instanciate Stress Model");
087: Thread.sleep(100);
088: ps.remove();
089: }
090:
091: UserSessionHome uHome = UserSessionUtil.getHome();
092: UserSession us = uHome.create();
093: Collection instances = us.getInstancesListNames();
094: Iterator index = instances.iterator();
095: UserSession usUser = uHome.create();
096: while (index.hasNext()) {
097: String name = (String) index.next();
098: Collection task = usUser.getToDoList(name);
099: Iterator it = task.iterator();
100: while (it.hasNext()) {
101: String activity = (String) it.next();
102: usUser.startActivity(name, activity);
103: System.out.println(" --> User: " + uName
104: + " Instance: " + name + " -- Start Act: "
105: + activity);
106: if (activity.matches(".*_instance.*"))
107: executeSubProcess(activity);
108:
109: Thread.sleep(100);
110: usUser.terminateActivity(name, activity);
111: System.out.println(" --> User: " + uName
112: + " -- Stop Act: " + activity);
113: task = usUser.getToDoList(name);
114: it = task.iterator();
115: }
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
124: .println(" --> Stress Model system time elapsed : "
125: + h + ":" + m + ":" + s);
126: }
127:
128: }
129:
130: public static void executeSubProcess(String subProcess)
131: throws Exception {
132: UserSessionHome uHome = UserSessionUtil.getHome();
133: UserSession us = uHome.create();
134: us.startActivity(subProcess, "subNode1");
135: us.terminateActivity(subProcess, "subNode1");
136: us.startActivity(subProcess, "subNode2");
137: us.terminateActivity(subProcess, "subNode2");
138: }
139:
140: }
|