1 22 package org.jboss.test.perf.test; 23 24 import java.io.IOException ; 25 import java.rmi.RemoteException ; 26 import javax.ejb.CreateException ; 27 import javax.naming.InitialContext ; 28 import javax.naming.NamingException ; 29 import javax.rmi.PortableRemoteObject ; 30 31 import junit.framework.Test; 32 import junit.framework.TestCase; 33 import junit.framework.TestSuite; 34 35 import org.jboss.test.perf.interfaces.Entity; 36 import org.jboss.test.perf.interfaces.EntityPK; 37 import org.jboss.test.perf.interfaces.Entity2PK; 38 import org.jboss.test.perf.interfaces.EntityHome; 39 import org.jboss.test.perf.interfaces.Entity2Home; 40 import org.jboss.test.perf.interfaces.Probe; 41 import org.jboss.test.perf.interfaces.ProbeHome; 42 import org.jboss.test.perf.interfaces.Session; 43 import org.jboss.test.perf.interfaces.SessionHome; 44 import org.jboss.test.perf.interfaces.TxSession; 45 import org.jboss.test.perf.interfaces.TxSessionHome; 46 47 import org.jboss.test.JBossTestCase; 48 49 54 public class PerfStressTestCase extends JBossTestCase 55 { 56 protected String CLIENT_SESSION = "perf.ClientSession"; 57 protected String CLIENT_ENTITY = "local/perfClientEntity"; 58 protected String PROBE = "perf.Probe"; 59 protected String PROBE_CMT = "perf.ProbeCMT"; 60 protected String TX_SESSION = "perf.TxSession"; 61 protected String ENTITY = "perfEntity"; 62 protected String ENTITY2 = "perfEntity2"; 63 64 int iterationCount; 65 int beanCount; 66 67 public PerfStressTestCase(String name) 68 { 69 super(name); 70 iterationCount = getIterationCount(); 71 beanCount = getBeanCount(); 72 } 73 74 public void testClientSession() throws Exception 75 { 76 getLog().debug("+++ testClientSession()"); 77 Object obj = getInitialContext().lookup(CLIENT_SESSION); 78 obj = PortableRemoteObject.narrow(obj, SessionHome.class); 79 SessionHome home = (SessionHome) obj; 80 getLog().debug("Found SessionHome @ jndiName=ClientSession"); 81 Session bean = home.create(CLIENT_ENTITY); 82 getLog().debug("Created ClientSession"); 83 84 try 85 { 86 bean.create(0, getBeanCount()); 87 } 88 catch(javax.ejb.CreateException e) 89 { 90 getLog().debug("Exception while creating entities: ", e); 91 } 92 93 long start = System.currentTimeMillis(); 94 bean.read(0); 95 bean.read(0, getBeanCount()); 96 bean.write(0); 97 bean.write(0, getBeanCount()); 98 bean.remove(0, getBeanCount()); 99 long end = System.currentTimeMillis(); 100 long elapsed = end - start; 101 getLog().debug("Elapsed time = "+(elapsed / iterationCount)); 102 } 103 104 public void testTimings() throws Exception 105 { 106 getLog().debug("+++ testTimings()"); 107 Object obj = getInitialContext().lookup(PROBE); 108 obj = PortableRemoteObject.narrow(obj, ProbeHome.class); 109 ProbeHome home = (ProbeHome) obj; 110 getLog().debug("Found ProbeHome @ jndiName=Probe"); 111 Probe bean = home.create(); 112 getLog().debug("Created Probe"); 113 warmup(bean); 114 noop(bean); 115 ping(bean); 116 echo(bean); 117 } 118 119 public void testTimingsCMT() throws Exception 120 { 121 getLog().debug("+++ testTimingsCMT()"); 122 Object obj = getInitialContext().lookup(PROBE_CMT); 123 obj = PortableRemoteObject.narrow(obj, ProbeHome.class); 124 ProbeHome home = (ProbeHome) obj; 125 getLog().debug("Found ProbeHome @ jndiName=ProbeCMT"); 126 Probe bean = home.create(); 127 getLog().debug("Created ProbeCMT"); 128 warmup(bean); 129 noop(bean); 130 ping(bean); 131 echo(bean); 132 } 133 134 public void testTxTimings() throws Exception 135 { 136 getLog().debug("+++ testTxTimings()"); 137 Object obj = getInitialContext().lookup(TX_SESSION); 138 obj = PortableRemoteObject.narrow(obj, TxSessionHome.class); 139 TxSessionHome home = (TxSessionHome) obj; 140 getLog().debug("Found TxSession @ jndiName=TxSession"); 141 TxSession bean = home.create(); 142 getLog().debug("Created TxSession"); 143 txRequired(bean); 144 txRequiresNew(bean); 145 txSupports(bean); 146 txNotSupported(bean); 147 requiredToSupports(bean); 148 requiredToMandatory(bean); 149 requiredToRequiresNew(bean); 150 } 151 public void testFindByPrimaryKey() throws Exception 152 { 153 getLog().debug("+++ testFindByPrimaryKey()"); 154 Object obj = getInitialContext().lookup(ENTITY); 155 obj = PortableRemoteObject.narrow(obj, EntityHome.class); 156 EntityHome home = (EntityHome) obj; 157 getLog().debug("Found EntityHome @ jndiName=Entity"); 158 EntityPK key = new EntityPK(0); 159 Entity bean = null; 160 161 getLog().debug("Running with " + iterationCount + " instances..."); 162 findByPrimaryKey(key, home); 163 } 164 public void testFindByPrimaryKey2() throws Exception 165 { 166 getLog().debug("+++ testFindByPrimaryKey2()"); 167 Object obj = getInitialContext().lookup(ENTITY2); 168 obj = PortableRemoteObject.narrow(obj, Entity2Home.class); 169 Entity2Home home = (Entity2Home) obj; 170 getLog().debug("Found EntityHome @ jndiName=Entity"); 171 Entity2PK key = new Entity2PK(0, "String0", new Double (0)); 172 Entity bean = null; 173 174 getLog().debug("Running with " + iterationCount + " instances..."); 175 findByPrimaryKey(key, home); 176 } 177 178 private void warmup(Probe bean) throws Exception 179 { 180 bean.noop(); 181 bean.ping("Ping"); 182 bean.echo("Echo"); 183 } 184 185 private void noop(Probe bean) throws Exception 186 { 187 getLog().debug("Starting "+iterationCount+" noop() invocations"); 188 long start = System.currentTimeMillis(); 189 for(int n = 0; n < iterationCount; n ++) 190 bean.noop(); 191 long end = System.currentTimeMillis(); 192 long elapsed = end - start; 193 getLog().debug(iterationCount+" noop() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/noop"); 194 } 195 private void ping(Probe bean) throws Exception 196 { 197 getLog().debug("Starting "+iterationCount+" ping(PING) invocations"); 198 long start = System.currentTimeMillis(); 199 for(int n = 0; n < iterationCount; n ++) 200 bean.ping("PING"); 201 long end = System.currentTimeMillis(); 202 long elapsed = end - start; 203 getLog().debug(iterationCount+" ping() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/noop"); 204 } 205 private void echo(Probe bean) throws Exception 206 { 207 getLog().debug("Starting "+iterationCount+" echo(ECHO) invocations"); 208 long start = System.currentTimeMillis(); 209 for(int n = 0; n < iterationCount; n ++) 210 { 211 String echo = bean.echo("ECHO"); 212 } 213 long end = System.currentTimeMillis(); 214 long elapsed = end - start; 215 getLog().debug(iterationCount+" echo() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/noop"); 216 } 217 private void txRequired(TxSession bean) throws Exception 218 { 219 getLog().debug("Starting "+iterationCount+" txRequired() invocations"); 220 long start = System.currentTimeMillis(); 221 for(int n = 0; n < iterationCount; n ++) 222 { 223 String echo = bean.txRequired(); 224 } 225 long end = System.currentTimeMillis(); 226 long elapsed = end - start; 227 getLog().debug(iterationCount+" txRequired() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/txRequired"); 228 } 229 private void txRequiresNew(TxSession bean) throws Exception 230 { 231 getLog().debug("Starting "+iterationCount+" txRequired() invocations"); 232 long start = System.currentTimeMillis(); 233 for(int n = 0; n < iterationCount; n ++) 234 { 235 String echo = bean.txRequiresNew(); 236 } 237 long end = System.currentTimeMillis(); 238 long elapsed = end - start; 239 getLog().debug(iterationCount+" txRequiresNew() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/txRequiresNew"); 240 } 241 private void txSupports(TxSession bean) throws Exception 242 { 243 getLog().debug("Starting "+iterationCount+" txSupports() invocations"); 244 long start = System.currentTimeMillis(); 245 for(int n = 0; n < iterationCount; n ++) 246 { 247 String echo = bean.txSupports(); 248 } 249 long end = System.currentTimeMillis(); 250 long elapsed = end - start; 251 getLog().debug(iterationCount+" txSupports() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/txSupports"); 252 } 253 private void txNotSupported(TxSession bean) throws Exception 254 { 255 getLog().debug("Starting "+iterationCount+" txNotSupported() invocations"); 256 long start = System.currentTimeMillis(); 257 for(int n = 0; n < iterationCount; n ++) 258 { 259 String echo = bean.txNotSupported(); 260 } 261 long end = System.currentTimeMillis(); 262 long elapsed = end - start; 263 getLog().debug(iterationCount+" txNotSupported() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/txNotSupported"); 264 } 265 private void requiredToSupports(TxSession bean) throws Exception 266 { 267 getLog().debug("Starting "+iterationCount+" requiredToSupports() invocations"); 268 long start = System.currentTimeMillis(); 269 for(int n = 0; n < iterationCount; n ++) 270 { 271 String echo = bean.requiredToSupports(); 272 } 273 long end = System.currentTimeMillis(); 274 long elapsed = end - start; 275 getLog().debug(iterationCount+" requiredToSupports() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/requiredToSupports"); 276 } 277 private void requiredToMandatory(TxSession bean) throws Exception 278 { 279 getLog().debug("Starting "+iterationCount+" requiredToMandatory() invocations"); 280 long start = System.currentTimeMillis(); 281 for(int n = 0; n < iterationCount; n ++) 282 { 283 String echo = bean.requiredToMandatory(); 284 } 285 long end = System.currentTimeMillis(); 286 long elapsed = end - start; 287 getLog().debug(iterationCount+" requiredToMandatory() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/requiredToMandatory"); 288 } 289 private void requiredToRequiresNew(TxSession bean) throws Exception 290 { 291 getLog().debug("Starting "+iterationCount+" requiredToRequiresNew() invocations"); 292 long start = System.currentTimeMillis(); 293 for(int n = 0; n < iterationCount; n ++) 294 { 295 String echo = bean.requiredToRequiresNew(); 296 } 297 long end = System.currentTimeMillis(); 298 long elapsed = end - start; 299 getLog().debug(iterationCount+" requiredToRequiresNew() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/requiredToRequiresNew"); 300 } 301 302 private void findByPrimaryKey(EntityPK key, EntityHome home) throws Exception 303 { 304 getLog().debug("Starting "+iterationCount+" findByPrimaryKey(key="+key+") invocations"); 305 long start = System.currentTimeMillis(); 306 for(int n = 0; n < iterationCount; n ++) 307 { 308 Entity bean = home.findByPrimaryKey(key); 309 } 310 long end = System.currentTimeMillis(); 311 long elapsed = end - start; 312 getLog().debug(iterationCount+" findByPrimaryKey() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/findByPrimaryKey"); 313 } 314 private void findByPrimaryKey(Entity2PK key, Entity2Home home) throws Exception 315 { 316 getLog().debug("Starting "+iterationCount+" findByPrimaryKey(key="+key+") invocations"); 317 long start = System.currentTimeMillis(); 318 for(int n = 0; n < iterationCount; n ++) 319 { 320 Entity bean = home.findByPrimaryKey(key); 321 } 322 long end = System.currentTimeMillis(); 323 long elapsed = end - start; 324 getLog().debug(iterationCount+" findByPrimaryKey() invocations = "+elapsed+" ms, "+(elapsed / iterationCount)+" ms/findByPrimaryKey"); 325 } 326 327 public static Test suite() throws Exception 328 { 329 TestSuite suite = new TestSuite(); 330 suite.addTest(new TestSuite(PerfStressTestCase.class)); 331 332 Setup wrapper = new Setup(suite, "perf.jar", false); 334 return wrapper; 335 } 336 337 } 338 | Popular Tags |