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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/transport/socket/connectionpool/ConnectionPoolSizeTestCase.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
 
* JBoss, Home of Professional Open Source
3
 
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
 
* by the @authors tag. See the copyright.txt in the distribution for a
5
 
* full listing of individual contributors.
6
 
*
7
 
* This is free software; you can redistribute it and/or modify it
8
 
* under the terms of the GNU Lesser General Public License as
9
 
* published by the Free Software Foundation; either version 2.1 of
10
 
* the License, or (at your option) any later version.
11
 
*
12
 
* This software is distributed in the hope that it will be useful,
13
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
 
* Lesser General Public License for more details.
16
 
*
17
 
* You should have received a copy of the GNU Lesser General Public
18
 
* License along with this software; if not, write to the Free
19
 
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
 
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21
 
*/
22
 
package org.jboss.test.remoting.transport.socket.connectionpool;
23
 
 
24
 
import java.lang.reflect.Field;
25
 
import java.net.InetAddress;
26
 
import java.util.HashMap;
27
 
import java.util.Map;
28
 
 
29
 
import javax.management.MBeanServer;
30
 
 
31
 
import junit.framework.TestCase;
32
 
 
33
 
import org.apache.log4j.ConsoleAppender;
34
 
import org.apache.log4j.Level;
35
 
import org.apache.log4j.Logger;
36
 
import org.apache.log4j.PatternLayout;
37
 
import org.jboss.remoting.Client;
38
 
import org.jboss.remoting.InvocationRequest;
39
 
import org.jboss.remoting.InvokerLocator;
40
 
import org.jboss.remoting.ServerInvocationHandler;
41
 
import org.jboss.remoting.ServerInvoker;
42
 
import org.jboss.remoting.callback.Callback;
43
 
import org.jboss.remoting.callback.HandleCallbackException;
44
 
import org.jboss.remoting.callback.InvokerCallbackHandler;
45
 
import org.jboss.remoting.transport.Connector;
46
 
import org.jboss.remoting.transport.PortUtil;
47
 
import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
48
 
 
49
 
 
50
 
/**
51
 
 * 
52
 
 * Unit test for JBREM-858.
53
 
 * 
54
 
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
55
 
 * @version $Revision: 1.1 $
56
 
 * <p>
57
 
 * Copyright Dec 3, 2007
58
 
 * </p>
59
 
 */
60
 
public class ConnectionPoolSizeTestCase extends TestCase
61
 
{
62
 
   private static Logger log = Logger.getLogger(ConnectionPoolSizeTestCase.class);
63
 
   
64
 
   private static boolean firstTime = true;
65
 
   
66
 
   protected String host;
67
 
   protected int port;
68
 
   protected String locatorURI;
69
 
   protected InvokerLocator serverLocator;
70
 
   protected Connector connector;
71
 
   protected TestInvocationHandler invocationHandler;
72
 
 
73
 
   
74
 
   public void setUp() throws Exception
75
 
   {
76
 
      if (firstTime)
77
 
      {
78
 
         firstTime = false;
79
 
         Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
80
 
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
81
 
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
82
 
         PatternLayout layout = new PatternLayout(pattern);
83
 
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
84
 
         Logger.getRootLogger().addAppender(consoleAppender);  
85
 
      }
86
 
   }
87
 
 
88
 
   
89
 
   public void tearDown()
90
 
   {
91
 
   }
92
 
   
93
 
   
94
 
   public void testClientMaxPoolSizeInConnectionPoolKey() throws Throwable
95
 
   {
96
 
      log.info("entering " + getName());
97
 
      
98
 
      // Start server.
99
 
      setupServer();
100
 
      
101
 
      // Create clients.
102
 
      InvokerLocator clientLocator1 = new InvokerLocator(locatorURI + "/?" + MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG + "=3");
103
 
      InvokerLocator clientLocator2 = new InvokerLocator(locatorURI + "/?" + MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG + "=7");
104
 
      HashMap clientConfig = new HashMap();
105
 
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
106
 
      addExtraClientConfig(clientConfig);
107
 
      Client client1 = new Client(clientLocator1, clientConfig);
108
 
      client1.connect();
109
 
      log.info("client1 is connected: " + clientLocator1);
110
 
      Client client2 = new Client(clientLocator2, clientConfig);
111
 
      client2.connect();
112
 
      log.info("client2 is connected: " + clientLocator2);
113
 
      
114
 
      // Test connections.
115
 
      assertEquals("abc", client1.invoke("abc"));
116
 
      log.info("connection 1 is good");
117
 
      assertEquals("def", client2.invoke("def"));
118
 
      log.info("connection 2 is good");
119
 
      
120
 
      log.info("invoker1: " + client1.getInvoker());
121
 
      log.info("invoker2: " + client2.getInvoker());
122
 
      assertTrue(client1.getInvoker() instanceof MicroSocketClientInvoker);
123
 
      assertTrue(client2.getInvoker() instanceof MicroSocketClientInvoker);
124
 
      MicroSocketClientInvoker invoker1 = (MicroSocketClientInvoker) client1.getInvoker();
125
 
      MicroSocketClientInvoker invoker2 = (MicroSocketClientInvoker) client2.getInvoker();
126
 
      assertNotSame(invoker1, invoker2);
127
 
      Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
128
 
      field.setAccessible(true);
129
 
      assertNotSame(field.get(invoker1), field.get(invoker2));
130
 
      
131
 
      field = MicroSocketClientInvoker.class.getDeclaredField("address");
132
 
      field.setAccessible(true);
133
 
      log.info("invoker1.address: " + field.get(invoker1));
134
 
      log.info("invoker2.address: " + field.get(invoker2));
135
 
      
136
 
      client1.disconnect();
137
 
      client2.disconnect();
138
 
      shutdownServer();
139
 
      log.info(getName() + " PASSES");
140
 
   }
141
 
   
142
 
   
143
 
   protected String getTransport()
144
 
   {
145
 
      return "socket";
146
 
   }
147
 
   
148
 
   
149
 
   protected void addExtraClientConfig(Map config) {}
150
 
   protected void addExtraServerConfig(Map config) {}
151
 
   
152
 
 
153
 
   protected void setupServer() throws Exception
154
 
   {
155
 
      host = InetAddress.getLocalHost().getHostAddress();
156
 
      port = PortUtil.findFreePort(host);
157
 
      locatorURI = getTransport() + "://" + host + ":" + port; 
158
 
      serverLocator = new InvokerLocator(locatorURI);
159
 
      log.info("Starting remoting server with locator uri of: " + locatorURI);
160
 
      HashMap config = new HashMap();
161
 
      config.put(InvokerLocator.FORCE_REMOTE, "true");
162
 
      addExtraServerConfig(config);
163
 
      connector = new Connector(serverLocator, config);
164
 
      connector.create();
165
 
      invocationHandler = new TestInvocationHandler();
166
 
      connector.addInvocationHandler("test", invocationHandler);
167
 
      connector.start();
168
 
   }
169
 
   
170
 
   
171
 
   protected void shutdownServer() throws Exception
172
 
   {
173
 
      if (connector != null)
174
 
         connector.stop();
175
 
   }
176
 
   
177
 
   
178
 
   static class TestInvocationHandler implements ServerInvocationHandler
179
 
   {
180
 
      public void addListener(InvokerCallbackHandler callbackHandler) {}
181
 
      public Object invoke(final InvocationRequest invocation) throws Throwable
182
 
      {
183
 
         return invocation.getParameter();
184
 
      }
185
 
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
186
 
      public void setMBeanServer(MBeanServer server) {}
187
 
      public void setInvoker(ServerInvoker invoker) {}
188
 
   }
189
 
   
190
 
   
191
 
   static class TestCallbackHandler implements InvokerCallbackHandler
192
 
   {
193
 
      public void handleCallback(Callback callback) throws HandleCallbackException
194
 
      {
195
 
         log.info("received callback");
196
 
      }  
197
 
   }
198
 
}
 
 
b'\\ No newline at end of file'