KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > iiopperf > test > T9PassExceptionTestCase


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.iiopperf.test;
23
24
25 import javax.ejb.*;
26 import javax.naming.*;
27 import javax.rmi.PortableRemoteObject JavaDoc;
28
29 import org.jboss.test.iiopperf.interfaces.*;
30
31 import junit.framework.Test;
32 import junit.framework.TestCase;
33 import junit.framework.TestSuite;
34 import org.jboss.test.JBossTestCase;
35
36
37 /**
38  * @author Francisco.Reverbel@jboss.org
39  * @version $Revision: 37406 $
40  */

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

46    // Attributes ----------------------------------------------------
47
private java.util.Properties JavaDoc cosnamingJndiProps;
48
49    // Static --------------------------------------------------------
50

51    // Constructors --------------------------------------------------
52
public T9PassExceptionTestCase(String JavaDoc name)
53        throws java.io.IOException JavaDoc
54    {
55       super(name);
56       java.net.URL JavaDoc url;
57
58       url = ClassLoader.getSystemResource("cosnaming.jndi.properties");
59       cosnamingJndiProps = new java.util.Properties JavaDoc();
60       cosnamingJndiProps.load(url.openStream());
61    }
62    
63    // Package --------------------------------------------------------
64

65    InitialContext getInitialContext(java.util.Properties JavaDoc jndiProps)
66        throws Exception JavaDoc
67    {
68       return new InitialContext(jndiProps);
69    }
70
71    // Public --------------------------------------------------------
72

73    /**
74     * This tests the speed of JRMP throwException invocations
75     *
76     * @exception Exception
77     */

78    public void testJRMPReceiveException()
79       throws Exception JavaDoc
80    {
81       SessionHome home = (SessionHome)PortableRemoteObject.narrow(
82             getInitialContext().lookup(SessionHome.JNDI_NAME),
83             SessionHome.class);
84       Session session = home.create();
85       session.sendRemote(session);
86       int n = getIterationCount();
87       long start = System.currentTimeMillis();
88       for (int i = 0 ; i < n; i++)
89       {
90          try
91          {
92             session.throwException();
93          }
94          catch (Exception JavaDoc e)
95          {
96          }
97       }
98       long end = System.currentTimeMillis();
99       getLog().info("JRMP throwException: " +
100                     ((end - start) / (double)n) + " ms/call");
101    }
102    
103    /**
104     * This tests the speed of IIOP throwException invocations
105     *
106     * @exception Exception
107     */

108    public void testIIOPReceiveException()
109       throws Exception JavaDoc
110    {
111       SessionHome home = (SessionHome)PortableRemoteObject.narrow(
112             getInitialContext(cosnamingJndiProps).lookup(SessionHome.JNDI_NAME),
113             SessionHome.class);
114       Session session = home.create();
115       session.sendRemote(session);
116       int n = getIterationCount();
117       long start = System.currentTimeMillis();
118       for (int i = 0 ; i < n; i++)
119       {
120          try
121          {
122             session.throwException();
123          }
124          catch (Exception JavaDoc e)
125          {
126          }
127       }
128       long end = System.currentTimeMillis();
129       getLog().info("IIOP throwException: " +
130                     ((end - start) / (double)n) + " ms/call");
131    }
132    
133    public static Test suite() throws Exception JavaDoc
134    {
135       return getDeploySetup(T9PassExceptionTestCase.class, "iiopperf.jar");
136    }
137
138 }
139
Popular Tags