[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/performance/spring/http/client ...
Tom Elrod
tom.elrod at jboss.com
Mon Aug 14 18:06:34 EDT 2006
User: telrod
Date: 06/08/14 18:06:34
Added: src/tests/org/jboss/test/remoting/performance/spring/http/client
SpringHttpCallbackServer.java
SpringHttpCallbackServerImpl.java
SpringHttpClientService.xml
SpringHttpPerformanceClient.java
Log:
JBREM-578 - add performance benchmark test for spring http transport.
Revision Changes Path
1.1 date: 2006/08/14 22:06:34; author: telrod; state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/performance/spring/http/client/SpringHttpCallbackServer.java
Index: SpringHttpCallbackServer.java
===================================================================
/***************************************
* *
* JBoss: The OpenSource J2EE WebOS *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.org. *
* *
***************************************/
package org.jboss.test.remoting.performance.spring.http.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 SpringHttpCallbackServer extends PerformanceCallbackKeeper, InvokerCallbackHandler
{
public void finishedProcessing(Object obj);
void setClientSessionId(String clientSessionId);
void setServerDoneLock(Latch serverDoneLock);
}
1.1 date: 2006/08/14 22:06:34; author: telrod; state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/performance/spring/http/client/SpringHttpCallbackServerImpl.java
Index: SpringHttpCallbackServerImpl.java
===================================================================
/***************************************
* *
* JBoss: The OpenSource J2EE WebOS *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.org. *
* *
***************************************/
package org.jboss.test.remoting.performance.spring.http.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 SpringHttpCallbackServerImpl implements SpringHttpCallbackServer
{
private String sessionId;
private Latch lock;
private int numberOfCallsProcessed = 0;
private int numberOfDuplicates = 0;
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/14 22:06:34; author: telrod; state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/performance/spring/http/client/SpringHttpClientService.xml
Index: SpringHttpClientService.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 id="springHttpServerService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/remoting/springHttpServerService"/>
<property name="serviceInterface" value="org.jboss.test.remoting.performance.spring.http.web.SpringHttpServer"/>
</bean>
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="serviceName" value="SpringHttpCallbackServerService"/>
<property name="service" ref="springHttpCallbackServerService"/>
<property name="servicePort" value="1300"/>
<property name="serviceInterface" value="org.jboss.test.remoting.performance.spring.http.client.SpringHttpCallbackServer"/>
<property name="registryPort" value="1299"/>
</bean>
<bean id="springHttpCallbackServerService"
class="org.jboss.test.remoting.performance.spring.http.client.SpringHttpCallbackServerImpl">
</bean>
</beans>
1.1 date: 2006/08/14 22:06:34; author: telrod; state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/performance/spring/http/client/SpringHttpPerformanceClient.java
Index: SpringHttpPerformanceClient.java
===================================================================
/***************************************
* *
* JBoss: The OpenSource J2EE WebOS *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.org. *
* *
***************************************/
package org.jboss.test.remoting.performance.spring.http.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.http.web.SpringHttpServer;
import org.jboss.test.remoting.performance.synchronous.PerformanceCallbackKeeper;
import org.jboss.test.remoting.performance.synchronous.PerformanceClientTest;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import java.rmi.server.UID;
import java.util.Map;
/**
* @author <a href="mailto:tom at jboss.org">Tom Elrod</a>
*/
public class SpringHttpPerformanceClient extends PerformanceClientTest
{
private SpringHttpServer springHttpServerService;
private String clientSessionId = new UID().toString();
protected static final Logger log = Logger.getLogger(SpringHttpPerformanceClient.class);
public static Test suite()
{
return new ThreadLocalDecorator(SpringHttpPerformanceClient.class, 1);
}
public SpringHttpServer getSpringHttpServerService()
{
return springHttpServerService;
}
public void setSpringHttpServerService(SpringHttpServer springHttpServerService)
{
this.springHttpServerService = springHttpServerService;
}
public void init()
{
Resource res = new ClassPathResource("SpringHttpClientService.xml", SpringHttpPerformanceClient.class);
BeanFactory factory = new XmlBeanFactory(res);
springHttpServerService = (SpringHttpServer)factory.getBean("springHttpServerService");
/*
try
{
// HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
BurlapProxyFactoryBean factory = new BurlapProxyFactoryBean();
factory.setServiceInterface(SpringHttpServer.class);
factory.setServiceUrl("http://localhost:8080/remoting/springHessianServerService");
factory.afterPropertiesSet();
springHessianServerService = (SpringHttpServer) 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("SpringHttpClientService.xml").getFile();
ApplicationContext context = new FileSystemXmlApplicationContext(springServiceXml);
SpringHttpCallbackServer callbackServer = (SpringHttpCallbackServer) context.getBean("springHttpCallbackServerService");
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_http");
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_http" + "_" + getNumberOfCalls() + "_" + getPayloadSize() + "_" + "java";
}
}
return config;
}
protected Object makeInvocation(String method, Object param) throws Throwable
{
if(method.equals(NUM_OF_CALLS))
{
return springHttpServerService.sendNumberOfCalls(clientSessionId, param);
}
else if(method.equals(TEST_INVOCATION))
{
return springHttpServerService.makeCall(clientSessionId, param);
}
else
{
throw new Exception("Was not able to find remote method call for " + method);
}
}
public static void main(String[] args)
{
SpringHttpPerformanceClient test = new SpringHttpPerformanceClient();
try
{
test.setUp();
test.testClientCalls();
test.tearDown();
}
catch(Throwable throwable)
{
throwable.printStackTrace();
}
}
}
More information about the jboss-cvs-commits
mailing list