KickJava   Java API By Example, From Geeks To Geeks.

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


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

42 public class HelloClusteredHttpStressTestCase extends JBossTestCase
43 {
44    static final String JavaDoc JNDI_NAME = "helloworld/HelloHA-HTTP";
45
46    // Constructors --------------------------------------------------
47
public HelloClusteredHttpStressTestCase(String JavaDoc name)
48    {
49       super(name);
50    }
51    
52    // Public --------------------------------------------------------
53

54    /**
55     * Lookup the bean, call it, remove it.
56     *
57     * @exception Exception
58     */

59    public void testHello()
60       throws Exception JavaDoc
61    {
62       HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME);
63       Hello hello = home.create();
64       getLog().debug(hello.hello("testHello"));
65       hello.remove();
66    }
67
68    /**
69     * Lookup the bean, call it, remove it.
70     *
71     * @exception Exception
72     */

73    public void testSleepingHello()
74       throws Exception JavaDoc
75    {
76       HelloHome home = (HelloHome) getInitialContext().lookup(JNDI_NAME);
77       Hello hello = home.create();
78       getLog().debug(hello.sleepingHello("testSleepingHello", 10000));
79       hello.remove();
80    }
81
82    /** Test that an application declared exception is not wrapped and does
83     * not trigger failover.
84     * @throws Exception
85     */

86    public void testHelloException()
87       throws Exception JavaDoc
88    {
89       HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME);
90       Hello hello = home.create();
91       try
92       {
93          getLog().debug("Invoking helloException");
94          hello.helloException("testHelloException");
95          fail("Was able to call helloException");
96       }
97       catch(HelloException e)
98       {
99          getLog().debug("Caught HelloException as expected");
100       }
101       hello.remove();
102    }
103
104    /** Test that a runtime error does trigger failover.
105     * @throws Exception
106     */

107    public void testCNFEObject()
108       throws Exception JavaDoc
109    {
110       HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME);
111       Hello hello = home.create();
112       try
113       {
114          // Remove
115
File JavaDoc clazz = new File JavaDoc("classes/org/jboss/test/hello/ejb/HelloBean$ServerData.class");
116          clazz.delete();
117          getLog().debug("Invoking getCNFEObject");
118          hello.getCNFEObject();
119       }
120       catch(Exception JavaDoc e)
121       {
122          getLog().debug("Caught ClassNotFoundException as expected", e);
123       }
124    }
125
126    public void testServerExceptionDoesntFailOver()
127       throws Exception JavaDoc
128    {
129       HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME);
130       Hello hello = home.create();
131       try
132       {
133          hello.throwException();
134       }
135       catch(Exception JavaDoc e)
136       {
137          getLog().debug("Caught IOException as expected", e);
138       }
139       hello.hello("server exception error");
140    }
141
142    public void testClientSerializationErrorDoesntFailOver()
143       throws Exception JavaDoc
144    {
145       HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME);
146       Hello hello = home.create();
147       try
148       {
149          hello.setNotSerializable(new NotSerializable());
150       }
151       catch(Exception JavaDoc e)
152       {
153          getLog().debug("Caught IOException as expected", e);
154       }
155       hello.hello("client serialization error");
156    }
157
158    public void testServerSerializationErrorDoesntFailOver()
159       throws Exception JavaDoc
160    {
161       HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME);
162       Hello hello = home.create();
163       try
164       {
165          hello.getNotSerializable();
166       }
167       catch(Exception JavaDoc e)
168       {
169          getLog().debug("Caught IOException as expected", e);
170       }
171       hello.hello("server serialization error");
172    }
173
174    /**
175     * Test marshalling of custom data-holders.
176     *
177     * @exception Exception
178     */

179    public void testData()
180       throws Exception JavaDoc
181    {
182       HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME);
183       Hello hello = home.create();
184       HelloData name = new HelloData();
185       name.setName("testData");
186       getLog().debug(hello.howdy(name));
187       hello.remove();
188    }
189    
190    /**
191     * This tests the speed of invocations
192     *
193     * @exception Exception
194     */

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

214    public void testSpeed2()
215       throws Exception JavaDoc
216    {
217       long start = System.currentTimeMillis();
218       long start2 = start;
219       HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME);
220       Hello hello = home.create();
221       for (int i = 0 ; i < getIterationCount(); i++)
222       {
223          hello.helloHello(hello);
224       }
225       long end = System.currentTimeMillis();
226       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
227    }
228
229    /**
230     * This tests the speed of InitialContext lookups
231     * including getting the initial context.
232     * @exception Exception
233     */

234    public void testContextSpeed()
235       throws Exception JavaDoc
236    {
237       long start = System.currentTimeMillis();
238       
239       getLog().debug("Starting context lookup speed test");
240       for (int i = 0; i < getIterationCount(); i++)
241       {
242          HelloHome home = (HelloHome)new InitialContext JavaDoc().lookup(JNDI_NAME);
243       }
244       long end = System.currentTimeMillis();
245       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
246    }
247
248    /**
249     * This tests the speed of JNDI lookups
250     *
251     * @exception Exception
252     */

253    public void testReusedContextSpeed()
254       throws Exception JavaDoc
255    {
256       Context JavaDoc ctx = getInitialContext();
257       long start = System.currentTimeMillis();
258       
259       getLog().debug("Starting context lookup speed test");
260       for (int i = 0; i < getIterationCount(); i++)
261       {
262          HelloHome home = (HelloHome)ctx.lookup(JNDI_NAME);
263       }
264       long end = System.currentTimeMillis();
265       getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount()));
266    }
267    
268    
269    public static Test suite() throws Exception JavaDoc
270    {
271       return getDeploySetup(HelloClusteredHttpStressTestCase.class, "hello-ha.jar");
272    }
273
274 }
275
Popular Tags