1 22 package org.jboss.test.hellojrmpiiop.test; 23 24 25 import java.net.URL ; 26 import javax.ejb.*; 27 import javax.naming.*; 28 import javax.rmi.PortableRemoteObject ; 29 30 import org.jboss.test.hellojrmpiiop.interfaces.*; 31 32 import junit.framework.Test; 33 import junit.framework.TestCase; 34 import junit.framework.TestSuite; 35 import org.jboss.test.JBossTestCase; 36 37 38 43 public class HelloTimingStressTestCase 44 extends JBossTestCase 45 { 46 48 private java.util.Properties cosnamingJndiProps; 50 private java.util.Properties iiopJndiProps; 51 52 54 public HelloTimingStressTestCase(String name) 56 throws java.io.IOException 57 { 58 super(name); 59 URL url; 60 String host = System.getProperty("jbosstest.server.host", "localhost"); 61 62 url = ClassLoader.getSystemResource("iiop.jndi.properties"); 63 iiopJndiProps = new java.util.Properties (); 64 iiopJndiProps.load(url.openStream()); 65 String jnp = "jnp://"+host+":1099/iiop"; 66 iiopJndiProps.setProperty("java.naming.provider.url", jnp); 67 68 url = ClassLoader.getSystemResource("cosnaming.jndi.properties"); 69 cosnamingJndiProps = new java.util.Properties (); 70 cosnamingJndiProps.load(url.openStream()); 71 String corbaloc = "corbaloc::"+host+":3528/JBoss/Naming/root"; 72 cosnamingJndiProps.setProperty("java.naming.provider.url", corbaloc); 73 } 74 75 77 InitialContext getInitialContext(java.util.Properties jndiProps) 78 throws Exception 79 { 80 return new InitialContext(jndiProps); 81 } 82 83 87 public InitialContext getInitialContext() 88 throws Exception 89 { 90 return super.getInitialContext(); 91 } 92 93 public int getIterationCount() 94 { 95 return super.getIterationCount(); 96 } 97 98 100 105 public void testHello() 106 throws Exception 107 { 108 HelloHome home; 109 Hello hello; 110 111 home = (HelloHome)PortableRemoteObject.narrow( 114 getInitialContext().lookup(HelloHome.JNDI_NAME), 115 HelloHome.class); 116 hello = home.create(); 117 getLog().debug(hello.hello("World")); 118 hello.remove(); 119 120 home = (HelloHome)PortableRemoteObject.narrow( 123 getInitialContext(iiopJndiProps).lookup( 124 HelloHome.JNDI_NAME), 125 HelloHome.class); 126 hello = home.create(); 127 getLog().debug(hello.hello("World")); 128 hello.remove(); 129 130 home = (HelloHome)PortableRemoteObject.narrow( 133 getInitialContext(cosnamingJndiProps).lookup( 134 HelloHome.JNDI_NAME), 135 HelloHome.class); 136 hello = home.create(); 137 getLog().debug(hello.hello("World")); 138 hello.remove(); 139 } 140 141 146 public void testData() 147 throws Exception 148 { 149 HelloHome home; 150 Hello hello; 151 HelloData name; 152 153 home = (HelloHome)PortableRemoteObject.narrow( 156 getInitialContext().lookup(HelloHome.JNDI_NAME), 157 HelloHome.class); 158 hello = home.create(); 159 name = new HelloData(); 160 name.setName("World"); 161 getLog().debug(hello.howdy(name)); 162 hello.remove(); 163 164 home = (HelloHome)PortableRemoteObject.narrow( 167 getInitialContext(iiopJndiProps).lookup( 168 HelloHome.JNDI_NAME), 169 HelloHome.class); 170 hello = home.create(); 171 name = new HelloData(); 172 name.setName("World"); 173 getLog().debug(hello.howdy(name)); 174 hello.remove(); 175 176 home = (HelloHome)PortableRemoteObject.narrow( 179 getInitialContext(cosnamingJndiProps).lookup( 180 HelloHome.JNDI_NAME), 181 HelloHome.class); 182 hello = home.create(); 183 name = new HelloData(); 184 name.setName("World"); 185 getLog().debug(hello.howdy(name)); 186 hello.remove(); 187 188 } 189 190 195 public void testJRMPSpeed() 196 throws Exception 197 { 198 long start = System.currentTimeMillis(); 199 HelloHome home = (HelloHome)PortableRemoteObject.narrow( 200 getInitialContext().lookup(HelloHome.JNDI_NAME), 201 HelloHome.class); 202 Hello hello = home.create(); 203 for (int i = 0 ; i < getIterationCount(); i++) 204 { 205 hello.hello("Rickard"); 206 } 207 long end = System.currentTimeMillis(); 208 getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount())); 209 } 210 211 216 public void testIIOPSpeed() 217 throws Exception 218 { 219 long start = System.currentTimeMillis(); 220 HelloHome home = (HelloHome)PortableRemoteObject.narrow( 221 getInitialContext(iiopJndiProps).lookup( 222 HelloHome.JNDI_NAME), 223 HelloHome.class); 224 Hello hello = home.create(); 225 for (int i = 0 ; i < getIterationCount(); i++) 226 { 227 hello.hello("Rickard"); 228 } 229 long end = System.currentTimeMillis(); 230 getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount())); 231 } 232 233 238 public void testJRMPSpeed2() 239 throws Exception 240 { 241 long start = System.currentTimeMillis(); 242 long start2 = start; 243 HelloHome home = (HelloHome)PortableRemoteObject.narrow( 244 getInitialContext().lookup(HelloHome.JNDI_NAME), 245 HelloHome.class); 246 Hello hello = home.create(); 247 for (int i = 0 ; i < getIterationCount(); i++) 248 { 249 hello.helloHello(hello); 250 } 251 long end = System.currentTimeMillis(); 252 getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount())); 253 } 254 255 260 public void testIIOPSpeed2() 261 throws Exception 262 { 263 long start = System.currentTimeMillis(); 264 long start2 = start; 265 HelloHome home = (HelloHome)PortableRemoteObject.narrow( 266 getInitialContext(iiopJndiProps).lookup( 267 HelloHome.JNDI_NAME), 268 HelloHome.class); 269 Hello hello = home.create(); 270 for (int i = 0 ; i < getIterationCount(); i++) 271 { 272 hello.helloHello(hello); 273 } 274 long end = System.currentTimeMillis(); 275 getLog().debug("Avg. time/call(ms):"+((end-start)/getIterationCount())); 276 } 277 278 283 public void testConcurrentJrmpAndIiopInvocations() 284 throws Exception 285 { 286 Thread t1 = new Thread () { 287 public void run() { 288 try 289 { 290 HelloHome home = (HelloHome)PortableRemoteObject.narrow( 291 getInitialContext().lookup(HelloHome.JNDI_NAME), 292 HelloHome.class); 293 Hello hello = home.create(); 294 for (int i = 0 ; i < getIterationCount(); i++) 295 { 296 sleep(100); 297 hello.hello("Rickard"); 298 } 299 for (int i = 0 ; i < getIterationCount(); i++) 300 { 301 sleep(100); 302 hello.helloHello(hello); 303 } 304 } 305 catch (Exception e) 306 { 307 e.printStackTrace(); 308 } 309 } 310 }; 311 312 Thread t2 = new Thread () { 313 public void run() { 314 try 315 { 316 HelloHome home = (HelloHome)PortableRemoteObject.narrow( 317 getInitialContext(cosnamingJndiProps).lookup( 318 HelloHome.JNDI_NAME), 319 HelloHome.class); 320 Hello hello = home.create(); 321 for (int i = 0 ; i < getIterationCount() ; i++) 322 { 323 sleep(10); 324 hello.hello("Rickard"); 325 } 326 for (int i = 0 ; i < getIterationCount() ; i++) 327 { 328 sleep(10); 329 hello.helloHello(hello); 330 } 331 } 332 catch (Exception e) 333 { 334 e.printStackTrace(); 335 } 336 } 337 }; 338 339 t1.start(); 340 t2.start(); 341 342 t1.join(); 343 t2.join(); 344 345 } 346 347 public static Test suite() throws Exception 348 { 349 return getDeploySetup(HelloTimingStressTestCase.class, "hellojrmpiiop.jar"); 350 } 351 352 } 353 | Popular Tags |