KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.naming.Context JavaDoc;
25 import javax.naming.InitialContext JavaDoc;
26
27 import junit.framework.Test;
28
29 import org.jboss.test.JBossTestCase;
30 import org.jboss.test.hello.interfaces.Hello;
31 import org.jboss.test.hello.interfaces.HelloData;
32 import org.jboss.test.hello.interfaces.HelloHome;
33 import org.jboss.test.hello.interfaces.HelloLog;
34 import org.jboss.test.hello.interfaces.HelloLogHome;
35
36 /** Simple tests of the Hello stateless session bean using http as the transport
37  *
38  * @author Scott.Stark@jboss.org
39  * @version $Revision: 37406 $
40  */

41 public class HelloHttpStressTestCase
42    extends JBossTestCase
43 {
44    // Constants -----------------------------------------------------
45
static final String JavaDoc JNDI_NAME = "helloworld/HelloHTTP";
46    // Attributes ----------------------------------------------------
47

48    // Static --------------------------------------------------------
49
static boolean deployed = false;
50
51    // Constructors --------------------------------------------------
52
public HelloHttpStressTestCase(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       InitialContext JavaDoc ctx = getInitialContext();
68       HelloHome home = (HelloHome) ctx.lookup("helloworld/HelloHTTP");
69       Hello hello = home.create();
70       String JavaDoc reply = hello.hello("World");
71       getLog().debug(reply);
72       hello.remove();
73    }
74
75    /** Execute the loggedHello call to have the session create an entity and
76     * then find the entity and query the loggedHello times.
77     *
78     * @throws Exception
79     */

80    public void testLoggedHello()
81       throws Exception JavaDoc
82    {
83       InitialContext JavaDoc ctx = getInitialContext();
84       HelloHome home = (HelloHome) ctx.lookup("helloworld/HelloHTTP");
85       Hello hello = home.create();
86       String JavaDoc reply = hello.loggedHello("World");
87       getLog().debug(reply);
88       hello.remove();
89
90       // Find
91
HelloLogHome logHome = (HelloLogHome) ctx.lookup("helloworld/HelloLogHTTP");
92       HelloLog log = logHome.findByPrimaryKey("World");
93       long start = log.getStartTime();
94       long end = log.getEndTime();
95       getLog().debug("HelloLog times: "+start+","+end);
96       long elapsed = log.getElapsedTime();
97       getLog().debug("HelloLog elapsed: "+elapsed);
98    }
99
100    /**
101     * Test marshalling of custom data-holders.
102     *
103     * @exception Exception
104     */

105    public void testData()
106       throws Exception JavaDoc
107    {
108       HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME);
109       Hello hello = home.create();
110       HelloData name = new HelloData();
111       name.setName("World");
112       getLog().debug(hello.howdy(name));
113       hello.remove();
114    }
115
116    /**
117     * This tests the speed of invocations
118     *
119     * @exception Exception
120     */

121    public void testSpeed()
122       throws Exception JavaDoc
123    {
124       long start = System.currentTimeMillis();
125       HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME);
126       Hello hello = home.create();
127       int count = getIterationCount();
128       for (int i = 0 ; i < count; i++)
129       {
130          hello.hello("Argument#"+i);
131       }
132       long end = System.currentTimeMillis();
133       getLog().debug("Avg. for "+count+" calls (ms):"+((end-start)/count));
134    }
135
136    /**
137     * This tests the speed of invocations
138     *
139     * @exception Exception
140     */

141    public void testSpeed2()
142       throws Exception JavaDoc
143    {
144       long start = System.currentTimeMillis();
145       HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME);
146       Hello hello = home.create();
147       int count = getIterationCount();
148       for (int i = 0 ; i < count; i++)
149       {
150          hello.helloHello(hello);
151       }
152       long end = System.currentTimeMillis();
153       getLog().debug("Avg. for "+count+" calls (ms):"+((end-start)/count));
154    }
155
156    /**
157     * This tests the speed of InitialContext lookups
158     * including getting the initial context.
159     * @exception Exception
160     */

161    public void testContextSpeed()
162       throws Exception JavaDoc
163    {
164       long start = System.currentTimeMillis();
165
166       getLog().debug("Starting context lookup speed test");
167       int count = getIterationCount();
168       for (int i = 0 ; i < count; i++)
169       {
170          HelloHome home = (HelloHome) new InitialContext JavaDoc().lookup(JNDI_NAME);
171          home.hashCode();
172       }
173       long end = System.currentTimeMillis();
174       getLog().debug("Avg. for "+count+" lookups (ms):"+((end-start)/count));
175    }
176
177    /**
178     * This tests the speed of JNDI lookups
179     *
180     * @exception Exception
181     */

182    public void testReusedContextSpeed()
183       throws Exception JavaDoc
184    {
185       Context JavaDoc ctx = getInitialContext();
186       long start = System.currentTimeMillis();
187
188       getLog().debug("Starting context lookup speed test");
189       int count = getIterationCount();
190       for (int i = 0 ; i < count; i++)
191       {
192          HelloHome home = (HelloHome) ctx.lookup(JNDI_NAME);
193          home.hashCode();
194       }
195       long end = System.currentTimeMillis();
196       getLog().debug("Avg. for "+count+" lookups (ms):"+((end-start)/count));
197    }
198
199
200    public static Test suite() throws Exception JavaDoc
201    {
202       return getDeploySetup(HelloHttpStressTestCase.class, "hello.jar");
203    }
204
205 }
206
Popular Tags