KickJava   Java API By Example, From Geeks To Geeks.

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

43 public class HelloTimingStressTestCase
44    extends JBossTestCase
45 {
46    // Constants -----------------------------------------------------
47

48    // Attributes ----------------------------------------------------
49
private java.util.Properties JavaDoc cosnamingJndiProps;
50    private java.util.Properties JavaDoc iiopJndiProps;
51    
52    // Static --------------------------------------------------------
53

54    // Constructors --------------------------------------------------
55
public HelloTimingStressTestCase(String JavaDoc name)
56        throws java.io.IOException JavaDoc
57    {
58       super(name);
59       URL JavaDoc url;
60       String JavaDoc host = System.getProperty("jbosstest.server.host", "localhost");
61
62       url = ClassLoader.getSystemResource("iiop.jndi.properties");
63       iiopJndiProps = new java.util.Properties JavaDoc();
64       iiopJndiProps.load(url.openStream());
65       String JavaDoc jnp = "jnp://"+host+":1099/iiop";
66       iiopJndiProps.setProperty("java.naming.provider.url", jnp);
67
68       url = ClassLoader.getSystemResource("cosnaming.jndi.properties");
69       cosnamingJndiProps = new java.util.Properties JavaDoc();
70       cosnamingJndiProps.load(url.openStream());
71       String JavaDoc corbaloc = "corbaloc::"+host+":3528/JBoss/Naming/root";
72       cosnamingJndiProps.setProperty("java.naming.provider.url", corbaloc);
73    }
74    
75    // Package --------------------------------------------------------
76

77    InitialContext getInitialContext(java.util.Properties JavaDoc jndiProps)
78        throws Exception JavaDoc
79    {
80       return new InitialContext(jndiProps);
81    }
82
83    // The two methods below are protected in the superclass. Here they're
84
// redefined as public to be called by the anonymous local Thread subclasses
85
// within testConcurrentJrmpAndIiopInvocations().
86

87    public InitialContext getInitialContext()
88        throws Exception JavaDoc
89    {
90       return super.getInitialContext();
91    }
92
93    public int getIterationCount()
94    {
95       return super.getIterationCount();
96    }
97
98    // Public --------------------------------------------------------
99

100    /**
101     * Lookup the bean, call it, remove it.
102     *
103     * @exception Exception
104     */

105    public void testHello()
106       throws Exception JavaDoc
107    {
108       HelloHome home;
109       Hello hello;
110
111       // use JRMP invoker
112
// (home is a JRMP proxy gotten from the JNP naming service)
113
home = (HelloHome)PortableRemoteObject.narrow(
114                                getInitialContext().lookup(HelloHome.JNDI_NAME),
115                                HelloHome.class);
116       hello = home.create();
117       getLog().debug(hello.hello("World"));
118       hello.remove();
119
120       // use IIOP invoker
121
// (home is an IOR gotten from the JNP naming service)
122
home = (HelloHome)PortableRemoteObject.narrow(
123                                getInitialContext(iiopJndiProps).lookup(
124                                                           HelloHome.JNDI_NAME),
125                                HelloHome.class);
126       hello = home.create();
127       getLog().debug(hello.hello("World"));
128       hello.remove();
129
130       // use IIOP invoker
131
// (home is an IOR gotten from the CORBA naming service)
132
home = (HelloHome)PortableRemoteObject.narrow(
133                                getInitialContext(cosnamingJndiProps).lookup(
134                                                           HelloHome.JNDI_NAME),
135                                HelloHome.class);
136       hello = home.create();
137       getLog().debug(hello.hello("World"));
138       hello.remove();
139    }
140    
141    /**
142     * Test marshalling of custom data-holders.
143     *
144     * @exception Exception
145     */

146    public void testData()
147       throws Exception JavaDoc
148    {
149       HelloHome home;
150       Hello hello;
151       HelloData name;
152
153       // use JRMP invoker
154
// (home is a JRMP proxy gotten from the JNP naming service)
155
home = (HelloHome)PortableRemoteObject.narrow(
156                                getInitialContext().lookup(HelloHome.JNDI_NAME),
157                                HelloHome.class);
158       hello = home.create();
159       name = new HelloData();
160       name.setName("World");
161       getLog().debug(hello.howdy(name));
162       hello.remove();
163
164       // use IIOP invoker
165
// (home is an IOR gotten from the JNP naming service)
166
home = (HelloHome)PortableRemoteObject.narrow(
167                                getInitialContext(iiopJndiProps).lookup(
168                                                           HelloHome.JNDI_NAME),
169                                HelloHome.class);
170       hello = home.create();
171       name = new HelloData();
172       name.setName("World");
173       getLog().debug(hello.howdy(name));
174       hello.remove();
175
176       // use IIOP invoker
177
// (home is an IOR gotten from the CORBA naming service)
178
home = (HelloHome)PortableRemoteObject.narrow(
179                                getInitialContext(cosnamingJndiProps).lookup(
180                                                           HelloHome.JNDI_NAME),
181                                HelloHome.class);
182       hello = home.create();
183       name = new HelloData();
184       name.setName("World");
185       getLog().debug(hello.howdy(name));
186       hello.remove();
187
188    }
189    
190    /**
191     * This tests the speed of JRMP invocations
192     *
193     * @exception Exception
194     */

195    public void testJRMPSpeed()
196       throws Exception JavaDoc
197    {
198       long start = System.currentTimeMillis();
199       HelloHome home = (HelloHome)PortableRemoteObject.narrow(
200                                getInitialContext().lookup(HelloHome.JNDI_NAME),
201                                HelloHome.class);
202       Hello hello = home.create();
203       for (int i = 0 ; i < getIterationCount(); i++)
204       {
205          hello.hello("Rickard");
206       }
207       long end = System.currentTimeMillis();
208       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
209    }
210    
211    /**
212     * This tests the speed of IIOP invocations
213     *
214     * @exception Exception
215     */

216    public void testIIOPSpeed()
217       throws Exception JavaDoc
218    {
219       long start = System.currentTimeMillis();
220       HelloHome home = (HelloHome)PortableRemoteObject.narrow(
221                                getInitialContext(iiopJndiProps).lookup(
222                                                           HelloHome.JNDI_NAME),
223                                HelloHome.class);
224       Hello hello = home.create();
225       for (int i = 0 ; i < getIterationCount(); i++)
226       {
227          hello.hello("Rickard");
228       }
229       long end = System.currentTimeMillis();
230       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
231    }
232    
233    /**
234     * This tests the speed of JRMP invocations
235     *
236     * @exception Exception
237     */

238    public void testJRMPSpeed2()
239       throws Exception JavaDoc
240    {
241       long start = System.currentTimeMillis();
242       long start2 = start;
243       HelloHome home = (HelloHome)PortableRemoteObject.narrow(
244                                getInitialContext().lookup(HelloHome.JNDI_NAME),
245                                HelloHome.class);
246       Hello hello = home.create();
247       for (int i = 0 ; i < getIterationCount(); i++)
248       {
249          hello.helloHello(hello);
250       }
251       long end = System.currentTimeMillis();
252       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
253    }
254
255    /**
256     * This tests the speed of IIOP invocations
257     *
258     * @exception Exception
259     */

260    public void testIIOPSpeed2()
261       throws Exception JavaDoc
262    {
263       long start = System.currentTimeMillis();
264       long start2 = start;
265       HelloHome home = (HelloHome)PortableRemoteObject.narrow(
266                                getInitialContext(iiopJndiProps).lookup(
267                                                           HelloHome.JNDI_NAME),
268                                HelloHome.class);
269       Hello hello = home.create();
270       for (int i = 0 ; i < getIterationCount(); i++)
271       {
272          hello.helloHello(hello);
273       }
274       long end = System.currentTimeMillis();
275       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
276    }
277
278    /**
279     * This tests concurrent JRMP and IIOP invocations
280     *
281     * @exception Exception
282     */

283    public void testConcurrentJrmpAndIiopInvocations()
284       throws Exception JavaDoc
285    {
286       Thread JavaDoc t1 = new Thread JavaDoc() {
287          public void run() {
288             try
289             {
290                HelloHome home = (HelloHome)PortableRemoteObject.narrow(
291                      getInitialContext().lookup(HelloHome.JNDI_NAME),
292                      HelloHome.class);
293                Hello hello = home.create();
294                for (int i = 0 ; i < getIterationCount(); i++)
295                {
296                   sleep(100);
297                   hello.hello("Rickard");
298                }
299                for (int i = 0 ; i < getIterationCount(); i++)
300                {
301                   sleep(100);
302                   hello.helloHello(hello);
303                }
304             }
305             catch (Exception JavaDoc e)
306             {
307                e.printStackTrace();
308             }
309          }
310       };
311
312       Thread JavaDoc t2 = new Thread JavaDoc() {
313          public void run() {
314             try
315             {
316                HelloHome home = (HelloHome)PortableRemoteObject.narrow(
317                      getInitialContext(cosnamingJndiProps).lookup(
318                                                           HelloHome.JNDI_NAME),
319                      HelloHome.class);
320                Hello hello = home.create();
321                for (int i = 0 ; i < getIterationCount() ; i++)
322                {
323                   sleep(10);
324                   hello.hello("Rickard");
325                }
326                for (int i = 0 ; i < getIterationCount() ; i++)
327                {
328                   sleep(10);
329                   hello.helloHello(hello);
330                }
331             }
332             catch (Exception JavaDoc e)
333             {
334                e.printStackTrace();
335             }
336          }
337       };
338       
339       t1.start();
340       t2.start();
341
342       t1.join();
343       t2.join();
344       
345    }
346    
347    public static Test suite() throws Exception JavaDoc
348    {
349       return getDeploySetup(HelloTimingStressTestCase.class, "hellojrmpiiop.jar");
350    }
351
352 }
353
Popular Tags