~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/performance/spring/http/client/SpringHttpPerformanceClient.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************
2
 
 *                                     *
3
 
 *  JBoss: The OpenSource J2EE WebOS   *
4
 
 *                                     *
5
 
 *  Distributable under LGPL license.  *
6
 
 *  See terms of license at gnu.org.   *
7
 
 *                                     *
8
 
 ***************************************/
9
 
package org.jboss.test.remoting.performance.spring.http.client;
10
 
 
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;
26
 
 
27
 
import java.rmi.server.UID;
28
 
import java.util.Map;
29
 
 
30
 
/**
31
 
 * @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
32
 
 */
33
 
public class SpringHttpPerformanceClient extends PerformanceClientTest
34
 
{
35
 
 
36
 
   private SpringHttpServer springHttpServerService;
37
 
   private String clientSessionId = new UID().toString();
38
 
 
39
 
   protected static final Logger log = Logger.getLogger(SpringHttpPerformanceClient.class);
40
 
 
41
 
   public static Test suite()
42
 
   {
43
 
      return new ThreadLocalDecorator(SpringHttpPerformanceClient.class, 1);
44
 
   }
45
 
 
46
 
   public SpringHttpServer getSpringHttpServerService()
47
 
   {
48
 
      return springHttpServerService;
49
 
   }
50
 
 
51
 
   public void setSpringHttpServerService(SpringHttpServer springHttpServerService)
52
 
   {
53
 
      this.springHttpServerService = springHttpServerService;
54
 
   }
55
 
 
56
 
   public void init()
57
 
   {
58
 
 
59
 
      Resource res = new ClassPathResource("SpringHttpClientService.xml", SpringHttpPerformanceClient.class);
60
 
      BeanFactory factory = new XmlBeanFactory(res);
61
 
      springHttpServerService = (SpringHttpServer)factory.getBean("springHttpServerService");
62
 
 
63
 
 
64
 
      /*
65
 
      try
66
 
      {
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();
73
 
      }
74
 
      catch (MalformedURLException e)
75
 
      {
76
 
         e.printStackTrace();
77
 
      }
78
 
      */
79
 
 
80
 
   }
81
 
 
82
 
   /**
83
 
    * This will be used to create callback server
84
 
    *
85
 
    * @param port
86
 
    * @return
87
 
    * @throws Exception
88
 
    */
89
 
   protected InvokerLocator initServer(int port) throws Exception
90
 
   {
91
 
      return null;
92
 
   }
93
 
 
94
 
   protected PerformanceCallbackKeeper addCallbackListener(String sessionId, Latch serverDoneLock)
95
 
         throws Throwable
96
 
   {
97
 
      String springServiceXml = this.getClass().getResource("SpringHttpClientService.xml").getFile();
98
 
 
99
 
      ApplicationContext context = null;
100
 
      for (int i = 0; i < 10; i++)
101
 
      {
102
 
         try
103
 
         {
104
 
            context = new FileSystemXmlApplicationContext(springServiceXml);
105
 
            if (context != null)
106
 
               break;
107
 
         }
108
 
         catch (Exception e)
109
 
         {
110
 
            Thread.sleep(2000);
111
 
         }
112
 
      }
113
 
      
114
 
      if (context == null)
115
 
      {
116
 
         log.error("unable to create FileSystemXmlApplicationContext from SpringHttpClientService.xml");
117
 
         throw new Exception("unable to create FileSystemXmlApplicationContext from SpringHttpClientService.xml");
118
 
      }
119
 
      
120
 
      SpringHttpCallbackServer callbackServer = (SpringHttpCallbackServer) context.getBean("springHttpCallbackServerService");
121
 
      callbackServer.setClientSessionId(clientSessionId);
122
 
      callbackServer.setServerDoneLock(serverDoneLock);
123
 
      
124
 
/*
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.
128
 
    
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"/>
135
 
   </bean> 
136
 
*/
137
 
      for (int i = 0; i < 10; i++)
138
 
      {
139
 
         try
140
 
         {
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);
148
 
            break;
149
 
         }
150
 
         catch (Exception e)
151
 
         {
152
 
            Thread.sleep(2000);
153
 
         }
154
 
      }
155
 
      
156
 
      return callbackServer;
157
 
 
158
 
//      RMICallbackServer callbackServer = new RMICallbackServer(clientSessionId, serverDoneLock);
159
 
//      callbackServer.start();
160
 
//      return callbackServer;
161
 
   }
162
 
 
163
 
   protected void populateMetadata(Map metadata)
164
 
   {
165
 
      super.populateMetadata(metadata);
166
 
      metadata.put("transport", "spring_http");
167
 
      metadata.put("serialization", "java");
168
 
   }
169
 
 
170
 
   protected Object getBenchmarkAlias()
171
 
   {
172
 
      String config = System.getProperty("alias");
173
 
      if(config == null || config.length() == 0)
174
 
      {
175
 
         config = System.getProperty("jboss-junit-configuration");
176
 
         if(config == null || config.length() == 0)
177
 
         {
178
 
            config = "spring_http" + "_" + getNumberOfCalls() + "_" + getPayloadSize() + "_" + "java";
179
 
         }
180
 
      }
181
 
      return config;
182
 
   }
183
 
 
184
 
 
185
 
   protected Object makeInvocation(String method, Object param) throws Throwable
186
 
   {
187
 
      while (true)
188
 
      {
189
 
         try
190
 
         {
191
 
            if(method.equals(NUM_OF_CALLS))
192
 
            {
193
 
               return springHttpServerService.sendNumberOfCalls(clientSessionId, param);
194
 
            }
195
 
            else if(method.equals(TEST_INVOCATION))
196
 
            {
197
 
               return springHttpServerService.makeCall(clientSessionId, param);
198
 
            }
199
 
            else
200
 
            {
201
 
               throw new Exception("Was not able to find remote method call for " + method);
202
 
            }
203
 
         }
204
 
         catch (Exception e)
205
 
         {
206
 
            log.error("invocation error: " + e);
207
 
         }
208
 
      }
209
 
   }
210
 
 
211
 
   public static void main(String[] args)
212
 
   {
213
 
      SpringHttpPerformanceClient test = new SpringHttpPerformanceClient();
214
 
      try
215
 
      {
216
 
         test.setUp();
217
 
         test.testClientCalls();
218
 
         test.tearDown();
219
 
      }
220
 
      catch(Throwable throwable)
221
 
      {
222
 
         throwable.printStackTrace();
223
 
      }
224
 
   }
225
 
 
226
 
}