KickJava   Java API By Example, From Geeks To Geeks.

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


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: ThreadLanceurPerfTest.java,v 1.1 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
48 import java.sql.Time JavaDoc;
49 import java.util.Collection JavaDoc;
50 import java.util.Iterator JavaDoc;
51
52 public class ThreadLanceurPerfTest
53 {
54     public static int injectes = 0 ;
55     public static int userCreesEnCours = 0;
56     
57        public static void main(String JavaDoc[] args) throws Exception JavaDoc
58        {
59
60     int argNb = 8;
61     int userNb = 0;
62     String JavaDoc uNb = "0";
63     int instNb = 1;
64     int nbUsersParPallier = userNb;
65     int tpsPallier = 10; // secondes
66
int tpsEntreUsers = 1 ;
67     int tpsEntreInjInst = 1 ;
68     int tpsEntreInst = 1 ;
69     int tpsRunDbtInst = 3 ;
70     
71     if (args.length != argNb)
72     {
73         System.out.println("Number of arguments needed : "+argNb);
74         
75         System.out.println("Args : -DuserId -DnbInst -Dnbuserspallier= -Dtpspallier= -DtpsEntreUsers= -DtpsEntreInjInst= -DtpsEtreInst -DtpsRunDbtInst");
76     }
77     else
78     {
79
80       try
81       {
82        uNb = new String JavaDoc(args[0]);
83        userNb = Integer.valueOf(uNb).intValue() ;
84       }
85       catch(Exception JavaDoc e){System.out.println(" --> " + e);}
86
87       try
88       {
89       String JavaDoc instanceNum = new String JavaDoc(args[1]);
90       instNb = Integer.valueOf(instanceNum).intValue() ;
91       }
92       catch(Exception JavaDoc e){System.out.println(" --> " + e);}
93
94       try
95       {
96       String JavaDoc usersParPallier = new String JavaDoc(args[2]);
97       nbUsersParPallier = Integer.valueOf(usersParPallier).intValue() ;
98       }
99       catch(Exception JavaDoc e){System.out.println(" --> " + e);}
100       
101       try
102       {
103       String JavaDoc tpsSecParPallier = new String JavaDoc(args[3]);
104       tpsPallier = Integer.valueOf(tpsSecParPallier).intValue() ;
105       }
106       catch(Exception JavaDoc e){System.out.println(" --> " + e);}
107       
108       try
109       {
110         String JavaDoc tps_entre_users = new String JavaDoc(args[4]);
111         tpsEntreUsers = Integer.valueOf(tps_entre_users).intValue() ;
112       }
113       catch(Exception JavaDoc e){System.out.println(" --> " + e);}
114       
115       try
116       {
117         String JavaDoc tps_entre_inj_inst = new String JavaDoc(args[5]);
118         tpsEntreInjInst = Integer.valueOf(tps_entre_inj_inst).intValue() ;
119       }
120       catch(Exception JavaDoc e){System.out.println(" --> " + e);}
121       
122       try
123       {
124         String JavaDoc tps_entre_inst = new String JavaDoc(args[6]);
125         tpsEntreInst = Integer.valueOf(tps_entre_inst).intValue() ;
126       }
127       catch(Exception JavaDoc e){System.out.println(" --> " + e);}
128       
129       try
130       {
131         String JavaDoc tps_run_dbt_inst = new String JavaDoc(args[7]);
132         tpsRunDbtInst = Integer.valueOf(tps_run_dbt_inst).intValue() ;
133       }
134       catch(Exception JavaDoc e){System.out.println(" --> " + e);}
135     }
136     
137     ////////// TEST ////////////////////////////////////////////////
138

139       UserRegistrationHome urHome = UserRegistrationUtil.getHome();
140       UserRegistration userReg=urHome.create();
141       
142       
143       int userRestant = userNb;
144       int userInj = 0;
145       int maxInj = 0;
146       
147       while(userRestant > 0)
148       {
149         try
150         {
151            maxInj = Math.min( nbUsersParPallier , userRestant ) ;
152            
153            for (userInj=injectes ; userInj < injectes+maxInj ; userInj++)
154            {
155             userCreesEnCours +=1;
156             // user creation
157
try
158                 {
159                     userReg.userCreate("user"+userInj,"user"+userInj,"Anne.Geron@bull.net");
160                     ThreadInstancesPerfTest.userCrees = userCreesEnCours ;
161                     Thread.sleep(tpsEntreUsers * 1000);
162                     // System.out.println("---> Creation user "+ userInj) ;
163
}
164                 catch (Exception JavaDoc e)
165                 {
166                     System.out.println(" --> " + e);
167                 }
168           }
169        
170           Thread.sleep(tpsEntreInjInst * 1000);
171           
172           for (int userInst=injectes ; userInst < injectes+maxInj ; userInst++)
173           {
174                 //System.out.println("Main : User : " + userInst + " - Instance : "+instNb);
175
try
176                 {
177                     for(int i=0;i<instNb;i++)
178                     {
179                         // Creation du thread
180

181                         ThreadInstancesPerfTest thisInst = new ThreadInstancesPerfTest(userInst,i,tpsRunDbtInst);
182                         // Lancement du thread
183
thisInst.start();
184                         Thread.sleep(tpsEntreInst * 1000);
185                     }
186                 }
187                 catch (Exception JavaDoc e)
188                 {
189                     System.out.println(" --> " + e);
190                 }
191           }
192           
193         }
194         catch (Exception JavaDoc se)
195         {
196             System.out.println(" // " + se);
197         }
198         finally
199         {
200             System.out.println(" ///////// ATTENTE ( " + tpsPallier +" sec) " );
201             Thread.sleep(tpsPallier * 1000);
202             System.out.println(" ///////// NOUVELLE INJECTION ");
203             injectes += maxInj ;
204             userRestant = userNb - injectes;
205         }
206           
207       } // fin boucle while
208

209     }
210        
211     private void mode1()
212     {
213         
214     }
215     
216     private void mode2()
217     {
218         
219     }
220     
221     private void regUser()
222     {
223         
224     }
225     
226     private void creaInst()
227     {
228         
229     }
230 }
231
232
233
Popular Tags