001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.hello.test;
023:
024: import java.io.File;
025: import javax.naming.Context;
026: import javax.naming.InitialContext;
027:
028: import junit.framework.Test;
029:
030: import org.jboss.test.JBossTestCase;
031: import org.jboss.test.hello.interfaces.Hello;
032: import org.jboss.test.hello.interfaces.HelloData;
033: import org.jboss.test.hello.interfaces.HelloException;
034: import org.jboss.test.hello.interfaces.HelloHome;
035: import org.jboss.test.hello.interfaces.NotSerializable;
036:
037: /** Simple tests of the Hello stateless session bean
038: *
039: * @author Scott.Stark@jboss.org
040: * @version $Revision: 57211 $
041: */
042: public class HelloClusteredHttpStressTestCase extends JBossTestCase {
043: static final String JNDI_NAME = "helloworld/HelloHA-HTTP";
044:
045: // Constructors --------------------------------------------------
046: public HelloClusteredHttpStressTestCase(String name) {
047: super (name);
048: }
049:
050: // Public --------------------------------------------------------
051:
052: /**
053: * Lookup the bean, call it, remove it.
054: *
055: * @exception Exception
056: */
057: public void testHello() throws Exception {
058: HelloHome home = (HelloHome) getInitialContext().lookup(
059: JNDI_NAME);
060: Hello hello = home.create();
061: getLog().debug(hello.hello("testHello"));
062: hello.remove();
063: }
064:
065: /**
066: * Lookup the bean, call it, remove it.
067: *
068: * @exception Exception
069: */
070: public void testSleepingHello() throws Exception {
071: HelloHome home = (HelloHome) getInitialContext().lookup(
072: JNDI_NAME);
073: Hello hello = home.create();
074: getLog().debug(hello.sleepingHello("testSleepingHello", 10000));
075: hello.remove();
076: }
077:
078: /** Test that an application declared exception is not wrapped and does
079: * not trigger failover.
080: * @throws Exception
081: */
082: public void testHelloException() throws Exception {
083: HelloHome home = (HelloHome) getInitialContext().lookup(
084: JNDI_NAME);
085: Hello hello = home.create();
086: try {
087: getLog().debug("Invoking helloException");
088: hello.helloException("testHelloException");
089: fail("Was able to call helloException");
090: } catch (HelloException e) {
091: getLog().debug("Caught HelloException as expected");
092: }
093: hello.remove();
094: }
095:
096: /** Test that a runtime error does trigger failover.
097: * @throws Exception
098: */
099: public void testCNFEObject() throws Exception {
100: HelloHome home = (HelloHome) getInitialContext().lookup(
101: JNDI_NAME);
102: Hello hello = home.create();
103: try {
104: // Remove
105: File clazz = new File(
106: "classes/org/jboss/test/hello/ejb/HelloBean$ServerData.class");
107: clazz.delete();
108: getLog().debug("Invoking getCNFEObject");
109: hello.getCNFEObject();
110: } catch (Exception e) {
111: getLog().debug("Caught ClassNotFoundException as expected",
112: e);
113: }
114: }
115:
116: public void testServerExceptionDoesntFailOver() throws Exception {
117: HelloHome home = (HelloHome) getInitialContext().lookup(
118: JNDI_NAME);
119: Hello hello = home.create();
120: try {
121: hello.throwException();
122: } catch (Exception e) {
123: getLog().debug("Caught IOException as expected", e);
124: }
125: hello.hello("server exception error");
126: }
127:
128: public void testClientSerializationErrorDoesntFailOver()
129: throws Exception {
130: HelloHome home = (HelloHome) getInitialContext().lookup(
131: JNDI_NAME);
132: Hello hello = home.create();
133: try {
134: hello.setNotSerializable(new NotSerializable());
135: } catch (Exception e) {
136: getLog().debug("Caught IOException as expected", e);
137: }
138: hello.hello("client serialization error");
139: }
140:
141: public void testServerSerializationErrorDoesntFailOver()
142: throws Exception {
143: HelloHome home = (HelloHome) getInitialContext().lookup(
144: JNDI_NAME);
145: Hello hello = home.create();
146: try {
147: hello.getNotSerializable();
148: } catch (Exception e) {
149: getLog().debug("Caught IOException as expected", e);
150: }
151: hello.hello("server serialization error");
152: }
153:
154: /**
155: * Test marshalling of custom data-holders.
156: *
157: * @exception Exception
158: */
159: public void testData() throws Exception {
160: HelloHome home = (HelloHome) getInitialContext().lookup(
161: JNDI_NAME);
162: Hello hello = home.create();
163: HelloData name = new HelloData();
164: name.setName("testData");
165: getLog().debug(hello.howdy(name));
166: hello.remove();
167: }
168:
169: /**
170: * This tests the speed of invocations
171: *
172: * @exception Exception
173: */
174: public void testSpeed() throws Exception {
175: long start = System.currentTimeMillis();
176: HelloHome home = (HelloHome) getInitialContext().lookup(
177: JNDI_NAME);
178: Hello hello = home.create();
179: for (int i = 0; i < getIterationCount(); i++) {
180: hello.hello("testSpeed");
181: }
182: long end = System.currentTimeMillis();
183: getLog().debug(
184: "Avg. time/call(ms):"
185: + ((end - start) / getIterationCount()));
186: }
187:
188: /**
189: * This tests the speed of invocations
190: *
191: * @exception Exception
192: */
193: public void testSpeed2() throws Exception {
194: long start = System.currentTimeMillis();
195: long start2 = start;
196: HelloHome home = (HelloHome) getInitialContext().lookup(
197: JNDI_NAME);
198: Hello hello = home.create();
199: for (int i = 0; i < getIterationCount(); i++) {
200: hello.helloHello(hello);
201: }
202: long end = System.currentTimeMillis();
203: getLog().debug(
204: "Avg. time/call(ms):"
205: + ((end - start) / getIterationCount()));
206: }
207:
208: /**
209: * This tests the speed of InitialContext lookups
210: * including getting the initial context.
211: * @exception Exception
212: */
213: public void testContextSpeed() throws Exception {
214: long start = System.currentTimeMillis();
215:
216: getLog().debug("Starting context lookup speed test");
217: for (int i = 0; i < getIterationCount(); i++) {
218: HelloHome home = (HelloHome) new InitialContext()
219: .lookup(JNDI_NAME);
220: }
221: long end = System.currentTimeMillis();
222: getLog().debug(
223: "Avg. time/call(ms):"
224: + ((end - start) / getIterationCount()));
225: }
226:
227: /**
228: * This tests the speed of JNDI lookups
229: *
230: * @exception Exception
231: */
232: public void testReusedContextSpeed() throws Exception {
233: Context ctx = getInitialContext();
234: long start = System.currentTimeMillis();
235:
236: getLog().debug("Starting context lookup speed test");
237: for (int i = 0; i < getIterationCount(); i++) {
238: HelloHome home = (HelloHome) ctx.lookup(JNDI_NAME);
239: }
240: long end = System.currentTimeMillis();
241: getLog().debug(
242: "Avg. time/call(ms):"
243: + ((end - start) / getIterationCount()));
244: }
245:
246: public static Test suite() throws Exception {
247: return getDeploySetup(HelloClusteredHttpStressTestCase.class,
248: "hello-ha.jar");
249: }
250:
251: }
|