1 22 package org.jboss.test.hello.test; 23 24 import java.io.File ; 25 import javax.naming.Context ; 26 import javax.naming.InitialContext ; 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 42 public class HelloClusteredHttpStressTestCase extends JBossTestCase 43 { 44 static final String JNDI_NAME = "helloworld/HelloHA-HTTP"; 45 46 public HelloClusteredHttpStressTestCase(String name) 48 { 49 super(name); 50 } 51 52 54 59 public void testHello() 60 throws Exception 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 73 public void testSleepingHello() 74 throws Exception 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 86 public void testHelloException() 87 throws Exception 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 107 public void testCNFEObject() 108 throws Exception 109 { 110 HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME); 111 Hello hello = home.create(); 112 try 113 { 114 File clazz = new File ("classes/org/jboss/test/hello/ejb/HelloBean$ServerData.class"); 116 clazz.delete(); 117 getLog().debug("Invoking getCNFEObject"); 118 hello.getCNFEObject(); 119 } 120 catch(Exception e) 121 { 122 getLog().debug("Caught ClassNotFoundException as expected", e); 123 } 124 } 125 126 public void testServerExceptionDoesntFailOver() 127 throws Exception 128 { 129 HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME); 130 Hello hello = home.create(); 131 try 132 { 133 hello.throwException(); 134 } 135 catch(Exception 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 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 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 160 { 161 HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME); 162 Hello hello = home.create(); 163 try 164 { 165 hello.getNotSerializable(); 166 } 167 catch(Exception e) 168 { 169 getLog().debug("Caught IOException as expected", e); 170 } 171 hello.hello("server serialization error"); 172 } 173 174 179 public void testData() 180 throws Exception 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 195 public void testSpeed() 196 throws Exception 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 214 public void testSpeed2() 215 throws Exception 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 234 public void testContextSpeed() 235 throws Exception 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 ().lookup(JNDI_NAME); 243 } 244 long end = System.currentTimeMillis(); 245 getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount())); 246 } 247 248 253 public void testReusedContextSpeed() 254 throws Exception 255 { 256 Context 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 270 { 271 return getDeploySetup(HelloClusteredHttpStressTestCase.class, "hello-ha.jar"); 272 } 273 274 } 275 | Popular Tags |