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: ThreadInstancesPerfTest.java,v 1.1 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.BnProject;
034: import hero.interfaces.BnProjectHome;
035: import hero.interfaces.BnProjectPK;
036: import hero.interfaces.BnProjectValue;
037: import hero.interfaces.ProjectSession;
038: import hero.interfaces.ProjectSessionHome;
039: import hero.interfaces.ProjectSessionUtil;
040: import hero.interfaces.UserSession;
041: import hero.interfaces.UserSessionHome;
042: import hero.interfaces.UserSessionUtil;
043: import hero.interfaces.UserRegistration;
044: import hero.interfaces.UserRegistrationHome;
045: import hero.interfaces.UserRegistrationUtil;
046: import junit.framework.TestCase;
047: import junit.framework.TestSuite;
048: import hero.interfaces.Constants;
049: import hero.util.BonitaServiceException;
050:
051: import java.util.Collection;
052: import java.util.Iterator;
053:
054: public class ThreadInstancesPerfTest extends Thread {
055:
056: private int userNb = 0;
057: private String uNb = "0";
058: private int instNb = 10;
059: private int tpsRunDbtInst = 3;
060:
061: SimpleCallbackHandler handler = null;
062: LoginContext lc = null;
063: ProjectSessionHome pHome;
064: static int instRunEnCours = 0;
065: static int instTotales = 0;
066: static int userCrees = 0;
067: String uName = null;
068:
069: public ThreadInstancesPerfTest(int user, int inst, int tpsdbtinst) {
070: this .userNb = user;
071: this .uNb = String.valueOf(user);
072: this .instNb = inst;
073: this .tpsRunDbtInst = tpsdbtinst;
074:
075: uName = "user" + uNb;
076: char[] password = uName.toCharArray();
077: try {
078: handler = new SimpleCallbackHandler(uName, password);
079: lc = new LoginContext("TestClient", handler);
080: lc.login();
081: pHome = ProjectSessionUtil.getHome();
082: } catch (Exception e) {
083: System.out.println("pffffffff....meme pas en reve " + e);
084: }
085: }
086:
087: public void run() {
088:
089: //System.out.println("Starting really runInstance (using " + uNb +", "+instNb + ")...");
090: String result = "";
091: long startTime = 0;
092: int instRunDebut = instRunEnCours;
093: int userCreesDbt = userCrees;
094:
095: try {
096:
097: int i = 0;
098:
099: Thread.sleep(tpsRunDbtInst * 1000);
100: startTime = System.currentTimeMillis();
101: ProjectSession ps = pHome.create();
102: instRunEnCours += 1;
103: instTotales += 1;
104: //for (i=0;i<instNb;i++) {
105: // threader CA :::::::: + timer par instance + stats instances en cours
106: ps.instantiateProject("Stress");
107: //System.out.println(" --> User: " + uName +" -- Instanciate Stress Model");
108:
109: //}
110:
111: ps.remove();
112: /*
113: UserSessionHome uHome = UserSessionUtil.getHome();
114: UserSession us = uHome.create();
115: Collection instances = us.getInstancesListNames();
116: Iterator index = instances.iterator();
117: UserSession usUser = uHome.create();
118: while (index.hasNext())
119: {
120: String name = (String)index.next();
121: Collection task = usUser.getToDoList(name);
122: Iterator it = task.iterator();
123: while (it.hasNext())
124: {
125: String activity = (String)it.next();
126: usUser.startActivity(name,activity);
127: System.out.println(" --> User: " + uName +" Instance: "+name+" -- Start Act: " + activity);
128: if (activity.matches(".*_instance.*"))
129: executeSubProcess(activity);
130:
131: Thread.sleep(100);
132: usUser.terminateActivity(name,activity);
133: System.out.println(" --> User: " + uName +" -- Stop Act: " + activity);
134: task = usUser.getToDoList(name);
135: it = task.iterator();
136: }
137: }*/
138: } catch (Exception e) {
139: System.out.println(" --> " + e);
140: }
141:
142: long time = System.currentTimeMillis();
143: long tmp = time - startTime; // tps en millisecondes
144: long h = tmp / 3600000;
145: long m = (tmp - 3600000 * h) / 60000;
146: long s = (tmp - 3600000 * h - 60000 * m) / 1000;
147: long millis = tmp - 3600000 * h - 60000 * m - 1000 * s;
148: System.out.println(" --> " + uName + " / ( " + userCreesDbt
149: + " -> " + userCrees + " ) " + " Stressed Model ( "
150: + instRunDebut + " -> " + instRunEnCours + " / "
151: + instTotales + " ) : system time elapsed : " + h + ":"
152: + m + ":" + s + ":" + millis);
153: instRunEnCours -= 1;
154:
155: }
156:
157: public static void executeSubProcess(String subProcess)
158: throws Exception {
159: UserSessionHome uHome = UserSessionUtil.getHome();
160: UserSession us = uHome.create();
161: us.startActivity(subProcess, "subNode1");
162: us.terminateActivity(subProcess, "subNode1");
163: us.startActivity(subProcess, "subNode2");
164: us.terminateActivity(subProcess, "subNode2");
165: }
166: }
|