KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > excepiiop > test > ExceptionTimingStressTestCase


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.excepiiop.test;
23
24
25 import javax.ejb.*;
26 import javax.naming.*;
27 import javax.rmi.PortableRemoteObject JavaDoc;
28
29 import org.jboss.test.excepiiop.interfaces.*;
30
31 import junit.framework.Test;
32 import junit.framework.TestCase;
33 import junit.framework.TestSuite;
34 import org.jboss.test.JBossTestCase;
35 import org.jboss.test.JBossIIOPTestCase;
36
37
38 public class ExceptionTimingStressTestCase
39    extends JBossIIOPTestCase
40 {
41    // Constants -----------------------------------------------------
42

43    // Attributes ----------------------------------------------------
44

45    // Static --------------------------------------------------------
46

47    // Constructors --------------------------------------------------
48
public ExceptionTimingStressTestCase(String JavaDoc name)
49    {
50       super(name);
51    }
52
53    // Public --------------------------------------------------------
54

55    public void testNoException()
56       throws Exception JavaDoc
57    {
58       ExceptionThrowerHome home =
59          (ExceptionThrowerHome)PortableRemoteObject.narrow(
60                getInitialContext().lookup(ExceptionThrowerHome.JNDI_NAME),
61                ExceptionThrowerHome.class);
62       ExceptionThrower exceptionThrower = home.create();
63       exceptionThrower.throwException(0);
64       exceptionThrower.remove();
65    }
66
67    public void testJavaException()
68       throws Exception JavaDoc
69    {
70       ExceptionThrowerHome home =
71          (ExceptionThrowerHome)PortableRemoteObject.narrow(
72                getInitialContext().lookup(ExceptionThrowerHome.JNDI_NAME),
73                ExceptionThrowerHome.class);
74       ExceptionThrower exceptionThrower = home.create();
75       try
76       {
77          exceptionThrower.throwException(1);
78       }
79       catch (JavaException e)
80       {
81          System.out.println("JavaException: " + e.i + ", " + e.s);
82       }
83       exceptionThrower.remove();
84    }
85
86    public void testIdlException()
87       throws Exception JavaDoc
88    {
89       ExceptionThrowerHome home =
90          (ExceptionThrowerHome)PortableRemoteObject.narrow(
91                getInitialContext().lookup(ExceptionThrowerHome.JNDI_NAME),
92                ExceptionThrowerHome.class);
93       ExceptionThrower exceptionThrower = home.create();
94       try
95       {
96          exceptionThrower.throwException(-1);
97       }
98       catch (IdlException e)
99       {
100          System.out.println("IdlException: " + e.i + ", " + e.s);
101       }
102       exceptionThrower.remove();
103    }
104
105    /**
106     * This tests the speed of invocations
107     *
108     * @exception Exception
109     */

110    public void testSpeedNoException()
111       throws Exception JavaDoc
112    {
113       long start = System.currentTimeMillis();
114       ExceptionThrowerHome home =
115          (ExceptionThrowerHome)PortableRemoteObject.narrow(
116                getInitialContext().lookup(ExceptionThrowerHome.JNDI_NAME),
117                ExceptionThrowerHome.class);
118       ExceptionThrower exceptionThrower = home.create();
119       for (int i = 0 ; i < getIterationCount(); i++)
120       {
121          exceptionThrower.throwException(0);
122       }
123       long end = System.currentTimeMillis();
124       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
125       exceptionThrower.remove();
126    }
127
128    /**
129     * This tests the speed of invocations
130     *
131     * @exception Exception
132     */

133    public void testSpeedJavaException()
134       throws Exception JavaDoc
135    {
136       long start = System.currentTimeMillis();
137       ExceptionThrowerHome home =
138          (ExceptionThrowerHome)PortableRemoteObject.narrow(
139                getInitialContext().lookup(ExceptionThrowerHome.JNDI_NAME),
140                ExceptionThrowerHome.class);
141       ExceptionThrower exceptionThrower = home.create();
142       for (int i = 0 ; i < getIterationCount(); i++)
143       {
144          try
145          {
146             exceptionThrower.throwException(i + 1);
147          }
148          catch (JavaException e)
149          {
150             System.out.println("JavaException: " + e.i + ", " + e.s);
151          }
152       }
153       long end = System.currentTimeMillis();
154       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
155       exceptionThrower.remove();
156    }
157
158    /**
159     * This tests the speed of invocations
160     *
161     * @exception Exception
162     */

163    public void testSpeedIdlException()
164       throws Exception JavaDoc
165    {
166       long start = System.currentTimeMillis();
167       ExceptionThrowerHome home =
168          (ExceptionThrowerHome)PortableRemoteObject.narrow(
169                getInitialContext().lookup(ExceptionThrowerHome.JNDI_NAME),
170                ExceptionThrowerHome.class);
171       ExceptionThrower exceptionThrower = home.create();
172       for (int i = 0 ; i < getIterationCount(); i++)
173       {
174          try
175          {
176             exceptionThrower.throwException(-1 - i);
177          }
178          catch (IdlException e)
179          {
180             System.out.println("IdlException: " + e.i + ", " + e.s);
181          }
182       }
183       long end = System.currentTimeMillis();
184       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
185       exceptionThrower.remove();
186    }
187
188    public static Test suite() throws Exception JavaDoc
189    {
190       return getDeploySetup(ExceptionTimingStressTestCase.class, "excepiiop.jar");
191    }
192
193 }
194
Popular Tags