KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > perf > test > PerfStressTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.perf.test;
23
24 import java.io.IOException JavaDoc;
25 import java.rmi.RemoteException JavaDoc;
26 import javax.ejb.CreateException JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28 import javax.naming.NamingException JavaDoc;
29 import javax.rmi.PortableRemoteObject JavaDoc;
30
31 import junit.framework.Test;
32 import junit.framework.TestCase;
33 import junit.framework.TestSuite;
34
35 import org.jboss.test.perf.interfaces.Entity;
36 import org.jboss.test.perf.interfaces.EntityPK;
37 import org.jboss.test.perf.interfaces.Entity2PK;
38 import org.jboss.test.perf.interfaces.EntityHome;
39 import org.jboss.test.perf.interfaces.Entity2Home;
40 import org.jboss.test.perf.interfaces.Probe;
41 import org.jboss.test.perf.interfaces.ProbeHome;
42 import org.jboss.test.perf.interfaces.Session;
43 import org.jboss.test.perf.interfaces.SessionHome;
44 import org.jboss.test.perf.interfaces.TxSession;
45 import org.jboss.test.perf.interfaces.TxSessionHome;
46
47 import org.jboss.test.JBossTestCase;
48
49 /** Test of EJB call invocation overhead.
50  
51  @author Scott.Stark@jboss.org
52  @version $Revision: 37406 $
53  */

54 public class PerfStressTestCase extends JBossTestCase
55 {
56    protected String JavaDoc CLIENT_SESSION = "perf.ClientSession";
57    protected String JavaDoc CLIENT_ENTITY = "local/perfClientEntity";
58    protected String JavaDoc PROBE = "perf.Probe";
59    protected String JavaDoc PROBE_CMT = "perf.ProbeCMT";
60    protected String JavaDoc TX_SESSION = "perf.TxSession";
61    protected String JavaDoc ENTITY = "perfEntity";
62    protected String JavaDoc ENTITY2 = "perfEntity2";
63
64    int iterationCount;
65    int beanCount;
66
67    public PerfStressTestCase(String JavaDoc name)
68    {
69       super(name);
70       iterationCount = getIterationCount();
71       beanCount = getBeanCount();
72    }
73    
74    public void testClientSession() throws Exception JavaDoc
75    {
76       getLog().debug("+++ testClientSession()");
77       Object JavaDoc obj = getInitialContext().lookup(CLIENT_SESSION);
78       obj = PortableRemoteObject.narrow(obj, SessionHome.class);
79       SessionHome home = (SessionHome) obj;
80       getLog().debug("Found SessionHome @ jndiName=ClientSession");
81       Session bean = home.create(CLIENT_ENTITY);
82       getLog().debug("Created ClientSession");
83       
84       try
85       {
86          bean.create(0, getBeanCount());
87       }
88       catch(javax.ejb.CreateException JavaDoc e)
89       {
90          getLog().debug("Exception while creating entities: ", e);
91       }
92       
93       long start = System.currentTimeMillis();
94       bean.read(0);
95       bean.read(0, getBeanCount());
96       bean.write(0);
97       bean.write(0, getBeanCount());
98       bean.remove(0, getBeanCount());
99       long end = System.currentTimeMillis();
100       long elapsed = end - start;
101       getLog().debug("Elapsed time = "+(elapsed / iterationCount));
102    }
103
104    public void testTimings() throws Exception JavaDoc
105    {
106       getLog().debug("+++ testTimings()");
107       Object JavaDoc obj = getInitialContext().lookup(PROBE);
108       obj = PortableRemoteObject.narrow(obj, ProbeHome.class);
109       ProbeHome home = (ProbeHome) obj;
110       getLog().debug("Found ProbeHome @ jndiName=Probe");
111       Probe bean = home.create();
112       getLog().debug("Created Probe");
113       warmup(bean);
114       noop(bean);
115       ping(bean);
116       echo(bean);
117    }
118
119    public void testTimingsCMT() throws Exception JavaDoc
120    {
121       getLog().debug("+++ testTimingsCMT()");
122       Object JavaDoc obj = getInitialContext().lookup(PROBE_CMT);
123       obj = PortableRemoteObject.narrow(obj, ProbeHome.class);
124       ProbeHome home = (ProbeHome) obj;
125       getLog().debug("Found ProbeHome @ jndiName=ProbeCMT");
126       Probe bean = home.create();
127       getLog().debug("Created ProbeCMT");
128       warmup(bean);
129       noop(bean);
130       ping(bean);
131       echo(bean);
132    }
133
134    public void testTxTimings() throws Exception JavaDoc
135    {
136       getLog().debug("+++ testTxTimings()");
137       Object JavaDoc obj = getInitialContext().lookup(TX_SESSION);
138       obj = PortableRemoteObject.narrow(obj, TxSessionHome.class);
139       TxSessionHome home = (TxSessionHome) obj;
140       getLog().debug("Found TxSession @ jndiName=TxSession");
141       TxSession bean = home.create();
142       getLog().debug("Created TxSession");
143       txRequired(bean);
144       txRequiresNew(bean);
145       txSupports(bean);
146       txNotSupported(bean);
147       requiredToSupports(bean);
148       requiredToMandatory(bean);
149       requiredToRequiresNew(bean);
150    }
151    public void testFindByPrimaryKey() throws Exception JavaDoc
152    {
153       getLog().debug("+++ testFindByPrimaryKey()");
154       Object JavaDoc obj = getInitialContext().lookup(ENTITY);
155       obj = PortableRemoteObject.narrow(obj, EntityHome.class);
156       EntityHome home = (EntityHome) obj;
157       getLog().debug("Found EntityHome @ jndiName=Entity");
158       EntityPK key = new EntityPK(0);
159       Entity bean = null;
160
161       getLog().debug("Running with " + iterationCount + " instances...");
162       findByPrimaryKey(key, home);
163    }
164    public void testFindByPrimaryKey2() throws Exception JavaDoc
165    {
166       getLog().debug("+++ testFindByPrimaryKey2()");
167       Object JavaDoc obj = getInitialContext().lookup(ENTITY2);
168       obj = PortableRemoteObject.narrow(obj, Entity2Home.class);
169       Entity2Home home = (Entity2Home) obj;
170       getLog().debug("Found EntityHome @ jndiName=Entity");
171       Entity2PK key = new Entity2PK(0, "String0", new Double JavaDoc(0));
172       Entity bean = null;
173
174       getLog().debug("Running with " + iterationCount + " instances...");
175       findByPrimaryKey(key, home);
176    }
177
178    private void warmup(Probe bean) throws Exception JavaDoc
179    {
180       bean.noop();
181       bean.ping("Ping");
182       bean.echo("Echo");
183    }
184
185    private void noop(Probe bean) throws Exception JavaDoc
186    {
187       getLog().debug("Starting "+iterationCount+" noop() invocations");
188       long start = System.currentTimeMillis();
189       for(int n = 0; n < iterationCount; n ++)
190          bean.noop();
191       long end = System.currentTimeMillis();
192       long elapsed = end - start;
193       getLog().debug(iterationCount+" noop() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/noop");
194    }
195    private void ping(Probe bean) throws Exception JavaDoc
196    {
197       getLog().debug("Starting "+iterationCount+" ping(PING) invocations");
198       long start = System.currentTimeMillis();
199       for(int n = 0; n < iterationCount; n ++)
200          bean.ping("PING");
201       long end = System.currentTimeMillis();
202       long elapsed = end - start;
203       getLog().debug(iterationCount+" ping() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/noop");
204    }
205    private void echo(Probe bean) throws Exception JavaDoc
206    {
207       getLog().debug("Starting "+iterationCount+" echo(ECHO) invocations");
208       long start = System.currentTimeMillis();
209       for(int n = 0; n < iterationCount; n ++)
210       {
211          String JavaDoc echo = bean.echo("ECHO");
212       }
213       long end = System.currentTimeMillis();
214       long elapsed = end - start;
215       getLog().debug(iterationCount+" echo() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/noop");
216    }
217    private void txRequired(TxSession bean) throws Exception JavaDoc
218    {
219       getLog().debug("Starting "+iterationCount+" txRequired() invocations");
220       long start = System.currentTimeMillis();
221       for(int n = 0; n < iterationCount; n ++)
222       {
223          String JavaDoc echo = bean.txRequired();
224       }
225       long end = System.currentTimeMillis();
226       long elapsed = end - start;
227       getLog().debug(iterationCount+" txRequired() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/txRequired");
228    }
229    private void txRequiresNew(TxSession bean) throws Exception JavaDoc
230    {
231       getLog().debug("Starting "+iterationCount+" txRequired() invocations");
232       long start = System.currentTimeMillis();
233       for(int n = 0; n < iterationCount; n ++)
234       {
235          String JavaDoc echo = bean.txRequiresNew();
236       }
237       long end = System.currentTimeMillis();
238       long elapsed = end - start;
239       getLog().debug(iterationCount+" txRequiresNew() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/txRequiresNew");
240    }
241    private void txSupports(TxSession bean) throws Exception JavaDoc
242    {
243       getLog().debug("Starting "+iterationCount+" txSupports() invocations");
244       long start = System.currentTimeMillis();
245       for(int n = 0; n < iterationCount; n ++)
246       {
247          String JavaDoc echo = bean.txSupports();
248       }
249       long end = System.currentTimeMillis();
250       long elapsed = end - start;
251       getLog().debug(iterationCount+" txSupports() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/txSupports");
252    }
253    private void txNotSupported(TxSession bean) throws Exception JavaDoc
254    {
255       getLog().debug("Starting "+iterationCount+" txNotSupported() invocations");
256       long start = System.currentTimeMillis();
257       for(int n = 0; n < iterationCount; n ++)
258       {
259          String JavaDoc echo = bean.txNotSupported();
260       }
261       long end = System.currentTimeMillis();
262       long elapsed = end - start;
263       getLog().debug(iterationCount+" txNotSupported() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/txNotSupported");
264    }
265    private void requiredToSupports(TxSession bean) throws Exception JavaDoc
266    {
267       getLog().debug("Starting "+iterationCount+" requiredToSupports() invocations");
268       long start = System.currentTimeMillis();
269       for(int n = 0; n < iterationCount; n ++)
270       {
271          String JavaDoc echo = bean.requiredToSupports();
272       }
273       long end = System.currentTimeMillis();
274       long elapsed = end - start;
275       getLog().debug(iterationCount+" requiredToSupports() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/requiredToSupports");
276    }
277    private void requiredToMandatory(TxSession bean) throws Exception JavaDoc
278    {
279       getLog().debug("Starting "+iterationCount+" requiredToMandatory() invocations");
280       long start = System.currentTimeMillis();
281       for(int n = 0; n < iterationCount; n ++)
282       {
283          String JavaDoc echo = bean.requiredToMandatory();
284       }
285       long end = System.currentTimeMillis();
286       long elapsed = end - start;
287       getLog().debug(iterationCount+" requiredToMandatory() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/requiredToMandatory");
288    }
289    private void requiredToRequiresNew(TxSession bean) throws Exception JavaDoc
290    {
291       getLog().debug("Starting "+iterationCount+" requiredToRequiresNew() invocations");
292       long start = System.currentTimeMillis();
293       for(int n = 0; n < iterationCount; n ++)
294       {
295          String JavaDoc echo = bean.requiredToRequiresNew();
296       }
297       long end = System.currentTimeMillis();
298       long elapsed = end - start;
299       getLog().debug(iterationCount+" requiredToRequiresNew() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/requiredToRequiresNew");
300    }
301
302    private void findByPrimaryKey(EntityPK key, EntityHome home) throws Exception JavaDoc
303    {
304       getLog().debug("Starting "+iterationCount+" findByPrimaryKey(key="+key+") invocations");
305       long start = System.currentTimeMillis();
306       for(int n = 0; n < iterationCount; n ++)
307       {
308          Entity bean = home.findByPrimaryKey(key);
309       }
310       long end = System.currentTimeMillis();
311       long elapsed = end - start;
312       getLog().debug(iterationCount+" findByPrimaryKey() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/findByPrimaryKey");
313    }
314    private void findByPrimaryKey(Entity2PK key, Entity2Home home) throws Exception JavaDoc
315    {
316       getLog().debug("Starting "+iterationCount+" findByPrimaryKey(key="+key+") invocations");
317       long start = System.currentTimeMillis();
318       for(int n = 0; n < iterationCount; n ++)
319       {
320          Entity bean = home.findByPrimaryKey(key);
321       }
322       long end = System.currentTimeMillis();
323       long elapsed = end - start;
324       getLog().debug(iterationCount+" findByPrimaryKey() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/findByPrimaryKey");
325    }
326
327    public static Test suite() throws Exception JavaDoc
328    {
329       TestSuite suite = new TestSuite();
330       suite.addTest(new TestSuite(PerfStressTestCase.class));
331
332       // Create an initializer for the test suite
333
Setup wrapper = new Setup(suite, "perf.jar", false);
334       return wrapper;
335    }
336
337 }
338
Popular Tags