1 22 package org.jboss.test.hello.test; 23 24 import javax.naming.Context ; 25 import javax.naming.InitialContext ; 26 27 import junit.framework.Test; 28 29 import org.jboss.test.JBossTestCase; 30 import org.jboss.test.hello.interfaces.Hello; 31 import org.jboss.test.hello.interfaces.HelloData; 32 import org.jboss.test.hello.interfaces.HelloHome; 33 import org.jboss.test.hello.interfaces.HelloLog; 34 import org.jboss.test.hello.interfaces.HelloLogHome; 35 36 41 public class HelloHttpStressTestCase 42 extends JBossTestCase 43 { 44 static final String JNDI_NAME = "helloworld/HelloHTTP"; 46 48 static boolean deployed = false; 50 51 public HelloHttpStressTestCase(String name) 53 { 54 super(name); 55 } 56 57 59 64 public void testHello() 65 throws Exception 66 { 67 InitialContext ctx = getInitialContext(); 68 HelloHome home = (HelloHome) ctx.lookup("helloworld/HelloHTTP"); 69 Hello hello = home.create(); 70 String reply = hello.hello("World"); 71 getLog().debug(reply); 72 hello.remove(); 73 } 74 75 80 public void testLoggedHello() 81 throws Exception 82 { 83 InitialContext ctx = getInitialContext(); 84 HelloHome home = (HelloHome) ctx.lookup("helloworld/HelloHTTP"); 85 Hello hello = home.create(); 86 String reply = hello.loggedHello("World"); 87 getLog().debug(reply); 88 hello.remove(); 89 90 HelloLogHome logHome = (HelloLogHome) ctx.lookup("helloworld/HelloLogHTTP"); 92 HelloLog log = logHome.findByPrimaryKey("World"); 93 long start = log.getStartTime(); 94 long end = log.getEndTime(); 95 getLog().debug("HelloLog times: "+start+","+end); 96 long elapsed = log.getElapsedTime(); 97 getLog().debug("HelloLog elapsed: "+elapsed); 98 } 99 100 105 public void testData() 106 throws Exception 107 { 108 HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME); 109 Hello hello = home.create(); 110 HelloData name = new HelloData(); 111 name.setName("World"); 112 getLog().debug(hello.howdy(name)); 113 hello.remove(); 114 } 115 116 121 public void testSpeed() 122 throws Exception 123 { 124 long start = System.currentTimeMillis(); 125 HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME); 126 Hello hello = home.create(); 127 int count = getIterationCount(); 128 for (int i = 0 ; i < count; i++) 129 { 130 hello.hello("Argument#"+i); 131 } 132 long end = System.currentTimeMillis(); 133 getLog().debug("Avg. for "+count+" calls (ms):"+((end-start)/count)); 134 } 135 136 141 public void testSpeed2() 142 throws Exception 143 { 144 long start = System.currentTimeMillis(); 145 HelloHome home = (HelloHome)getInitialContext().lookup(JNDI_NAME); 146 Hello hello = home.create(); 147 int count = getIterationCount(); 148 for (int i = 0 ; i < count; i++) 149 { 150 hello.helloHello(hello); 151 } 152 long end = System.currentTimeMillis(); 153 getLog().debug("Avg. for "+count+" calls (ms):"+((end-start)/count)); 154 } 155 156 161 public void testContextSpeed() 162 throws Exception 163 { 164 long start = System.currentTimeMillis(); 165 166 getLog().debug("Starting context lookup speed test"); 167 int count = getIterationCount(); 168 for (int i = 0 ; i < count; i++) 169 { 170 HelloHome home = (HelloHome) new InitialContext ().lookup(JNDI_NAME); 171 home.hashCode(); 172 } 173 long end = System.currentTimeMillis(); 174 getLog().debug("Avg. for "+count+" lookups (ms):"+((end-start)/count)); 175 } 176 177 182 public void testReusedContextSpeed() 183 throws Exception 184 { 185 Context ctx = getInitialContext(); 186 long start = System.currentTimeMillis(); 187 188 getLog().debug("Starting context lookup speed test"); 189 int count = getIterationCount(); 190 for (int i = 0 ; i < count; i++) 191 { 192 HelloHome home = (HelloHome) ctx.lookup(JNDI_NAME); 193 home.hashCode(); 194 } 195 long end = System.currentTimeMillis(); 196 getLog().debug("Avg. for "+count+" lookups (ms):"+((end-start)/count)); 197 } 198 199 200 public static Test suite() throws Exception 201 { 202 return getDeploySetup(HelloHttpStressTestCase.class, "hello.jar"); 203 } 204 205 } 206 | Popular Tags |