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.http.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.http.web.SpringHttpServer;
17
import org.jboss.test.remoting.performance.synchronous.PerformanceCallbackKeeper;
18
import org.jboss.test.remoting.performance.synchronous.PerformanceClientTest;
19
import org.springframework.beans.factory.BeanFactory;
20
import org.springframework.beans.factory.xml.XmlBeanFactory;
21
import org.springframework.context.ApplicationContext;
22
import org.springframework.context.support.FileSystemXmlApplicationContext;
23
import org.springframework.core.io.ClassPathResource;
24
import org.springframework.core.io.Resource;
25
import org.springframework.remoting.rmi.RmiServiceExporter;
27
import java.rmi.server.UID;
31
* @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
33
public class SpringHttpPerformanceClient extends PerformanceClientTest
36
private SpringHttpServer springHttpServerService;
37
private String clientSessionId = new UID().toString();
39
protected static final Logger log = Logger.getLogger(SpringHttpPerformanceClient.class);
41
public static Test suite()
43
return new ThreadLocalDecorator(SpringHttpPerformanceClient.class, 1);
46
public SpringHttpServer getSpringHttpServerService()
48
return springHttpServerService;
51
public void setSpringHttpServerService(SpringHttpServer springHttpServerService)
53
this.springHttpServerService = springHttpServerService;
59
Resource res = new ClassPathResource("SpringHttpClientService.xml", SpringHttpPerformanceClient.class);
60
BeanFactory factory = new XmlBeanFactory(res);
61
springHttpServerService = (SpringHttpServer)factory.getBean("springHttpServerService");
67
// HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
68
BurlapProxyFactoryBean factory = new BurlapProxyFactoryBean();
69
factory.setServiceInterface(SpringHttpServer.class);
70
factory.setServiceUrl("http://localhost:8080/remoting/springHessianServerService");
71
factory.afterPropertiesSet();
72
springHessianServerService = (SpringHttpServer) factory.getObject();
74
catch (MalformedURLException e)
83
* This will be used to create callback server
89
protected InvokerLocator initServer(int port) throws Exception
94
protected PerformanceCallbackKeeper addCallbackListener(String sessionId, Latch serverDoneLock)
97
String springServiceXml = this.getClass().getResource("SpringHttpClientService.xml").getFile();
99
ApplicationContext context = null;
100
for (int i = 0; i < 10; i++)
104
context = new FileSystemXmlApplicationContext(springServiceXml);
116
log.error("unable to create FileSystemXmlApplicationContext from SpringHttpClientService.xml");
117
throw new Exception("unable to create FileSystemXmlApplicationContext from SpringHttpClientService.xml");
120
SpringHttpCallbackServer callbackServer = (SpringHttpCallbackServer) context.getBean("springHttpCallbackServerService");
121
callbackServer.setClientSessionId(clientSessionId);
122
callbackServer.setServerDoneLock(serverDoneLock);
125
Instead of exporting callback servers by injection, the following xml declaration is
126
carried out programmatically. Each callback server is registered under a name
127
ending in the sessionId.
129
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
130
<property name="serviceName" value="SpringHttpCallbackServerService"/>
131
<property name="service" ref="springHttpCallbackServerService"/>
132
<property name="servicePort" value="1300"/>
133
<property name="serviceInterface" value="org.jboss.test.remoting.performance.spring.http.client.SpringHttpCallbackServer"/>
134
<property name="registryPort" value="1299"/>
137
for (int i = 0; i < 10; i++)
141
RmiServiceExporter exporter = new RmiServiceExporter();
142
exporter.setServiceName("SpringHttpCallbackServerService:" + clientSessionId);
143
exporter.setService(callbackServer);
144
exporter.setServiceInterface(org.jboss.test.remoting.performance.spring.http.client.SpringHttpCallbackServer.class);
145
exporter.setRegistryPort(1299);
146
exporter.afterPropertiesSet();
147
log.info("exported SpringHttpCallbackServerService:" + clientSessionId);
156
return callbackServer;
158
// RMICallbackServer callbackServer = new RMICallbackServer(clientSessionId, serverDoneLock);
159
// callbackServer.start();
160
// return callbackServer;
163
protected void populateMetadata(Map metadata)
165
super.populateMetadata(metadata);
166
metadata.put("transport", "spring_http");
167
metadata.put("serialization", "java");
170
protected Object getBenchmarkAlias()
172
String config = System.getProperty("alias");
173
if(config == null || config.length() == 0)
175
config = System.getProperty("jboss-junit-configuration");
176
if(config == null || config.length() == 0)
178
config = "spring_http" + "_" + getNumberOfCalls() + "_" + getPayloadSize() + "_" + "java";
185
protected Object makeInvocation(String method, Object param) throws Throwable
191
if(method.equals(NUM_OF_CALLS))
193
return springHttpServerService.sendNumberOfCalls(clientSessionId, param);
195
else if(method.equals(TEST_INVOCATION))
197
return springHttpServerService.makeCall(clientSessionId, param);
201
throw new Exception("Was not able to find remote method call for " + method);
206
log.error("invocation error: " + e);
211
public static void main(String[] args)
213
SpringHttpPerformanceClient test = new SpringHttpPerformanceClient();
217
test.testClientCalls();
220
catch(Throwable throwable)
222
throwable.printStackTrace();