[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/performance/spring/hessian/client ...

Tom Elrod tom.elrod at jboss.com
Sun Aug 13 15:30:05 EDT 2006


  User: telrod  
  Date: 06/08/13 15:30:05

  Added:       src/tests/org/jboss/test/remoting/performance/spring/hessian/client    
                        SpringHessianCallbackServer.java
                        SpringHessianCallbackServerImpl.java
                        SpringHessianClientService.xml
                        SpringHessianPerformanceClient.java
  Log:
  JBREM-578 - including spring remoting tests (rmi and hessian transports) to the performance benchmark testing.
  
  Revision  Changes    Path
  1.1      date: 2006/08/13 19:30:05;  author: telrod;  state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/performance/spring/hessian/client/SpringHessianCallbackServer.java
  
  Index: SpringHessianCallbackServer.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  package org.jboss.test.remoting.performance.spring.hessian.client;
  
  import EDU.oswego.cs.dl.util.concurrent.Latch;
  import org.jboss.remoting.callback.InvokerCallbackHandler;
  import org.jboss.test.remoting.performance.synchronous.PerformanceCallbackKeeper;
  
  /**
   * @author <a href="mailto:tom at jboss.org">Tom Elrod</a>
   */
  public interface SpringHessianCallbackServer extends PerformanceCallbackKeeper, InvokerCallbackHandler
  {
      public void finishedProcessing(Object obj);
  
     void setClientSessionId(String clientSessionId);
  
     void setServerDoneLock(Latch serverDoneLock);
  }
  
  
  
  1.1      date: 2006/08/13 19:30:05;  author: telrod;  state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/performance/spring/hessian/client/SpringHessianCallbackServerImpl.java
  
  Index: SpringHessianCallbackServerImpl.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  package org.jboss.test.remoting.performance.spring.hessian.client;
  
  import EDU.oswego.cs.dl.util.concurrent.Latch;
  import org.jboss.remoting.callback.Callback;
  import org.jboss.remoting.callback.HandleCallbackException;
  
  /**
   * @author <a href="mailto:tom at jboss.org">Tom Elrod</a>
   */
  public class SpringHessianCallbackServerImpl implements SpringHessianCallbackServer
  {
     private String sessionId;
     private Latch lock;
     private int numberOfCallsProcessed = 0;
     private int numberOfDuplicates = 0;
  
  
  //   public SpringRMICallbackServerImpl(String sessionId, Latch lock)
  //   {
  //      this.sessionId = sessionId;
  //      this.lock = lock;
  //   }
  
     public void finishedProcessing(Object obj)
     {
        System.out.println("finishedProcessing called with " + obj);
        Callback callback = (Callback)obj;
        try
        {
           handleCallback(callback);
        }
        catch(HandleCallbackException e)
        {
           e.printStackTrace();
        }
     }
  
     public void setClientSessionId(String clientSessionId)
     {
        this.sessionId = clientSessionId;
     }
  
     public void setServerDoneLock(Latch serverDoneLock)
     {
        this.lock = serverDoneLock;
     }
  
     public int getNumberOfCallsProcessed()
     {
        return numberOfCallsProcessed;
     }
  
     public int getNumberOfDuplicates()
     {
        return numberOfDuplicates;
     }
  
     public void handleCallback(Callback callback) throws HandleCallbackException
     {
        Object ret = callback.getCallbackObject();
        Integer[] handledArray = (Integer[])ret;
        Integer numOfCallsHandled = (Integer) handledArray[0];
        Integer numOfDuplicates = (Integer) handledArray[1];
        System.out.println("Server is done.  Number of calls handled: " + numOfCallsHandled);
        numberOfCallsProcessed = numOfCallsHandled.intValue();
        System.out.println("Number of duplicate calls: " + numOfDuplicates);
        numberOfDuplicates = numOfDuplicates.intValue();
        Object obj = callback.getCallbackHandleObject();
        //String handbackObj = (String) obj;
        //System.out.println("Handback object should be " + sessionId + " and server called back with " + handbackObj);
        lock.release();
  
     }
  
  }
  
  
  
  1.1      date: 2006/08/13 19:30:05;  author: telrod;  state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/performance/spring/hessian/client/SpringHessianClientService.xml
  
  Index: SpringHessianClientService.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
  
        "http://www.springframework.org/dtd/spring-beans.dtd">
  
  <beans>
  
     <!--<bean class="org.jboss.test.remoting.performance.spring.rmi.SpringRMIPerformanceClient">-->
        <!--<property name="springRMIServerService" ref="springRMIServerService"/>-->
     <!--</bean>-->
  <!---->
     <!--<bean id="springRMIServerService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">-->
        <!--<property name="serviceUrl" value="rmi://localhost:1199/SpringRMIServerService"/>-->
        <!--<property name="serviceInterface" value="org.jboss.test.remoting.performance.spring.rmi.SpringRMIServer"/>-->
     <!--</bean>-->
  
     <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
        <property name="serviceName" value="SpringHessianCallbackServerService"/>
        <property name="service" ref="springHessianCallbackServerService"/>
        <property name="servicePort" value="1300"/>
        <property name="serviceInterface" value="org.jboss.test.remoting.performance.spring.hessian.client.SpringHessianCallbackServer"/>
        <property name="registryPort" value="1299"/>
     </bean>
  
     <bean id="springHessianCallbackServerService"
           class="org.jboss.test.remoting.performance.spring.hessian.client.SpringHessianCallbackServerImpl">
     </bean>
  
  
  </beans>
  
  
  1.1      date: 2006/08/13 19:30:05;  author: telrod;  state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/performance/spring/hessian/client/SpringHessianPerformanceClient.java
  
  Index: SpringHessianPerformanceClient.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  package org.jboss.test.remoting.performance.spring.hessian.client;
  
  import EDU.oswego.cs.dl.util.concurrent.Latch;
  import junit.framework.Test;
  import org.jboss.jrunit.decorators.ThreadLocalDecorator;
  import org.jboss.logging.Logger;
  import org.jboss.remoting.InvokerLocator;
  import org.jboss.test.remoting.performance.spring.hessian.web.SpringHessianServer;
  import org.jboss.test.remoting.performance.synchronous.PerformanceCallbackKeeper;
  import org.jboss.test.remoting.performance.synchronous.PerformanceClientTest;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.FileSystemXmlApplicationContext;
  import org.springframework.remoting.caucho.HessianProxyFactoryBean;
  
  import java.net.MalformedURLException;
  import java.rmi.server.UID;
  import java.util.Map;
  
  /**
   * @author <a href="mailto:tom at jboss.org">Tom Elrod</a>
   */
  public class SpringHessianPerformanceClient extends PerformanceClientTest
  {
  
     private SpringHessianServer springHessianServerService;
     private String clientSessionId = new UID().toString();
  
     protected static final Logger log = Logger.getLogger(SpringHessianPerformanceClient.class);
  
     public static Test suite()
     {
        return new ThreadLocalDecorator(SpringHessianPerformanceClient.class, 1);
     }
  
     public SpringHessianServer getSpringHessianServerService()
     {
        return springHessianServerService;
     }
  
     public void setSpringHessianServerService(SpringHessianServer springHessianServerService)
     {
        this.springHessianServerService = springHessianServerService;
     }
  
     public void init()
     {
  
  //      Resource res = new ClassPathResource("SpringRMIClientService.xml", SpringHessianPerformanceClient.class);
  //      BeanFactory factory = new XmlBeanFactory(res);
  //      springHessianServerService = (SpringHessianServer)factory.getBean("springRMIServerService");
  
  
        try
        {
           HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
           factory.setServiceInterface(SpringHessianServer.class);
           factory.setServiceUrl("http://localhost:8080/remoting/springHessianServerService");
           factory.afterPropertiesSet();
           springHessianServerService = (SpringHessianServer) factory.getObject();
        }
        catch (MalformedURLException e)
        {
           e.printStackTrace();
        }
  
     }
  
     /**
      * This will be used to create callback server
      *
      * @param port
      * @return
      * @throws Exception
      */
     protected InvokerLocator initServer(int port) throws Exception
     {
        return null;
     }
  
     protected PerformanceCallbackKeeper addCallbackListener(String sessionId, Latch serverDoneLock)
           throws Throwable
     {
        String springServiceXml = this.getClass().getResource("SpringHessianClientService.xml").getFile();
  
        ApplicationContext context = new FileSystemXmlApplicationContext(springServiceXml);
        SpringHessianCallbackServer callbackServer = (SpringHessianCallbackServer) context.getBean("springHessianCallbackServerService");
        callbackServer.setClientSessionId(clientSessionId);
        callbackServer.setServerDoneLock(serverDoneLock);
        return callbackServer;
  
  //      RMICallbackServer callbackServer = new RMICallbackServer(clientSessionId, serverDoneLock);
  //      callbackServer.start();
  //      return callbackServer;
     }
  
     protected void populateMetadata(Map metadata)
     {
        super.populateMetadata(metadata);
        metadata.put("transport", "spring_hessian");
        metadata.put("serialization", "java");
     }
  
     protected Object getBenchmarkAlias()
     {
        String config = System.getProperty("alias");
        if(config == null || config.length() == 0)
        {
           config = System.getProperty("jboss-junit-configuration");
           if(config == null || config.length() == 0)
           {
              config = "spring_hessian" + "_" + getNumberOfCalls() + "_" + getPayloadSize() + "_" + "java";
           }
        }
        return config;
     }
  
  
     protected Object makeInvocation(String method, Object param) throws Throwable
     {
        if(method.equals(NUM_OF_CALLS))
        {
           return springHessianServerService.sendNumberOfCalls(clientSessionId, param);
        }
        else if(method.equals(TEST_INVOCATION))
        {
           return springHessianServerService.makeCall(clientSessionId, param);
        }
        else
        {
           throw new Exception("Was not able to find remote method call for " + method);
        }
     }
  
     public static void main(String[] args)
     {
        SpringHessianPerformanceClient test = new SpringHessianPerformanceClient();
        try
        {
           test.setUp();
           test.testClientCalls();
           test.tearDown();
        }
        catch(Throwable throwable)
        {
           throwable.printStackTrace();
        }
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list