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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/invoker/InvokerDestructionTest.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
package org.jboss.test.remoting.invoker;
 
2
 
 
3
 
 
4
import java.net.InetAddress;
 
5
import java.util.HashMap;
 
6
import java.util.Map;
 
7
 
 
8
import javax.management.MBeanServer;
 
9
 
 
10
import junit.framework.TestCase;
 
11
 
 
12
import org.apache.log4j.ConsoleAppender;
 
13
import org.apache.log4j.Level;
 
14
import org.apache.log4j.Logger;
 
15
import org.apache.log4j.PatternLayout;
 
16
import org.jboss.logging.XLevel;
 
17
import org.jboss.remoting.Client;
 
18
import org.jboss.remoting.InvocationRequest;
 
19
import org.jboss.remoting.InvokerLocator;
 
20
import org.jboss.remoting.ServerInvocationHandler;
 
21
import org.jboss.remoting.ServerInvoker;
 
22
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
23
import org.jboss.remoting.transport.Connector;
 
24
import org.jboss.remoting.transport.PortUtil;
 
25
 
 
26
 
 
27
/**
 
28
 * Demonstrates the cost of recreating a client invoker with each invocation.
 
29
 * See JBREM-877.
 
30
 * 
 
31
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
32
 * @version $Revision: 1.1 $
 
33
 * <p>
 
34
 * Copyright Feb 23, 2008
 
35
 * </p>
 
36
 */
 
37
public class InvokerDestructionTest extends TestCase
 
38
{
 
39
   private static Logger log = Logger.getLogger(InvokerDestructionTest.class);
 
40
   
 
41
   private static boolean firstTime = true;
 
42
   protected static String metadata;
 
43
   
 
44
   protected String host;
 
45
   protected int port;
 
46
   protected String locatorURI;
 
47
   protected InvokerLocator serverLocator;
 
48
   protected Connector connector;
 
49
   protected TestInvocationHandler invocationHandler;
 
50
 
 
51
   
 
52
   public void setUp() throws Exception
 
53
   {
 
54
      if (firstTime)
 
55
      {
 
56
         firstTime = false;
 
57
         Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
 
58
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
 
59
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
 
60
         PatternLayout layout = new PatternLayout(pattern);
 
61
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
 
62
         Logger.getRootLogger().addAppender(consoleAppender);
 
63
         metadata = System.getProperty("remoting.metadata", "serializationtype=java");
 
64
      }
 
65
   }
 
66
 
 
67
   
 
68
   public void tearDown()
 
69
   {
 
70
   }
 
71
   
 
72
 
 
73
   
 
74
   public void testNoDelay() throws Throwable
 
75
   {
 
76
      log.info("entering " + getName());
 
77
      
 
78
      // Start server.
 
79
      setupServer(0);
 
80
      
 
81
      // Create client.
 
82
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
 
83
      HashMap clientConfig = new HashMap();
 
84
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
85
      addExtraClientConfig(clientConfig);
 
86
      
 
87
      long l1 = doTest(clientLocator, clientConfig, 10000);
 
88
      log.info("delay 0: " + l1);
 
89
      
 
90
      shutdownServer();
 
91
      log.info(getName() + " PASSES");
 
92
   }
 
93
 
 
94
   
 
95
   public void testDelay() throws Throwable
 
96
   {
 
97
      log.info("entering " + getName());
 
98
      
 
99
      // Start server.
 
100
      setupServer(5000);
 
101
      
 
102
      // Create client.
 
103
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
 
104
      HashMap clientConfig = new HashMap();
 
105
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
106
      addExtraClientConfig(clientConfig);
 
107
      
 
108
      long l1 = doTest(clientLocator, clientConfig, 10000);
 
109
      log.info("delay 5000: " + l1);
 
110
      
 
111
      shutdownServer();
 
112
      log.info(getName() + " PASSES");
 
113
   }
 
114
   
 
115
   
 
116
   protected long doTest(InvokerLocator locator, Map config, int count) throws Throwable
 
117
   {
 
118
      long start = System.currentTimeMillis();
 
119
      for (int i = 0; i < count; i++)
 
120
      {
 
121
         Client client = new Client(locator, config);
 
122
         client.connect();
 
123
         client.invoke("abc");
 
124
         client.disconnect();
 
125
      }
 
126
      return System.currentTimeMillis() - start;
 
127
   }
 
128
   
 
129
   protected String getTransport()
 
130
   {
 
131
      return "socket";
 
132
   }
 
133
   
 
134
   
 
135
   protected void addExtraClientConfig(Map config) {}
 
136
   protected void addExtraServerConfig(Map config) {}
 
137
   
 
138
 
 
139
   protected void setupServer(int delay) throws Exception
 
140
   {
 
141
      host = InetAddress.getLocalHost().getHostAddress();
 
142
      port = PortUtil.findFreePort(host);
 
143
      locatorURI = getTransport() + "://" + host + ":" + port;
 
144
      locatorURI += "/?" + Client.INVOKER_DESTRUCTION_DELAY + "=" + delay;
 
145
      serverLocator = new InvokerLocator(locatorURI);
 
146
      log.info("Starting remoting server with locator uri of: " + locatorURI);
 
147
      HashMap config = new HashMap();
 
148
      config.put(InvokerLocator.FORCE_REMOTE, "true");
 
149
      addExtraServerConfig(config);
 
150
      connector = new Connector(serverLocator, config);
 
151
      connector.create();
 
152
      invocationHandler = new TestInvocationHandler();
 
153
      connector.addInvocationHandler("test", invocationHandler);
 
154
      connector.start();
 
155
   }
 
156
   
 
157
   
 
158
   protected void shutdownServer() throws Exception
 
159
   {
 
160
      if (connector != null)
 
161
         connector.stop();
 
162
   }
 
163
   
 
164
   
 
165
   static class TestInvocationHandler implements ServerInvocationHandler
 
166
   {
 
167
      public void addListener(InvokerCallbackHandler callbackHandler) {}
 
168
      public Object invoke(final InvocationRequest invocation) throws Throwable
 
169
      {
 
170
         return invocation.getParameter();
 
171
      }
 
172
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
 
173
      public void setMBeanServer(MBeanServer server) {}
 
174
      public void setInvoker(ServerInvoker invoker) {}
 
175
   }
 
176
}
 
 
b'\\ No newline at end of file'