User: starksm 
  Date: 02/02/16 13:14:56

  Modified:    src/main/org/jboss/test/perf/ejb ClientSessionBean.java
  Added:       src/main/org/jboss/test/perf/ejb PerfTestSessionBean.java
  Log:
  Add standard unit test of in-VM remote vs local interface overhead
  
  Revision  Changes    Path
  1.4       +2 -1      
jbosstest/src/main/org/jboss/test/perf/ejb/ClientSessionBean.java
  
  Index: ClientSessionBean.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/perf/ejb/ClientSessionBean.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ClientSessionBean.java    15 Feb 2002 06:15:55 -0000      1.3
  +++ ClientSessionBean.java    16 Feb 2002 21:14:55 -0000      1.4
  @@ -1,5 +1,4 @@
   package org.jboss.test.perf.ejb;
  -// SessionBean.java
   
   import java.rmi.RemoteException;
   import java.rmi.ServerException;
  @@ -15,6 +14,8 @@
   
   /** An implementation of the Session interface that delegates its calls
    to the SessionBean implementation to test session to session bean timings.
  +
  +@version $Revision: 1.4 $
   */
   public class ClientSessionBean implements javax.ejb.SessionBean
   {
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/perf/ejb/PerfTestSessionBean.java
  
  Index: PerfTestSessionBean.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.test.perf.ejb;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.io.StringWriter;
  import java.text.NumberFormat;
  import javax.naming.InitialContext;
  
  import org.jboss.test.perf.interfaces.Probe;
  import org.jboss.test.perf.interfaces.ProbeHome;
  import org.jboss.test.perf.interfaces.ProbeLocal;
  import org.jboss.test.perf.interfaces.ProbeLocalHome;
  import org.jboss.test.util.ejb.SessionSupport;
  
  /** A session bean that tests intra-VM EJB call invocation overhead. The
  runProbeTests method accepts the number of iterations and returns a simple
  html report showing the output of each test run against the Probe session.
   
  @author [EMAIL PROTECTED]
  @version $Revision: 1.1 $
  */
  public class PerfTestSessionBean extends SessionSupport 
  {
     private static NumberFormat fmt = NumberFormat.getInstance();
     static
     {
        fmt.setMinimumFractionDigits(3);
        fmt.setMaximumFractionDigits(3);
     }
  
     /** Run the unit tests using Probe and return a report as a string
      */
     public String runProbeTests(int iterationCount)
     {
        StringBuffer results = new 
StringBuffer("<h1>runProbeTests("+iterationCount+")</h1><pre>\n");
        int testCount = 0;
        int failureCount = 0;
  
        try
        {
           testCount ++;
           testProbeTimings(iterationCount, results);
        }
        catch(Throwable e)
        {
           failureCount ++;
           formatException(e, "testTimings", results);
        }
        results.append('\n');
  
        results.append("\nTotal tests: "+testCount);
        results.append("\nTotal failures: "+failureCount);
        results.append("\n</pre>");
  
        return results.toString();
     }
     /** Run the unit tests using ProbeLocal and return a report as a string
      */
     public String runProbeLocalTests(int iterationCount)
     {
        StringBuffer results = new 
StringBuffer("<h1>runProbeLocalTests("+iterationCount+")</h1><pre>\n");
        int testCount = 0;
        int failureCount = 0;
  
        try
        {
           testCount ++;
           testProbeLocalTimings(iterationCount, results);
        }
        catch(Throwable e)
        {
           failureCount ++;
           formatException(e, "testTimings", results);
        }
        results.append('\n');
  
        results.append("\nTotal tests: "+testCount);
        results.append("\nTotal failures: "+failureCount);
        results.append("\n</pre>");
  
        return results.toString();
     }
  
     private void testProbeTimings(int iterationCount, StringBuffer results) throws 
Exception
     {
        results.append("\n+++ testTimings()");
        Object obj = new InitialContext().lookup("java:comp/env/ejb/ProbeHome");
        Class homeClass = obj.getClass();         
        ProbeHome home = (ProbeHome) obj;
        results.append("\nFound ProbeHome");
        Probe bean = home.create();
        results.append("\nCreated Probe");
        warmup(bean, results);
        noop(bean, iterationCount, results);
        ping(bean, iterationCount, results);
        echo(bean, iterationCount, results);
     }
     private void testProbeLocalTimings(int iterationCount, StringBuffer results) 
throws Exception
     {
        results.append("\n+++ testTimings()");
        Object obj = new InitialContext().lookup("java:comp/env/ejb/ProbeLocalHome");
        Class homeClass = obj.getClass();         
        ProbeLocalHome home = (ProbeLocalHome) obj;
        results.append("\nFound ProbeLocalHome");
        ProbeLocal bean = home.create();
        results.append("\nCreated ProbeLocal");
        warmup(bean, results);
        noop(bean, iterationCount, results);
        ping(bean, iterationCount, results);
        echo(bean, iterationCount, results);
     }
  
     private void warmup(Probe bean, StringBuffer results) throws Exception
     {
        bean.noop();
        bean.ping("Ping");
        bean.echo("Echo");
     }
     private void warmup(ProbeLocal bean, StringBuffer results) throws Exception
     {
        bean.noop();
        bean.ping("Ping");
        bean.echo("Echo");
     }
     private void noop(Probe bean, int iterationCount, StringBuffer results) throws 
Exception
     {
        results.append("\nStarting "+iterationCount+" noop() invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < iterationCount; n ++)
           bean.noop();
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        float avgTime = elapsed;
        avgTime /= iterationCount;
        results.append("\n"+iterationCount+" noop() invocations = "+elapsed+" ms, "
           + fmt.format(avgTime)+" ms/noop");
     }
     private void noop(ProbeLocal bean, int iterationCount, StringBuffer results) 
throws Exception
     {
        results.append("\nStarting "+iterationCount+" noop() invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < iterationCount; n ++)
           bean.noop();
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        float avgTime = elapsed;
        avgTime /= iterationCount;
        results.append("\n"+iterationCount+" noop() invocations = "+elapsed+" ms, "
           + fmt.format(avgTime)+" ms/noop");
     }
  
     private void ping(Probe bean, int iterationCount, StringBuffer results) throws 
Exception
     {
        results.append("\nStarting "+iterationCount+" ping(PING) invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < iterationCount; n ++)
           bean.ping("PING");
        long end = System.currentTimeMillis();
        long elapsed = end - start;      
        float avgTime = elapsed;
        avgTime /= iterationCount;
        results.append("\n"+iterationCount+" ping() invocations = "+elapsed+" ms, "
           + fmt.format(avgTime)+" ms/ping");
     }
     private void ping(ProbeLocal bean, int iterationCount, StringBuffer results) 
throws Exception
     {
        results.append("\nStarting "+iterationCount+" ping(PING) invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < iterationCount; n ++)
           bean.ping("PING");
        long end = System.currentTimeMillis();
        long elapsed = end - start;      
        float avgTime = elapsed;
        avgTime /= iterationCount;
        results.append("\n"+iterationCount+" ping() invocations = "+elapsed+" ms, "
           + fmt.format(avgTime)+" ms/ping");
     }
  
     private void echo(Probe bean, int iterationCount, StringBuffer results) throws 
Exception
     {
        results.append("\nStarting "+iterationCount+" echo(ECHO) invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < iterationCount; n ++)
        {
           String echo = bean.echo("ECHO");
        }
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        float avgTime = elapsed;
        avgTime /= iterationCount;
        results.append("\n"+iterationCount+" echo() invocations = "+elapsed+" ms, "
           + fmt.format(avgTime)+" ms/echo");
     }
     private void echo(ProbeLocal bean, int iterationCount, StringBuffer results) 
throws Exception
     {
        results.append("\nStarting "+iterationCount+" echo(ECHO) invocations");
        long start = System.currentTimeMillis();
        for(int n = 0; n < iterationCount; n ++)
        {
           String echo = bean.echo("ECHO");
        }
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        float avgTime = elapsed;
        avgTime /= iterationCount;
        results.append("\n"+iterationCount+" echo() invocations = "+elapsed+" ms, "
           + fmt.format(avgTime)+" ms/echo");
     }
  
     private void formatException(Throwable t, String testName, StringBuffer results)
     {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        t.printStackTrace(pw);
        results.append("\n"+testName+" failed:\n");
        results.append(sw.toString());
     }
  
  }
  
  
  

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

Reply via email to