1
/***************************************
3
* JBoss: The OpenSource J2EE WebOS *
5
* Distributable under LGPL license. *
6
* See terms of license at gnu.org. *
8
***************************************/
9
package org.jboss.test.remoting.performance.spring.hessian.client;
11
import EDU.oswego.cs.dl.util.concurrent.Latch;
12
import junit.framework.Test;
13
import org.jboss.jrunit.decorators.ThreadLocalDecorator;
14
import org.jboss.logging.Logger;
15
import org.jboss.remoting.InvokerLocator;
16
import org.jboss.test.remoting.performance.spring.hessian.web.SpringHessianServer;
17
import org.jboss.test.remoting.performance.synchronous.PerformanceCallbackKeeper;
18
import org.jboss.test.remoting.performance.synchronous.PerformanceClientTest;
19
import org.springframework.context.ApplicationContext;
20
import org.springframework.context.support.FileSystemXmlApplicationContext;
21
import org.springframework.remoting.caucho.HessianProxyFactoryBean;
23
import java.net.MalformedURLException;
24
import java.rmi.server.UID;
28
* @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
30
public class SpringHessianPerformanceClient extends PerformanceClientTest
33
private SpringHessianServer springHessianServerService;
34
private String clientSessionId = new UID().toString();
36
protected static final Logger log = Logger.getLogger(SpringHessianPerformanceClient.class);
38
public static Test suite()
40
return new ThreadLocalDecorator(SpringHessianPerformanceClient.class, 1);
43
public SpringHessianServer getSpringHessianServerService()
45
return springHessianServerService;
48
public void setSpringHessianServerService(SpringHessianServer springHessianServerService)
50
this.springHessianServerService = springHessianServerService;
56
// Resource res = new ClassPathResource("SpringRMIClientService.xml", SpringHessianPerformanceClient.class);
57
// BeanFactory factory = new XmlBeanFactory(res);
58
// springHessianServerService = (SpringHessianServer)factory.getBean("springRMIServerService");
63
HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
64
factory.setServiceInterface(SpringHessianServer.class);
65
factory.setServiceUrl("http://localhost:8080/remoting/springHessianServerService");
66
factory.afterPropertiesSet();
67
springHessianServerService = (SpringHessianServer) factory.getObject();
68
if (false) throw new MalformedURLException("xxx");
70
catch (MalformedURLException e)
78
* This will be used to create callback server
84
protected InvokerLocator initServer(int port) throws Exception
89
protected PerformanceCallbackKeeper addCallbackListener(String sessionId, Latch serverDoneLock)
92
String springServiceXml = this.getClass().getResource("SpringHessianClientService.xml").getFile();
94
ApplicationContext context = new FileSystemXmlApplicationContext(springServiceXml);
95
SpringHessianCallbackServer callbackServer = (SpringHessianCallbackServer) context.getBean("springHessianCallbackServerService");
96
callbackServer.setClientSessionId(clientSessionId);
97
callbackServer.setServerDoneLock(serverDoneLock);
98
return callbackServer;
100
// RMICallbackServer callbackServer = new RMICallbackServer(clientSessionId, serverDoneLock);
101
// callbackServer.start();
102
// return callbackServer;
105
protected void populateMetadata(Map metadata)
107
super.populateMetadata(metadata);
108
metadata.put("transport", "spring_hessian");
109
metadata.put("serialization", "java");
112
protected Object getBenchmarkAlias()
114
String config = System.getProperty("alias");
115
if(config == null || config.length() == 0)
117
config = System.getProperty("jboss-junit-configuration");
118
if(config == null || config.length() == 0)
120
config = "spring_hessian" + "_" + getNumberOfCalls() + "_" + getPayloadSize() + "_" + "java";
127
protected Object makeInvocation(String method, Object param) throws Throwable
129
if(method.equals(NUM_OF_CALLS))
131
return springHessianServerService.sendNumberOfCalls(clientSessionId, param);
133
else if(method.equals(TEST_INVOCATION))
135
return springHessianServerService.makeCall(clientSessionId, param);
139
throw new Exception("Was not able to find remote method call for " + method);
143
public static void main(String[] args)
145
SpringHessianPerformanceClient test = new SpringHessianPerformanceClient();
149
test.testClientCalls();
152
catch(Throwable throwable)
154
throwable.printStackTrace();