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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/shutdown/local/LocalShutdownTestCase.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.shutdown.local;
 
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.ConnectionListener;
 
39
import org.jboss.remoting.InvocationRequest;
 
40
import org.jboss.remoting.InvokerLocator;
 
41
import org.jboss.remoting.MicroRemoteClientInvoker;
 
42
import org.jboss.remoting.ServerInvocationHandler;
 
43
import org.jboss.remoting.ServerInvoker;
 
44
import org.jboss.remoting.callback.Callback;
 
45
import org.jboss.remoting.callback.HandleCallbackException;
 
46
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
47
import org.jboss.remoting.transport.Connector;
 
48
import org.jboss.remoting.transport.PortUtil;
 
49
 
 
50
/** 
 
51
 * Provides unit tests that verifies that Client.disconnectLocal() and
 
52
 * Client.removeListenerLocal() do not attempt to contact the server.
 
53
 * 
 
54
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
55
 * @version $Revision: 2172 $
 
56
 * <p>
 
57
 * Copyright Jan 18, 2007
 
58
 * </p>
 
59
 */
 
60
public class LocalShutdownTestCase extends TestCase
 
61
{
 
62
   private Logger log = Logger.getLogger(LocalShutdownTestCase.class);
 
63
   protected static boolean firstTime = true;
 
64
   
 
65
   
 
66
   public void setUp() throws Exception
 
67
   {
 
68
      if (firstTime)
 
69
      {
 
70
         firstTime = false;
 
71
         Logger.getLogger("org.jboss.remoting").setLevel(Level.DEBUG);
 
72
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.DEBUG);
 
73
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
 
74
         PatternLayout layout = new PatternLayout(pattern);
 
75
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
 
76
         Logger.getRootLogger().addAppender(consoleAppender);  
 
77
      }
 
78
   }
 
79
  
 
80
   public void testDummy()
 
81
   {
 
82
      
 
83
   }
 
84
//   public void testDisconnectLocal() throws Throwable
 
85
//   {
 
86
//      log.info("entering " + getName());
 
87
//      
 
88
//      // Start server.
 
89
//      String host = InetAddress.getLocalHost().getHostAddress();
 
90
//      int port = PortUtil.findFreePort(host);
 
91
//      String locatorURI = "socket://" + host + ":" + port;
 
92
//      InvokerLocator locator = new InvokerLocator(locatorURI);
 
93
//      HashMap serverConfig = new HashMap();
 
94
//      Connector connector = new Connector(locator, serverConfig);
 
95
//      connector.create();
 
96
//      connector.addInvocationHandler("test", new TestHandler());
 
97
//      connector.addConnectionListener(new TestListener());
 
98
//      connector.start();
 
99
//      
 
100
//      // Connect client, verify that a lease exists, then disconnect client
 
101
//      // and verify that lease has been removed on server.
 
102
//      HashMap clientConfig = new HashMap();
 
103
//      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
104
//      clientConfig.put(Client.ENABLE_LEASE, "true");
 
105
//      clientConfig.put(InvokerLocator.CLIENT_LEASE_PERIOD, "1000");
 
106
//      Client client = new Client(locator, clientConfig);
 
107
//      client.connect();
 
108
//      Integer i = (Integer) client.invoke(new Integer(7));
 
109
//      assertEquals(8, i.intValue());
 
110
//      Thread.sleep(1000);
 
111
//      ServerInvoker serverInvoker = connector.getServerInvoker();
 
112
//      Field field = ServerInvoker.class.getDeclaredField("clientLeases");
 
113
//      field.setAccessible(true);
 
114
//      Map clientLeases = (Map) field.get(serverInvoker);
 
115
//      assertEquals(1, clientLeases.size());
 
116
//      field = MicroRemoteClientInvoker.class.getDeclaredField("invokerSessionId");
 
117
//      field.setAccessible(true);
 
118
//      String invokerSessionId = (String) field.get(client.getInvoker());
 
119
//      assertTrue(clientLeases.containsKey(invokerSessionId));
 
120
//      client.disconnect();
 
121
//      assertEquals(0, clientLeases.size());
 
122
//      
 
123
//      // Connect new client, verify that a lease exists, then locally disconnect
 
124
//      // client and verify that lease still exists on server.
 
125
//      client = new Client(locator, clientConfig);
 
126
//      client.connect();
 
127
//      i = (Integer) client.invoke(new Integer(11));
 
128
//      assertEquals(12, i.intValue());
 
129
//      Thread.sleep(1000);
 
130
//      assertEquals(1, clientLeases.size());
 
131
//      invokerSessionId = (String) field.get(client.getInvoker());
 
132
//      assertTrue(clientLeases.containsKey(invokerSessionId));
 
133
//      client.disconnectLocal();
 
134
//      assertEquals(1, clientLeases.size());
 
135
//      assertTrue(clientLeases.containsKey(invokerSessionId));
 
136
//      
 
137
//      connector.stop();
 
138
//      log.info(getName() + " PASSES");
 
139
//   }
 
140
   
 
141
   
 
142
//   public void testRemoveListenerLocalPushCallbacks() throws Throwable
 
143
   {
 
144
//      log.info("entering " + getName());
 
145
//      
 
146
//      // Start server.
 
147
//      String host = InetAddress.getLocalHost().getHostAddress();
 
148
//      int port = PortUtil.findFreePort(host);
 
149
//      String locatorURI = "socket://" + host + ":" + port;
 
150
//      InvokerLocator locator = new InvokerLocator(locatorURI);
 
151
//      HashMap serverConfig = new HashMap();
 
152
//      serverConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
153
//      Connector connector = new Connector(locator, serverConfig);
 
154
//      connector.create();
 
155
//      connector.addInvocationHandler("test", new TestHandler());
 
156
//      connector.start();
 
157
//      
 
158
//      // Connect client, add a callback handler, then call Client.removeListener()
 
159
//      // and verify that callback handler has been removed on server.
 
160
//      HashMap clientConfig = new HashMap();
 
161
//      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
162
//      Client client = new Client(locator, clientConfig);
 
163
//      client.connect();
 
164
//      Integer i = (Integer) client.invoke(new Integer(7));
 
165
//      assertEquals(8, i.intValue());
 
166
//      TestCallbackHandler callbackHandler = new TestCallbackHandler();
 
167
//      client.addListener(callbackHandler, null, null, true);
 
168
//      ServerInvoker serverInvoker = connector.getServerInvoker();
 
169
//      Field field = ServerInvoker.class.getDeclaredField("callbackHandlers");
 
170
//      field.setAccessible(true);
 
171
//      Map callbackHandlers = (Map) field.get(serverInvoker);
 
172
//      assertEquals(1, callbackHandlers.size());
 
173
//      client.removeListener(callbackHandler);
 
174
//      assertEquals(0, callbackHandlers.size());
 
175
//      client.disconnect();      
 
176
//
 
177
//      // Connect client, add a callback handler, then call Client.removeListenerLocal()
 
178
//      // and verify that callback handler still exists on server.
 
179
//      client = new Client(locator, clientConfig);
 
180
//      client.connect();
 
181
//      i = (Integer) client.invoke(new Integer(11));
 
182
//      assertEquals(12, i.intValue());
 
183
//      callbackHandler = new TestCallbackHandler();
 
184
//      client.addListener(callbackHandler, null, null, true);
 
185
//      assertEquals(1, callbackHandlers.size());
 
186
//      client.removeListenerLocal(callbackHandler);
 
187
//      assertEquals(1, callbackHandlers.size());
 
188
//      client.disconnect();  
 
189
//      
 
190
//      connector.stop();
 
191
//      log.info(getName() + " PASSES");
 
192
//   }
 
193
//   
 
194
//   
 
195
//   public void testRemoveListenerLocalPolledCallbacks() throws Throwable
 
196
//   {
 
197
//      log.info("entering " + getName());
 
198
//      
 
199
//      // Start server.
 
200
//      String host = InetAddress.getLocalHost().getHostAddress();
 
201
//      int port = PortUtil.findFreePort(host);
 
202
//      String locatorURI = "socket://" + host + ":" + port;
 
203
//      InvokerLocator locator = new InvokerLocator(locatorURI);
 
204
//      HashMap serverConfig = new HashMap();
 
205
//      serverConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
206
//      Connector connector = new Connector(locator, serverConfig);
 
207
//      connector.create();
 
208
//      connector.addInvocationHandler("test", new TestHandler());
 
209
//      connector.start();
 
210
//      
 
211
//      // Connect client, add a callback handler, then call Client.removeListener()
 
212
//      // and verify that callback handler has been removed on server.
 
213
//      HashMap clientConfig = new HashMap();
 
214
//      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
215
//      Client client = new Client(locator, clientConfig);
 
216
//      client.connect();
 
217
//      Integer i = (Integer) client.invoke(new Integer(7));
 
218
//      assertEquals(8, i.intValue());
 
219
//      TestCallbackHandler callbackHandler = new TestCallbackHandler();
 
220
//      client.addListener(callbackHandler, null, null, false);
 
221
//      ServerInvoker serverInvoker = connector.getServerInvoker();
 
222
//      Field field = ServerInvoker.class.getDeclaredField("callbackHandlers");
 
223
//      field.setAccessible(true);
 
224
//      Map callbackHandlers = (Map) field.get(serverInvoker);
 
225
//      assertEquals(1, callbackHandlers.size());
 
226
//      client.removeListener(callbackHandler);
 
227
//      assertEquals(0, callbackHandlers.size());
 
228
//      client.disconnect();      
 
229
//
 
230
//      // Connect client, add a callback handler, then call Client.removeListenerLocal()
 
231
//      // and verify that callback handler still exists on server.
 
232
//      client = new Client(locator, clientConfig);
 
233
//      client.connect();
 
234
//      i = (Integer) client.invoke(new Integer(11));
 
235
//      assertEquals(12, i.intValue());
 
236
//      callbackHandler = new TestCallbackHandler();
 
237
//      client.addListener(callbackHandler, null, null, false);
 
238
//      assertEquals(1, callbackHandlers.size());
 
239
//      client.removeListenerLocal(callbackHandler);
 
240
//      assertEquals(1, callbackHandlers.size());
 
241
//      client.disconnect();  
 
242
//      
 
243
//      connector.stop();
 
244
//      log.info(getName() + " PASSES");
 
245
//   }
 
246
//   
 
247
//   
 
248
//   public void testRemoveListenerLocalPullCallbacks() throws Throwable
 
249
//   {
 
250
//      log.info("entering " + getName());
 
251
//      
 
252
//      // Start server.
 
253
//      String host = InetAddress.getLocalHost().getHostAddress();
 
254
//      int port = PortUtil.findFreePort(host);
 
255
//      String locatorURI = "socket://" + host + ":" + port;
 
256
//      InvokerLocator locator = new InvokerLocator(locatorURI);
 
257
//      HashMap serverConfig = new HashMap();
 
258
//      serverConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
259
//      Connector connector = new Connector(locator, serverConfig);
 
260
//      connector.create();
 
261
//      connector.addInvocationHandler("test", new TestHandler());
 
262
//      connector.start();
 
263
//      
 
264
//      // Connect client, add a callback handler, then call Client.removeListener()
 
265
//      // and verify that callback handler has been removed on server.
 
266
//      HashMap clientConfig = new HashMap();
 
267
//      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
268
//      Client client = new Client(locator, clientConfig);
 
269
//      client.connect();
 
270
//      Integer i = (Integer) client.invoke(new Integer(7));
 
271
//      assertEquals(8, i.intValue());
 
272
//      TestCallbackHandler callbackHandler = new TestCallbackHandler();
 
273
//      client.addListener(callbackHandler);
 
274
//      ServerInvoker serverInvoker = connector.getServerInvoker();
 
275
//      Field field = ServerInvoker.class.getDeclaredField("callbackHandlers");
 
276
//      field.setAccessible(true);
 
277
//      Map callbackHandlers = (Map) field.get(serverInvoker);
 
278
//      assertEquals(1, callbackHandlers.size());
 
279
//      client.removeListener(callbackHandler);
 
280
//      assertEquals(0, callbackHandlers.size());
 
281
//      client.disconnect();      
 
282
//
 
283
//      // Connect client, add a callback handler, then call Client.removeListenerLocal()
 
284
//      // and verify that callback handler still exists on server.
 
285
//      client = new Client(locator, clientConfig);
 
286
//      client.connect();
 
287
//      i = (Integer) client.invoke(new Integer(11));
 
288
//      assertEquals(12, i.intValue());
 
289
//      callbackHandler = new TestCallbackHandler();
 
290
//      client.addListener(callbackHandler);
 
291
//      assertEquals(1, callbackHandlers.size());
 
292
//      client.removeListenerLocal(callbackHandler);
 
293
//      assertEquals(1, callbackHandlers.size());
 
294
//      client.disconnect();  
 
295
//      
 
296
//      connector.stop();
 
297
//      log.info(getName() + " PASSES");
 
298
   }
 
299
   
 
300
   
 
301
   public class TestHandler implements ServerInvocationHandler
 
302
   {
 
303
 
 
304
      public void setMBeanServer(MBeanServer server) {}
 
305
      public void setInvoker(ServerInvoker invoker) {}
 
306
 
 
307
      public Object invoke(InvocationRequest invocation) throws Throwable
 
308
      {
 
309
         Integer i = (Integer) invocation.getParameter();
 
310
         return new Integer(i.intValue() + 1);
 
311
      }
 
312
 
 
313
      public void addListener(InvokerCallbackHandler callbackHandler) {}
 
314
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
 
315
   }
 
316
   
 
317
   
 
318
   public class TestListener implements ConnectionListener
 
319
   {
 
320
      public void handleConnectionException(Throwable throwable, Client client) {}
 
321
   }
 
322
   
 
323
   
 
324
   public class TestCallbackHandler implements InvokerCallbackHandler
 
325
   {
 
326
      public void handleCallback(Callback callback) throws HandleCallbackException
 
327
      {
 
328
         log.info("received callback: " + callback);
 
329
      }  
 
330
   }
 
331
}
 
 
b'\\ No newline at end of file'