KickJava   Java API By Example, From Geeks To Geeks.

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


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: InstancesPerfTest.java,v 1.1 2005/01/06 10:58:37 anneg 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
50 public class InstancesPerfTest {
51
52
53        static public void main(String JavaDoc[] args) throws Exception JavaDoc{
54
55     int argNb = 2;
56     if (args.length != argNb) {
57         System.out.println("Number of arguments needed : "+argNb);
58         System.out.println("Args : userId nbInstances");
59     } else {
60     
61     String JavaDoc uNb="0" ;
62     int instNb = 10 ;
63
64     long startTime = System.currentTimeMillis();
65
66     try {
67     uNb = new String JavaDoc(args[0]);
68     String JavaDoc instanceNum = new String JavaDoc(args[1]);
69     System.out.println("Parametres : uNb: "+ uNb+" - instanceNum: "+instanceNum) ;
70     instNb = Integer.valueOf(instanceNum).intValue() ;
71     }catch(Exception JavaDoc e){System.out.println(" --> " + e);}
72
73     String JavaDoc uName= "user"+uNb;
74     char[] password=uName.toCharArray();
75     SimpleCallbackHandler handler = new SimpleCallbackHandler(uName,password);
76     LoginContext JavaDoc lc = new LoginContext JavaDoc("TestClient", handler);
77     lc.login();
78
79     ProjectSessionHome pHome = ProjectSessionUtil.getHome();
80     int i=0;
81     for (i=0;i<instNb;i++) {
82         ProjectSession ps = pHome.create();
83         ps.instantiateProject("Stress");
84         System.out.println(" --> User: " + uName +" -- Instanciate Stress Model");
85         Thread.sleep(100);
86         ps.remove();
87     }
88         
89     UserSessionHome uHome = UserSessionUtil.getHome();
90     UserSession us = uHome.create();
91     Collection JavaDoc instances = us.getInstancesListNames();
92     Iterator JavaDoc index = instances.iterator();
93     UserSession usUser = uHome.create();
94     while (index.hasNext())
95     {
96         String JavaDoc name = (String JavaDoc)index.next();
97         Collection JavaDoc task = usUser.getToDoList(name);
98         Iterator JavaDoc it = task.iterator();
99         while (it.hasNext())
100         {
101           String JavaDoc activity = (String JavaDoc)it.next();
102           usUser.startActivity(name,activity);
103           System.out.println(" --> User: " + uName +" Instance: "+name+" -- Start Act: " + activity);
104           if (activity.matches(".*_instance.*"))
105              executeSubProcess(activity);
106
107           Thread.sleep(100);
108           usUser.terminateActivity(name,activity);
109           System.out.println(" --> User: " + uName +" -- Stop Act: " + activity);
110           task = usUser.getToDoList(name);
111           it = task.iterator();
112         }
113     }
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      }
122      
123    }
124
125    public static void executeSubProcess(String JavaDoc subProcess) throws Exception JavaDoc{
126      UserSessionHome uHome = UserSessionUtil.getHome();
127      UserSession us = uHome.create();
128      us.startActivity(subProcess,"subNode1");
129      us.terminateActivity(subProcess,"subNode1");
130      us.startActivity(subProcess,"subNode2");
131      us.terminateActivity(subProcess,"subNode2");
132    }
133    
134 }
135
Popular Tags