KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Autotest


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2004 France Telecom R&D
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * CLIF $Name: $
20 *
21 * Contact: clif@objectweb.org
22 */

23
24
25 import org.objectweb.clif.scenario.util.multithread.MTScenario;
26 import org.objectweb.clif.scenario.util.multithread.MTScenarioSession;
27 import org.objectweb.clif.storage.api.ActionEvent;
28 import org.objectweb.clif.supervisor.api.ClifException;
29
30 import java.util.StringTokenizer JavaDoc;
31
32
33 /**
34  * Example of MTScenario utilization, with actions consisting in simple calls to sleep().
35  *
36  * @author Bruno Dillenseger
37  */

38 public class Autotest extends MTScenario
39 {
40     long arg_sleep_ms = 0;
41
42
43     /**
44      * @param sessionId the session identifier
45      * @param arg should contain a single integer parameter giving the sleep duration of each action
46      * @return a new Autotest session
47      */

48     public MTScenarioSession newSession(int sessionId, String JavaDoc arg)
49         throws ClifException
50     {
51         try
52         {
53             StringTokenizer JavaDoc parser = new StringTokenizer JavaDoc(arg);
54             arg_sleep_ms = Integer.parseInt(parser.nextToken());
55         }
56         catch (Exception JavaDoc ex)
57         {
58             throw new ClifException(
59                 "Autotest requires 4 arguments:\n\t<number of concurrent threads>\n\t<test duration in seconds>\n\t<ramp-up duration in seconds>\n\t<iteration sleep duration in ms>",
60                 ex);
61         }
62         return new Session();
63     }
64
65
66     class Session implements MTScenarioSession
67     {
68         public ActionEvent action(ActionEvent report)
69         {
70             try
71             {
72                 Thread.sleep(arg_sleep_ms);
73             }
74             catch (InterruptedException JavaDoc ex)
75             {
76                 ex.printStackTrace(System.err);
77             }
78             report.duration = (int) (System.currentTimeMillis() - report.getDate());
79             report.type = "sleep action";
80             return report;
81         }
82     }
83 }
84
Popular Tags