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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/transport/socket/connection/ConnectionWaitTestCase.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.connection;
 
23
 
 
24
import java.net.InetAddress;
 
25
import java.util.HashMap;
 
26
import java.util.Map;
 
27
 
 
28
import javax.management.MBeanServer;
 
29
 
 
30
import junit.framework.TestCase;
 
31
 
 
32
import org.apache.log4j.ConsoleAppender;
 
33
import org.apache.log4j.Level;
 
34
import org.apache.log4j.Logger;
 
35
import org.apache.log4j.PatternLayout;
 
36
import org.jboss.logging.XLevel;
 
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.InvokerCallbackHandler;
 
43
import org.jboss.remoting.transport.Connector;
 
44
import org.jboss.remoting.transport.PortUtil;
 
45
import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
 
46
 
 
47
/**
 
48
 * Unit test for JBREM-986.
 
49
 * 
 
50
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
51
 * @version $Revision: 1.1 $
 
52
 * <p>
 
53
 * Copyright May 28, 2008
 
54
 * </p>
 
55
 */
 
56
public class ConnectionWaitTestCase extends TestCase
 
57
{
 
58
   private static Logger log = Logger.getLogger(ConnectionWaitTestCase.class);
 
59
   
 
60
   private static boolean firstTime = true;
 
61
   
 
62
   protected String host;
 
63
   protected int port;
 
64
   protected String locatorURI;
 
65
   protected InvokerLocator serverLocator;
 
66
   protected Connector connector;
 
67
   protected TestInvocationHandler invocationHandler;
 
68
 
 
69
   
 
70
   public void setUp() throws Exception
 
71
   {
 
72
      if (firstTime)
 
73
      {
 
74
         firstTime = false;
 
75
         Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
 
76
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
 
77
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
 
78
         PatternLayout layout = new PatternLayout(pattern);
 
79
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
 
80
         Logger.getRootLogger().addAppender(consoleAppender);  
 
81
      }
 
82
   }
 
83
 
 
84
   
 
85
   public void tearDown()
 
86
   {
 
87
   }
 
88
   
 
89
   
 
90
   public void testConnectionWaitDefault() throws Throwable
 
91
   {
 
92
      log.info("entering " + getName());
 
93
      
 
94
      // Start server.
 
95
      setupServer();
 
96
      
 
97
      // Create client.
 
98
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
 
99
      HashMap clientConfig = new HashMap();
 
100
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
101
      addExtraClientConfig(clientConfig);
 
102
      Client client = new Client(clientLocator, clientConfig);
 
103
      client.connect();
 
104
      log.info("client is connected");
 
105
      
 
106
      // Test connections.
 
107
      assertEquals("abc", client.invoke("abc"));
 
108
      log.info("connection is good");
 
109
      
 
110
      // Verify connectionWait is set to default value.
 
111
      MicroSocketClientInvoker invoker = (MicroSocketClientInvoker) client.getInvoker();
 
112
      assertEquals(MicroSocketClientInvoker.CONNECTION_WAIT_DEFAULT, invoker.getConnectionWait());
 
113
      
 
114
      client.disconnect();
 
115
      shutdownServer();
 
116
      log.info(getName() + " PASSES");
 
117
   }
 
118
   
 
119
   
 
120
   public void testConnectionWaitSetInLocator() throws Throwable
 
121
   {
 
122
      log.info("entering " + getName());
 
123
      
 
124
      // Start server.
 
125
      setupServer();
 
126
      
 
127
      // Create client.
 
128
      String clientLocatorURI = locatorURI + "/?" + MicroSocketClientInvoker.CONNECTION_WAIT + "=12345";
 
129
      InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
 
130
      HashMap clientConfig = new HashMap();
 
131
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
132
      addExtraClientConfig(clientConfig);
 
133
      Client client = new Client(clientLocator, clientConfig);
 
134
      client.connect();
 
135
      log.info("client is connected");
 
136
      
 
137
      // Test connections.
 
138
      assertEquals("abc", client.invoke("abc"));
 
139
      log.info("connection is good");
 
140
      
 
141
      // Verify connectionWait is set to configured value.
 
142
      MicroSocketClientInvoker invoker = (MicroSocketClientInvoker) client.getInvoker();
 
143
      assertEquals(12345, invoker.getConnectionWait());
 
144
      
 
145
      client.disconnect();
 
146
      shutdownServer();
 
147
      log.info(getName() + " PASSES");
 
148
   }
 
149
   
 
150
   
 
151
   public void testConnectionWaitSetInConfigMap() throws Throwable
 
152
   {
 
153
      log.info("entering " + getName());
 
154
      
 
155
      // Start server.
 
156
      setupServer();
 
157
      
 
158
      // Create client.
 
159
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
 
160
      HashMap clientConfig = new HashMap();
 
161
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
162
      clientConfig.put(MicroSocketClientInvoker.CONNECTION_WAIT, "12345");
 
163
      addExtraClientConfig(clientConfig);
 
164
      Client client = new Client(clientLocator, clientConfig);
 
165
      client.connect();
 
166
      log.info("client is connected");
 
167
      
 
168
      // Test connections.
 
169
      assertEquals("abc", client.invoke("abc"));
 
170
      log.info("connection is good");
 
171
      
 
172
      // Verify connectionWait is set to configured value.
 
173
      MicroSocketClientInvoker invoker = (MicroSocketClientInvoker) client.getInvoker();
 
174
      assertEquals(12345, invoker.getConnectionWait());
 
175
      
 
176
      client.disconnect();
 
177
      shutdownServer();
 
178
      log.info(getName() + " PASSES");
 
179
   }
 
180
   
 
181
   
 
182
   protected String getTransport()
 
183
   {
 
184
      return "socket";
 
185
   }
 
186
   
 
187
   
 
188
   protected void addExtraClientConfig(Map config) {}
 
189
   protected void addExtraServerConfig(Map config) {}
 
190
   
 
191
 
 
192
   protected void setupServer() throws Exception
 
193
   {
 
194
      host = InetAddress.getLocalHost().getHostAddress();
 
195
      port = PortUtil.findFreePort(host);
 
196
      locatorURI = getTransport() + "://" + host + ":" + port; 
 
197
      serverLocator = new InvokerLocator(locatorURI);
 
198
      log.info("Starting remoting server with locator uri of: " + locatorURI);
 
199
      HashMap config = new HashMap();
 
200
      config.put(InvokerLocator.FORCE_REMOTE, "true");
 
201
      addExtraServerConfig(config);
 
202
      connector = new Connector(serverLocator, config);
 
203
      connector.create();
 
204
      invocationHandler = new TestInvocationHandler();
 
205
      connector.addInvocationHandler("test", invocationHandler);
 
206
      connector.start();
 
207
   }
 
208
   
 
209
   
 
210
   protected void shutdownServer() throws Exception
 
211
   {
 
212
      if (connector != null)
 
213
         connector.stop();
 
214
   }
 
215
   
 
216
   
 
217
   static class TestInvocationHandler implements ServerInvocationHandler
 
218
   {
 
219
      public void addListener(InvokerCallbackHandler callbackHandler) {}
 
220
      public Object invoke(final InvocationRequest invocation) throws Throwable
 
221
      {
 
222
         return invocation.getParameter();
 
223
      }
 
224
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
 
225
      public void setMBeanServer(MBeanServer server) {}
 
226
      public void setInvoker(ServerInvoker invoker) {}
 
227
   }
 
228
}
 
 
b'\\ No newline at end of file'