KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > helloiiop > 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.helloiiop.test;
23
24
25 import javax.naming.Context JavaDoc;
26 import javax.rmi.PortableRemoteObject JavaDoc;
27
28 import junit.framework.Test;
29 import org.jboss.test.JBossIIOPTestCase;
30 import org.jboss.test.helloiiop.interfaces.Hello;
31 import org.jboss.test.helloiiop.interfaces.HelloData;
32 import org.jboss.test.helloiiop.interfaces.HelloHome;
33
34
35 /** Simple tests of the Hello stateless session bean
36  *
37  * @author Scott.Stark@jboss.org
38  * @version $Revision: 37406 $
39  */

40 public class HelloTimingStressTestCase
41    extends JBossIIOPTestCase
42 {
43    // Constants -----------------------------------------------------
44

45    // Attributes ----------------------------------------------------
46

47    // Static --------------------------------------------------------
48

49    // Constructors --------------------------------------------------
50
public HelloTimingStressTestCase(String JavaDoc name)
51    {
52       super(name);
53    }
54
55
56    // Public --------------------------------------------------------
57

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

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

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

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

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

140    public void testContextSpeed()
141       throws Exception JavaDoc
142    {
143       long start = System.currentTimeMillis();
144
145       getLog().debug("Starting context lookup speed test");
146       for (int i = 0; i < getIterationCount(); i++)
147       {
148          HelloHome home = (HelloHome)PortableRemoteObject.narrow(
149                               getInitialContext().lookup(HelloHome.JNDI_NAME),
150                               HelloHome.class);
151       }
152       long end = System.currentTimeMillis();
153       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
154    }
155
156    /**
157     * This tests the speed of JNDI lookups
158     *
159     * @exception Exception
160     */

161    public void testReusedContextSpeed()
162       throws Exception JavaDoc
163    {
164       Context JavaDoc ctx = getInitialContext();
165       long start = System.currentTimeMillis();
166
167       getLog().debug("Starting context lookup speed test");
168       for (int i = 0; i < getIterationCount(); i++)
169       {
170          HelloHome home = (HelloHome)PortableRemoteObject.narrow(
171                                   ctx.lookup(HelloHome.JNDI_NAME),
172                                   HelloHome.class);
173       }
174       long end = System.currentTimeMillis();
175       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
176    }
177
178    public static Test suite() throws Exception JavaDoc
179    {
180       return getDeploySetup(HelloTimingStressTestCase.class, "helloiiop.jar");
181    }
182
183 }
184
Popular Tags