User: starksm 
  Date: 01/07/14 00:34:08

  Added:       src/main/org/jboss/test/perf/test TestPerf.java
  Removed:     src/main/org/jboss/test/perf/test TestProbe.java
  Log:
  Renamed TestProbe to TestPerf
  
  Revision  Changes    Path
  1.1                  jbosstest/src/main/org/jboss/test/perf/test/TestPerf.java
  
  Index: TestPerf.java
  ===================================================================
  package org.jboss.test.perf.test;
  
  import java.io.IOException;
  import java.rmi.RemoteException;
  import javax.ejb.CreateException;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.rmi.PortableRemoteObject;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.jboss.test.perf.interfaces.Entity;
  import org.jboss.test.perf.interfaces.EntityPK;
  import org.jboss.test.perf.interfaces.Entity2PK;
  import org.jboss.test.perf.interfaces.EntityHome;
  import org.jboss.test.perf.interfaces.Entity2Home;
  import org.jboss.test.perf.interfaces.Probe;
  import org.jboss.test.perf.interfaces.ProbeHome;
  import org.jboss.test.perf.interfaces.Session;
  import org.jboss.test.perf.interfaces.SessionHome;
  import org.jboss.test.perf.interfaces.TxSession;
  import org.jboss.test.perf.interfaces.TxSessionHome;
  
  /** Test of EJB call invocation overhead.
   
   @author [EMAIL PROTECTED]
   @version $Revision: 1.1 $
   */
  public class TestPerf extends junit.framework.TestCase
  {
     static int N = 1000;
     
     public TestPerf(String name)
     {
        super(name);
     }
     
     public void testClientSession() throws Exception
     {
        System.out.println("+++ testClientSession()");
        InitialContext jndiContext = new InitialContext();
        Object obj = jndiContext.lookup("ClientSession");
        obj = PortableRemoteObject.narrow(obj, SessionHome.class);
        SessionHome home = (SessionHome) obj;
        System.out.println("Found SessionHome @ jndiName=ClientSession");
        Session bean = home.create("Entity");
        System.out.println("Created ClientSession");
        try
        {
           bean.create(0, 100);
        }
        catch(javax.ejb.CreateException e)
        {
        }
        long start = System.currentTimeMillis();
        bean.read(0);
        bean.read(0, 100);
        bean.write(0);
        bean.write(0, 100);
        bean.remove(0, 100);
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        System.out.println("Elapsed time = "+(elapsed / N));
     }
  
     public void testTimings() throws Exception
     {
        System.out.println("+++ testTimings()");
        InitialContext jndiContext = new InitialContext();
        Object obj = jndiContext.lookup("Probe");
        obj = PortableRemoteObject.narrow(obj, ProbeHome.class);
        ProbeHome home = (ProbeHome) obj;
        System.out.println("Found ProbeHome @ jndiName=Probe");
        Probe bean = home.create();
        System.out.println("Created Probe");
        warmup(bean);
        noop(bean);
        ping(bean);
        echo(bean);
     }
  
     public void testTimingsCMT() throws Exception
     {
        System.out.println("+++ testTimingsCMT()");
        InitialContext jndiContext = new InitialContext();
        Object obj = jndiContext.lookup("ProbeCMT");
        obj = PortableRemoteObject.narrow(obj, ProbeHome.class);
        ProbeHome home = (ProbeHome) obj;
        System.out.println("Found ProbeHome @ jndiName=ProbeCMT");
        Probe bean = home.create();
        System.out.println("Created ProbeCMT");
        warmup(bean);
        noop(bean);
        ping(bean);
        echo(bean);
     }
  
     public void testTxTimings() throws Exception
     {
        System.out.println("+++ testTxTimings()");
        InitialContext jndiContext = new InitialContext();
        Object obj = jndiContext.lookup("TxSession");
        obj = PortableRemoteObject.narrow(obj, TxSessionHome.class);
        TxSessionHome home = (TxSessionHome) obj;
        System.out.println("Found TxSession @ jndiName=TxSession");
        TxSession bean = home.create();
        System.out.println("Created TxSession");
        txRequired(bean);
        txRequiresNew(bean);
        txSupports(bean);
        txNotSupported(bean);
        requiredToSupports(bean);
        requiredToMandatory(bean);
        requiredToRequiresNew(bean);
     }
     public void testFindByPrimaryKey() throws Exception
     {
        System.out.println("+++ testFindByPrimaryKey()");
        InitialContext jndiContext = new InitialContext();
        Object obj = jndiContext.lookup("Entity");
        obj = PortableRemoteObject.narrow(obj, EntityHome.class);
        EntityHome home = (EntityHome) obj;
        System.out.println("Found EntityHome @ jndiName=Entity");
        EntityPK key = new EntityPK(1);
        Entity bean = null;
  
        System.out.println("Running with 1 instance...");
        findByPrimaryKey(key, home);
        System.out.println("Running with 100 instance...");
        findByPrimaryKey(key, home);
        System.out.println("Running with 1000 instance...");
        findByPrimaryKey(key, home);
  /*
        System.out.println("Running with 10000 instance...");
        findByPrimaryKey(key, home);
  */
     }
     public void testFindByPrimaryKey2() throws Exception
     {
        System.out.println("+++ testFindByPrimaryKey2()");
        InitialContext jndiContext = new InitialContext();
        Object obj = jndiContext.lookup("Entity2");
        obj = PortableRemoteObject.narrow(obj, Entity2Home.class);
        Entity2Home home = (Entity2Home) obj;
        System.out.println("Found EntityHome @ jndiName=Entity");
        Entity2PK key = new Entity2PK(1, "String1", new Double(1));
        Entity bean = null;
  
        System.out.println("Running with 1 instance...");
        findByPrimaryKey(key, home);
        System.out.println("Running with 100 instance...");
        findByPrimaryKey(key, home);
        System.out.println("Running with 1000 instance...");
        findByPrimaryKey(key, home);
  /*
        System.out.println("Running with 10000 instance...");
        findByPrimaryKey(key, home);
  */
     }
  
     private void warmup(Probe bean) throws Exception
     {
        bean.noop();
        bean.ping("Ping");
        bean.echo("Echo");
     }
  
     private void noop(Probe bean) throws Exception
     {
        System.out.println("Starting "+N+" noop() invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < N; n ++)
           bean.noop();
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        System.out.println(N+" noop() invocations = "+elapsed+" ms, "+(elapsed / N)+" 
ms/noop");
     }
     private void ping(Probe bean) throws Exception
     {
        System.out.println("Starting "+N+" ping(PING) invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < N; n ++)
           bean.ping("PING");
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        System.out.println(N+" ping() invocations = "+elapsed+" ms, "+(elapsed / N)+" 
ms/noop");
     }
     private void echo(Probe bean) throws Exception
     {
        System.out.println("Starting "+N+" echo(ECHO) invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < N; n ++)
        {
           String echo = bean.echo("ECHO");
        }
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        System.out.println(N+" echo() invocations = "+elapsed+" ms, "+(elapsed / N)+" 
ms/noop");
     }
     private void txRequired(TxSession bean) throws Exception
     {
        System.out.println("Starting "+N+" txRequired() invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < N; n ++)
        {
           String echo = bean.txRequired();
        }
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        System.out.println(N+" txRequired() invocations = "+elapsed+" ms, "+(elapsed / 
N)+" ms/txRequired");
     }
     private void txRequiresNew(TxSession bean) throws Exception
     {
        System.out.println("Starting "+N+" txRequired() invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < N; n ++)
        {
           String echo = bean.txRequiresNew();
        }
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        System.out.println(N+" txRequiresNew() invocations = "+elapsed+" ms, 
"+(elapsed / N)+" ms/txRequiresNew");
     }
     private void txSupports(TxSession bean) throws Exception
     {
        System.out.println("Starting "+N+" txSupports() invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < N; n ++)
        {
           String echo = bean.txSupports();
        }
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        System.out.println(N+" txSupports() invocations = "+elapsed+" ms, "+(elapsed / 
N)+" ms/txSupports");
     }
     private void txNotSupported(TxSession bean) throws Exception
     {
        System.out.println("Starting "+N+" txNotSupported() invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < N; n ++)
        {
           String echo = bean.txNotSupported();
        }
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        System.out.println(N+" txNotSupported() invocations = "+elapsed+" ms, 
"+(elapsed / N)+" ms/txNotSupported");
     }
     private void requiredToSupports(TxSession bean) throws Exception
     {
        System.out.println("Starting "+N+" requiredToSupports() invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < N; n ++)
        {
           String echo = bean.requiredToSupports();
        }
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        System.out.println(N+" requiredToSupports() invocations = "+elapsed+" ms, 
"+(elapsed / N)+" ms/requiredToSupports");
     }
     private void requiredToMandatory(TxSession bean) throws Exception
     {
        System.out.println("Starting "+N+" requiredToMandatory() invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < N; n ++)
        {
           String echo = bean.requiredToMandatory();
        }
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        System.out.println(N+" requiredToMandatory() invocations = "+elapsed+" ms, 
"+(elapsed / N)+" ms/requiredToMandatory");
     }
     private void requiredToRequiresNew(TxSession bean) throws Exception
     {
        System.out.println("Starting "+N+" requiredToRequiresNew() invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < N; n ++)
        {
           String echo = bean.requiredToRequiresNew();
        }
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        System.out.println(N+" requiredToRequiresNew() invocations = "+elapsed+" ms, 
"+(elapsed / N)+" ms/requiredToRequiresNew");
     }
  
     private void findByPrimaryKey(EntityPK key, EntityHome home) throws Exception
     {
        System.out.println("Starting "+N+" findByPrimaryKey(key="+key+") invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < N; n ++)
        {
           Entity bean = home.findByPrimaryKey(key);
        }
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        System.out.println(N+" findByPrimaryKey() invocations = "+elapsed+" ms, 
"+(elapsed / N)+" ms/findByPrimaryKey");
     }
     private void findByPrimaryKey(Entity2PK key, Entity2Home home) throws Exception
     {
        System.out.println("Starting "+N+" findByPrimaryKey(key="+key+") invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < N; n ++)
        {
           Entity bean = home.findByPrimaryKey(key);
        }
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        System.out.println(N+" findByPrimaryKey() invocations = "+elapsed+" ms, 
"+(elapsed / N)+" ms/findByPrimaryKey");
     }
  
     public static Test suite()
     {
        TestSuite suite = new TestSuite();  
        suite.addTest(new TestSuite(TestPerf.class));
  
        // Create an initializer for the test suite
        Setup wrapper = new Setup(suite, "perf.jar", false);
        return wrapper;
     }
  
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to