KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > hello > test > HelloTimingStressTestCase


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.hello.test;
23
24
25 import javax.ejb.*;
26 import javax.naming.*;
27
28 import org.jboss.test.hello.interfaces.*;
29
30 import junit.framework.Test;
31 import junit.framework.TestCase;
32 import junit.framework.TestSuite;
33 import org.jboss.test.JBossTestCase;
34
35
36 /** Simple tests of the Hello stateless session bean
37  *
38  * @author Scott.Stark@jboss.org
39  * @version $Revision: 37406 $
40  */

41 public class HelloTimingStressTestCase
42    extends JBossTestCase
43 {
44    // Constants -----------------------------------------------------
45

46    // Attributes ----------------------------------------------------
47

48    // Static --------------------------------------------------------
49
static boolean deployed = false;
50    
51    // Constructors --------------------------------------------------
52
public HelloTimingStressTestCase(String JavaDoc name)
53    {
54       super(name);
55    }
56    
57    // Public --------------------------------------------------------
58

59    /**
60     * Lookup the bean, call it, remove it.
61     *
62     * @exception Exception
63     */

64    public void testHello()
65       throws Exception JavaDoc
66    {
67       HelloHome home = (HelloHome)getInitialContext().lookup(HelloHome.JNDI_NAME);
68       Hello hello = home.create();
69       getLog().debug(hello.hello("World"));
70       hello.remove();
71    }
72    
73    /**
74     * Test marshalling of custom data-holders.
75     *
76     * @exception Exception
77     */

78    public void testData()
79       throws Exception JavaDoc
80    {
81       HelloHome home = (HelloHome)getInitialContext().lookup(HelloHome.JNDI_NAME);
82       Hello hello = home.create();
83       HelloData name = new HelloData();
84       name.setName("World");
85       getLog().debug(hello.howdy(name));
86       hello.remove();
87    }
88    
89    /**
90     * This tests the speed of invocations
91     *
92     * @exception Exception
93     */

94    public void testSpeed()
95       throws Exception JavaDoc
96    {
97       long start = System.currentTimeMillis();
98       HelloHome home = (HelloHome)getInitialContext().lookup(HelloHome.JNDI_NAME);
99       Hello hello = home.create();
100       for (int i = 0 ; i < getIterationCount(); i++)
101       {
102          hello.hello("Rickard");
103       }
104       long end = System.currentTimeMillis();
105       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
106    }
107    
108    /**
109     * This tests the speed of invocations
110     *
111     * @exception Exception
112     */

113    public void testSpeed2()
114       throws Exception JavaDoc
115    {
116       long start = System.currentTimeMillis();
117       long start2 = start;
118       HelloHome home = (HelloHome)getInitialContext().lookup(HelloHome.JNDI_NAME);
119       Hello hello = home.create();
120       for (int i = 0 ; i < getIterationCount(); i++)
121       {
122          hello.helloHello(hello);
123       }
124       long end = System.currentTimeMillis();
125       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
126    }
127
128    /**
129     * This tests the speed of InitialContext lookups
130     * including getting the initial context.
131     * @exception Exception
132     */

133    public void testContextSpeed()
134       throws Exception JavaDoc
135    {
136       long start = System.currentTimeMillis();
137       
138       getLog().debug("Starting context lookup speed test");
139       for (int i = 0; i < getIterationCount(); i++)
140       {
141          HelloHome home = (HelloHome)new InitialContext().lookup(HelloHome.JNDI_NAME);
142       }
143       long end = System.currentTimeMillis();
144       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
145    }
146
147    /**
148     * This tests the speed of JNDI lookups
149     *
150     * @exception Exception
151     */

152    public void testReusedContextSpeed()
153       throws Exception JavaDoc
154    {
155       Context ctx = getInitialContext();
156       long start = System.currentTimeMillis();
157       
158       getLog().debug("Starting context lookup speed test");
159       for (int i = 0; i < getIterationCount(); i++)
160       {
161          HelloHome home = (HelloHome)ctx.lookup(HelloHome.JNDI_NAME);
162       }
163       long end = System.currentTimeMillis();
164       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
165    }
166    
167    
168    public static Test suite() throws Exception JavaDoc
169    {
170       return getDeploySetup(HelloTimingStressTestCase.class, "hello.jar");
171    }
172
173 }
174
Popular Tags