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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/performance/spring/rmi/MultiThreadedSpringRMIPerformanceClient.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.rmi;
 
10
 
 
11
import java.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.synchronous.MultiThreadedPerformanceClientTest;
 
17
import org.jboss.test.remoting.performance.synchronous.PerformanceCallbackKeeper;
 
18
import org.springframework.beans.factory.BeanFactory;
 
19
import org.springframework.beans.factory.xml.XmlBeanFactory;
 
20
import org.springframework.context.ApplicationContext;
 
21
import org.springframework.context.support.FileSystemXmlApplicationContext;
 
22
import org.springframework.core.io.ClassPathResource;
 
23
import org.springframework.core.io.Resource;
 
24
import org.springframework.remoting.rmi.RmiServiceExporter;
 
25
 
 
26
import java.rmi.server.UID;
 
27
import java.util.Map;
 
28
 
 
29
/**
 
30
 * @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
 
31
 */
 
32
public class MultiThreadedSpringRMIPerformanceClient extends MultiThreadedPerformanceClientTest
 
33
{
 
34
   private SpringRMIServer springRMIServerService;
 
35
   private String clientSessionId = new UID().toString();
 
36
 
 
37
   protected static final Logger log = Logger.getLogger(MultiThreadedSpringRMIPerformanceClient.class);
 
38
 
 
39
   public static Test suite()
 
40
   {
 
41
      return new ThreadLocalDecorator(MultiThreadedSpringRMIPerformanceClient.class, 1);
 
42
   }
 
43
 
 
44
   public SpringRMIServer getSpringRMIServerService()
 
45
   {
 
46
      return springRMIServerService;
 
47
   }
 
48
 
 
49
   public void setSpringRMIServerService(SpringRMIServer springRMIServerService)
 
50
   {
 
51
      this.springRMIServerService = springRMIServerService;
 
52
   }
 
53
 
 
54
   public void init()
 
55
   {
 
56
 
 
57
      Resource res = new ClassPathResource("SpringRMIClientService.xml", SpringRMIPerformanceClient.class);
 
58
      BeanFactory factory = new XmlBeanFactory(res);
 
59
      springRMIServerService = (SpringRMIServer)factory.getBean("springRMIServerService");
 
60
 
 
61
      /*
 
62
      //super.init();
 
63
 
 
64
      String name = "//localhost/RMIServer";
 
65
//         RMIServer svr = (RMIServer) Naming.lookup(name);
 
66
 
 
67
      try
 
68
      {
 
69
         //Registry regsitry = LocateRegistry.getRegistry("localhost", rmiPort);
 
70
         Registry regsitry = LocateRegistry.getRegistry(rmiPort);
 
71
         Remote remoteObj = regsitry.lookup(name);
 
72
         rmiServer = (RMIServerRemote) remoteObj;
 
73
      }
 
74
      catch(Exception e)
 
75
      {
 
76
         log.error("Error initializating rmi client.", e);
 
77
      }
 
78
      */
 
79
   }
 
80
 
 
81
   /**
 
82
    * This will be used to create callback server
 
83
    *
 
84
    * @param port
 
85
    * @return
 
86
    * @throws Exception
 
87
    */
 
88
   protected InvokerLocator initServer(int port) throws Exception
 
89
   {
 
90
      return null;
 
91
   }
 
92
 
 
93
   protected PerformanceCallbackKeeper addCallbackListener(String sessionId, Latch serverDoneLock)
 
94
         throws Throwable
 
95
   {
 
96
      String springServiceXml = this.getClass().getResource("SpringRMIClientService.xml").getFile();
 
97
 
 
98
//      ApplicationContext context = new FileSystemXmlApplicationContext(springServiceXml);
 
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
      SpringRMICallbackServer callbackServer = (SpringRMICallbackServer) context.getBean("springRMICallbackServerService");
 
115
      callbackServer.setClientSessionId(clientSessionId);
 
116
      callbackServer.setServerDoneLock(serverDoneLock);
 
117
     
 
118
/*
 
119
      Instead of exporting callback servers by injection, the following xml declaration is
 
120
      carried out programmatically.  Each callback server is registered under a name
 
121
      ending in the sessionId.
 
122
    
 
123
   <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
 
124
      <property name="serviceName" value="SpringRMICallbackServerService"/>
 
125
      <property name="service" ref="springRMICallbackServerService"/>
 
126
      <!--<property name="servicePort" value="1300"/>-->
 
127
      <property name="serviceInterface" value="org.jboss.test.remoting.performance.spring.rmi.SpringRMICallbackServer"/>
 
128
      <property name="registryPort" value="1299"/>
 
129
   </bean> 
 
130
*/
 
131
      for (int i = 0; i < 10; i++)
 
132
      {
 
133
         try
 
134
         {
 
135
            RmiServiceExporter exporter = new RmiServiceExporter();
 
136
            exporter.setServiceName("SpringRMICallbackServerService:" + clientSessionId);
 
137
            exporter.setService(callbackServer);
 
138
            exporter.setServiceInterface(org.jboss.test.remoting.performance.spring.rmi.SpringRMICallbackServer.class);
 
139
            exporter.setRegistryPort(1299);
 
140
            exporter.afterPropertiesSet();
 
141
            log.info("exported SpringRMICallbackServerService:" + clientSessionId);
 
142
            break;
 
143
         }
 
144
         catch (Exception e)
 
145
         {
 
146
            Thread.sleep(2000);
 
147
         }
 
148
      }
 
149
      
 
150
      return callbackServer;
 
151
 
 
152
//      RMICallbackServer callbackServer = new RMICallbackServer(clientSessionId, serverDoneLock);
 
153
//      callbackServer.start();
 
154
//      return callbackServer;
 
155
   }
 
156
 
 
157
   protected void populateMetadata(Map metadata)
 
158
   {
 
159
      super.populateMetadata(metadata);
 
160
      metadata.put("transport", "spring_rmi");
 
161
      metadata.put("serialization", "java");
 
162
   }
 
163
 
 
164
   protected Object getBenchmarkAlias()
 
165
   {
 
166
      String config = System.getProperty("alias");
 
167
      if(config == null || config.length() == 0)
 
168
      {
 
169
         config = System.getProperty("jboss-junit-configuration");
 
170
         if(config == null || config.length() == 0)
 
171
         {
 
172
            config = "spring_rmi" + "_" + getNumberOfCalls() + "_" + getPayloadSize() + "_" + "java";
 
173
         }
 
174
      }
 
175
      return config;
 
176
   }
 
177
 
 
178
 
 
179
   protected Object makeInvocation(String method, Object param) throws Throwable
 
180
   {
 
181
      if(method.equals(NUM_OF_CALLS))
 
182
      {
 
183
         return springRMIServerService.sendNumberOfCalls(clientSessionId, param);
 
184
      }
 
185
      else if(method.equals(TEST_INVOCATION))
 
186
      {
 
187
         return springRMIServerService.makeCall(clientSessionId, param);
 
188
      }
 
189
      else
 
190
      {
 
191
         throw new Exception("Was not able to find remote method call for " + method);
 
192
      }
 
193
   }
 
194
 
 
195
   public static void main(String[] args)
 
196
   {
 
197
      MultiThreadedPerformanceClientTest test = new MultiThreadedSpringRMIPerformanceClient();
 
198
      try
 
199
      {
 
200
         test.setUp();
 
201
         test.testClientCalls();
 
202
         test.tearDown();
 
203
      }
 
204
      catch(Throwable throwable)
 
205
      {
 
206
         throwable.printStackTrace();
 
207
      }
 
208
   }
 
209
 
 
210
 
 
211
}