/*
 *
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package org.jboss.ejb3.test.microbench.unit;

//import java.rmi.*;


import junit.framework.Test;
import org.jboss.ejb3.test.microbench.StatelessHomeRemote;
import org.jboss.ejb3.test.microbench.StatelessRemote;
import org.jboss.ejb3.test.microbench.StatelessRemote21;
import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
import org.jboss.test.JBossTestCase;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;

/**
 * Sample client for the jboss container.
 *
 * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
 * @version $Id: BenchUnitTestCase.java,v 1.1.2.5 2005/09/14 22:19:11 bill Exp $
 */

public class BenchUnitTestCase
        extends JBossTestCase
{
   public BenchUnitTestCase(String name)
   {

      super(name);

   }

   public void testLocalBenchmark() throws Exception
   {
	   MBeanServerConnection server = getServer();
      ObjectName testerName = new ObjectName("jboss.ejb3:service=Benchmark");
      Object[] params = {new Integer(100000)};
      String[] sig = {"int"};
      System.out.println("21Local: " + server.invoke(testerName, "benchLocalStateless21", params, sig));
      System.out.println("30Local: " + server.invoke(testerName, "benchLocalStateless30", params, sig));


   }

   public void testRemoteBenchmark() throws Exception
   {
      StatelessRemote remote = (StatelessRemote) getInitialContext().lookup(StatelessRemote.class.getName());
      StatelessHomeRemote home = (StatelessHomeRemote) getInitialContext().lookup("StatelessBean21Remote");
      StatelessRemote21 remote21 = home.create();

      long start = System.currentTimeMillis();
      for (int i = 0; i < 1000; i++)
      {
         remote21.test(i);
      }
      long end = System.currentTimeMillis() - start;
      System.out.println("21Remote: " + end);

      start = System.currentTimeMillis();
      for (int i = 0; i < 1000; i++)
      {
         remote.test(i);
      }
      end = System.currentTimeMillis() - start;
      System.out.println("30Remote: " + end);

   }

   public static Test suite() throws Exception
   {
      return getDeploySetup(BenchUnitTestCase.class, "benchmark-ejb3-test.sar");
   }

}
