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.PerfResult; 36 import org.jboss.test.perf.interfaces.PerfTestSession; 37 import org.jboss.test.perf.interfaces.PerfTestSessionHome; 38 import org.jboss.test.perf.interfaces.Probe; 39 import org.jboss.test.perf.interfaces.ProbeHome; 40 41 import org.jboss.test.JBossTestCase; 42 43 50 public class PerfUnitTestCase extends JBossTestCase 51 { 52 int iterationCount; 53 54 public PerfUnitTestCase(String name) 55 { 56 super(name); 57 iterationCount = getIterationCount(); 58 } 59 60 public void testInVMCalls() throws Exception 61 { 62 getLog().debug("+++ testInVMCalls()"); 63 Object obj = getInitialContext().lookup("PerfTestSession"); 64 obj = PortableRemoteObject.narrow(obj, PerfTestSessionHome.class); 65 PerfTestSessionHome home = (PerfTestSessionHome) obj; 66 getLog().debug("Found PerfTestSessionHome @ jndiName=PerfTestSessionHome"); 67 PerfTestSession bean = home.create(); 68 getLog().debug("Created PerfTestSession"); 69 long start = System.currentTimeMillis(); 70 PerfResult result = bean.runProbeTests(iterationCount); 71 String report = result.report; 72 long end = System.currentTimeMillis(); 73 long elapsed = end - start; 74 getLog().debug("Elapsed time = "+(elapsed / iterationCount)); 75 getLog().info("The testInVMCalls report is:\n"+report); 76 if( result.error != null ) 77 throw result.error; 78 } 79 80 public void testInVMLocalCalls() throws Exception 81 { 82 getLog().debug("+++ testInVMLocalCalls()"); 83 Object obj = getInitialContext().lookup("PerfTestSession"); 84 obj = PortableRemoteObject.narrow(obj, PerfTestSessionHome.class); 85 PerfTestSessionHome home = (PerfTestSessionHome) obj; 86 getLog().debug("Found PerfTestSessionHome @ jndiName=PerfTestSessionHome"); 87 PerfTestSession bean = home.create(); 88 getLog().debug("Created PerfTestSession"); 89 long start = System.currentTimeMillis(); 90 PerfResult result = bean.runProbeLocalTests(iterationCount); 91 String report = result.report; 92 long end = System.currentTimeMillis(); 93 long elapsed = end - start; 94 getLog().debug("Elapsed time = "+(elapsed / iterationCount)); 95 getLog().info("The testInVMLocalCalls report is:\n"+report); 96 if( result.error != null ) 97 throw result.error; 98 } 99 100 public static Test suite() throws Exception 101 { 102 Test test = getDeploySetup(PerfUnitTestCase.class, "probe.jar"); 103 return test; 104 } 105 106 } 107 | Popular Tags |