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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/callback/timeout/BisocketCallbackTimeoutTestCase.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.callback.timeout;
 
23
 
 
24
import java.lang.reflect.Field;
 
25
import java.net.InetAddress;
 
26
import java.util.HashMap;
 
27
import java.util.HashSet;
 
28
import java.util.Iterator;
 
29
import java.util.LinkedList;
 
30
import java.util.Map;
 
31
import java.util.Set;
 
32
 
 
33
import javax.management.MBeanServer;
 
34
 
 
35
import junit.framework.TestCase;
 
36
 
 
37
import org.apache.log4j.ConsoleAppender;
 
38
import org.apache.log4j.Level;
 
39
import org.apache.log4j.Logger;
 
40
import org.apache.log4j.PatternLayout;
 
41
import org.jboss.remoting.Client;
 
42
import org.jboss.remoting.InvocationRequest;
 
43
import org.jboss.remoting.InvokerLocator;
 
44
import org.jboss.remoting.ServerInvocationHandler;
 
45
import org.jboss.remoting.ServerInvoker;
 
46
import org.jboss.remoting.callback.Callback;
 
47
import org.jboss.remoting.callback.HandleCallbackException;
 
48
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
49
import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
 
50
import org.jboss.remoting.transport.Connector;
 
51
import org.jboss.remoting.transport.PortUtil;
 
52
import org.jboss.remoting.transport.socket.ClientSocketWrapper;
 
53
import org.jboss.remoting.transport.socket.LRUPool;
 
54
import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
 
55
import org.jboss.remoting.transport.socket.ServerSocketWrapper;
 
56
import org.jboss.remoting.transport.socket.ServerThread;
 
57
import org.jboss.remoting.transport.socket.SocketServerInvoker;
 
58
 
 
59
 
 
60
 
 
61
/**
 
62
 * Unit test for JBREM-765.
 
63
 * 
 
64
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
65
 * @version $Revision: 2751 $
 
66
 * <p>
 
67
 * Copyright Aug 5, 2007
 
68
 * </p>
 
69
 */
 
70
public class BisocketCallbackTimeoutTestCase extends TestCase
 
71
{
 
72
   public static int port;
 
73
   private static Logger log = Logger.getLogger(BisocketCallbackTimeoutTestCase.class);
 
74
   private static final String CALLBACK_TEST = "callbackTest";
 
75
 
 
76
   private static boolean firstTime = true;
 
77
 
 
78
   // remoting server connector
 
79
   private Connector connector;
 
80
   private InvokerLocator serverLocator;
 
81
   private TestInvocationHandler invocationHandler;
 
82
 
 
83
 
 
84
   /**
 
85
    * Sets up target remoting server.
 
86
    */
 
87
   public void setUp() throws Exception
 
88
   {
 
89
      if (firstTime)
 
90
      {
 
91
         firstTime = false;
 
92
         Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
 
93
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
 
94
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
 
95
         PatternLayout layout = new PatternLayout(pattern);
 
96
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
 
97
         Logger.getRootLogger().addAppender(consoleAppender);  
 
98
      }
 
99
   }
 
100
 
 
101
 
 
102
   public void tearDown()
 
103
   {
 
104
   }
 
105
 
 
106
 
 
107
   /**
 
108
    * Verifies that "timeout" value is used in absence of "callbackTimeout" value.
 
109
    */
 
110
   public void testNoCallbackTimeout() throws Throwable
 
111
   {
 
112
      log.info("entering " + getName());
 
113
 
 
114
      // Start server.
 
115
      String host = InetAddress.getLocalHost().getHostAddress();
 
116
      port = PortUtil.findFreePort(host);
 
117
      String locatorURI = getTransport() + "://" + host + ":" + port; 
 
118
      serverLocator = new InvokerLocator(locatorURI);
 
119
      log.info("Starting remoting server with locator uri of: " + locatorURI);
 
120
      HashMap config = new HashMap();
 
121
      config.put(InvokerLocator.FORCE_REMOTE, "true");
 
122
      config.put(ServerInvoker.TIMEOUT, "3000");
 
123
      addExtraServerConfig(config);
 
124
      connector = new Connector(serverLocator, config);
 
125
      connector.create();
 
126
      invocationHandler = new TestInvocationHandler();
 
127
      connector.addInvocationHandler("sample", invocationHandler);
 
128
      connector.start();
 
129
 
 
130
      // Create client.
 
131
      HashMap clientConfig = new HashMap();
 
132
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
133
      addExtraClientConfig(clientConfig);
 
134
      final Client client = new Client(serverLocator, clientConfig);
 
135
      client.connect();
 
136
      assertEquals("abc", client.invoke("abc"));
 
137
      log.info("client is connected");
 
138
 
 
139
      // Add callback handler.
 
140
      TestInvokerCallbackHandler callbackHandler = new TestInvokerCallbackHandler();
 
141
      client.addListener(callbackHandler, new HashMap());
 
142
      client.invoke(CALLBACK_TEST);
 
143
      assertEquals(1, callbackHandler.counter);
 
144
      log.info("callback handler is installed");
 
145
 
 
146
      // Verify that "timeout" is used correctly.
 
147
      assertTrue(connector.getServerInvoker() instanceof SocketServerInvoker);
 
148
      SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
 
149
      Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
 
150
      field.setAccessible(true);
 
151
      LRUPool clientpool = (LRUPool) field.get(serverInvoker);
 
152
      Set threads = clientpool.getContents();
 
153
      assertEquals(1, threads.size());
 
154
      ServerThread serverThread = (ServerThread) threads.iterator().next();
 
155
      field = ServerThread.class.getDeclaredField("socketWrapper");
 
156
      field.setAccessible(true);
 
157
      assertTrue(field.get(serverThread) instanceof ServerSocketWrapper);
 
158
      ServerSocketWrapper serverWrapper = (ServerSocketWrapper) field.get(serverThread);
 
159
      assertEquals(3000, serverWrapper.getTimeout());
 
160
 
 
161
      // Verify that "timeout" is used in the absence of "callbackTimeout".
 
162
      field = ServerInvoker.class.getDeclaredField("callbackHandlers");
 
163
      field.setAccessible(true);
 
164
      Map callbackHandlers = (Map) field.get(serverInvoker);
 
165
      assertEquals(1, callbackHandlers.size());
 
166
      ServerInvokerCallbackHandler serverInvokerCallbackHandler;
 
167
      serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) callbackHandlers.values().iterator().next();
 
168
      Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
 
169
      assertTrue(callbackClient.getInvoker() instanceof MicroSocketClientInvoker);
 
170
      MicroSocketClientInvoker callbackClientInvoker = (MicroSocketClientInvoker) callbackClient.getInvoker();
 
171
      field = MicroSocketClientInvoker.class.getDeclaredField("pool");
 
172
      field.setAccessible(true);
 
173
      LinkedList pool = (LinkedList) field.get(callbackClientInvoker);
 
174
      assertEquals(1, pool.size());
 
175
      Object o = pool.iterator().next();
 
176
      assertTrue(o instanceof ClientSocketWrapper);
 
177
      ClientSocketWrapper clientWrapper = (ClientSocketWrapper) o;
 
178
      assertEquals(3000, clientWrapper.getTimeout());
 
179
 
 
180
      client.removeListener(callbackHandler);
 
181
      client.disconnect();
 
182
      connector.stop();
 
183
   }
 
184
 
 
185
 
 
186
   /**
 
187
    * Verifies that "callbackTimeout" value overrides "timeout" value.
 
188
    * Values are specified in configuration map.
 
189
    */
 
190
   public void testDistinctCallbackTimeoutConfigMap() throws Throwable
 
191
   {
 
192
      log.info("entering " + getName());
 
193
 
 
194
      // Start server.
 
195
      String host = InetAddress.getLocalHost().getHostAddress();
 
196
      port = PortUtil.findFreePort(host);
 
197
      String locatorURI = getTransport() + "://" + host + ":" + port; 
 
198
      serverLocator = new InvokerLocator(locatorURI);
 
199
      log.info("Starting remoting server with locator uri of: " + locatorURI);
 
200
      HashMap config = new HashMap();
 
201
      config.put(InvokerLocator.FORCE_REMOTE, "true");
 
202
      config.put(ServerInvoker.TIMEOUT, "3000");
 
203
      config.put(ServerInvokerCallbackHandler.CALLBACK_TIMEOUT, "7000");
 
204
      addExtraServerConfig(config);
 
205
      connector = new Connector(serverLocator, config);
 
206
      connector.create();
 
207
      invocationHandler = new TestInvocationHandler();
 
208
      connector.addInvocationHandler("sample", invocationHandler);
 
209
      connector.start();
 
210
 
 
211
      // Create client.
 
212
      HashMap clientConfig = new HashMap();
 
213
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
214
      addExtraClientConfig(clientConfig);
 
215
      final Client client = new Client(serverLocator, clientConfig);
 
216
      client.connect();
 
217
      assertEquals("abc", client.invoke("abc"));
 
218
      log.info("client is connected");
 
219
 
 
220
      // Add callback handler.
 
221
      TestInvokerCallbackHandler callbackHandler = new TestInvokerCallbackHandler();
 
222
      client.addListener(callbackHandler, new HashMap());
 
223
      client.invoke(CALLBACK_TEST);
 
224
      assertEquals(1, callbackHandler.counter);
 
225
      log.info("callback handler is installed");
 
226
 
 
227
      // Verify that "timeout" is used correctly.
 
228
      assertTrue(connector.getServerInvoker() instanceof SocketServerInvoker);
 
229
      SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
 
230
      Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
 
231
      field.setAccessible(true);
 
232
      LRUPool clientpool = (LRUPool) field.get(serverInvoker);
 
233
      Set threads = clientpool.getContents();
 
234
      assertEquals(1, threads.size());
 
235
      ServerThread serverThread = (ServerThread) threads.iterator().next();
 
236
      field = ServerThread.class.getDeclaredField("socketWrapper");
 
237
      field.setAccessible(true);
 
238
      assertTrue(field.get(serverThread) instanceof ServerSocketWrapper);
 
239
      ServerSocketWrapper serverWrapper = (ServerSocketWrapper) field.get(serverThread);
 
240
      assertEquals(3000, serverWrapper.getTimeout());
 
241
 
 
242
      // Verify that "callbackTimeout" is used correctly.
 
243
      field = ServerInvoker.class.getDeclaredField("callbackHandlers");
 
244
      field.setAccessible(true);
 
245
      Map callbackHandlers = (Map) field.get(serverInvoker);
 
246
      assertEquals(1, callbackHandlers.size());
 
247
      ServerInvokerCallbackHandler serverInvokerCallbackHandler;
 
248
      serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) callbackHandlers.values().iterator().next();
 
249
      Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
 
250
      assertTrue(callbackClient.getInvoker() instanceof MicroSocketClientInvoker);
 
251
      MicroSocketClientInvoker callbackClientInvoker = (MicroSocketClientInvoker) callbackClient.getInvoker();
 
252
      field = MicroSocketClientInvoker.class.getDeclaredField("pool");
 
253
      field.setAccessible(true);
 
254
      LinkedList pool = (LinkedList) field.get(callbackClientInvoker);
 
255
      assertEquals(1, pool.size());
 
256
      Object o = pool.iterator().next();
 
257
      assertTrue(o instanceof ClientSocketWrapper);
 
258
      ClientSocketWrapper clientWrapper = (ClientSocketWrapper) o;
 
259
      assertEquals(7000, clientWrapper.getTimeout());
 
260
 
 
261
      client.removeListener(callbackHandler);
 
262
      client.disconnect();
 
263
      connector.stop();
 
264
   }
 
265
 
 
266
 
 
267
   /**
 
268
    * Verifies that "callbackTimeout" value overrides "timeout" value.
 
269
    * Values are specified in InvokerLocator.
 
270
    */
 
271
   public void testDistinctCallbackTimeoutLocator() throws Throwable
 
272
   {
 
273
      log.info("entering " + getName());
 
274
 
 
275
      // Start server.
 
276
      String host = InetAddress.getLocalHost().getHostAddress();
 
277
      port = PortUtil.findFreePort(host);
 
278
      String locatorURI = getTransport() + "://" + host + ":" + port; 
 
279
      locatorURI += "/?timeout=3000&callbackTimeout=7000";
 
280
      serverLocator = new InvokerLocator(locatorURI);
 
281
      log.info("Starting remoting server with locator uri of: " + locatorURI);
 
282
      HashMap config = new HashMap();
 
283
      config.put(InvokerLocator.FORCE_REMOTE, "true");
 
284
      addExtraServerConfig(config);
 
285
      connector = new Connector(serverLocator, config);
 
286
      connector.create();
 
287
      invocationHandler = new TestInvocationHandler();
 
288
      connector.addInvocationHandler("sample", invocationHandler);
 
289
      connector.start();
 
290
 
 
291
      // Create client.
 
292
      HashMap clientConfig = new HashMap();
 
293
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
294
      addExtraClientConfig(clientConfig);
 
295
      final Client client = new Client(serverLocator, clientConfig);
 
296
      client.connect();
 
297
      assertEquals("abc", client.invoke("abc"));
 
298
      log.info("client is connected");
 
299
 
 
300
      // Add callback handler.
 
301
      TestInvokerCallbackHandler callbackHandler = new TestInvokerCallbackHandler();
 
302
      client.addListener(callbackHandler, new HashMap());
 
303
      client.invoke(CALLBACK_TEST);
 
304
      assertEquals(1, callbackHandler.counter);
 
305
      log.info("callback handler is installed");
 
306
 
 
307
      // Verify that "timeout" is used correctly.
 
308
      assertTrue(connector.getServerInvoker() instanceof SocketServerInvoker);
 
309
      SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
 
310
      Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
 
311
      field.setAccessible(true);
 
312
      LRUPool clientpool = (LRUPool) field.get(serverInvoker);
 
313
      Set threads = clientpool.getContents();
 
314
      assertEquals(1, threads.size());
 
315
      ServerThread serverThread = (ServerThread) threads.iterator().next();
 
316
      field = ServerThread.class.getDeclaredField("socketWrapper");
 
317
      field.setAccessible(true);
 
318
      assertTrue(field.get(serverThread) instanceof ServerSocketWrapper);
 
319
      ServerSocketWrapper serverWrapper = (ServerSocketWrapper) field.get(serverThread);
 
320
      assertEquals(3000, serverWrapper.getTimeout());
 
321
 
 
322
      // Verify that "callbackTimeout" is used correctly.
 
323
      field = ServerInvoker.class.getDeclaredField("callbackHandlers");
 
324
      field.setAccessible(true);
 
325
      Map callbackHandlers = (Map) field.get(serverInvoker);
 
326
      assertEquals(1, callbackHandlers.size());
 
327
      ServerInvokerCallbackHandler serverInvokerCallbackHandler;
 
328
      serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) callbackHandlers.values().iterator().next();
 
329
      Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
 
330
      assertTrue(callbackClient.getInvoker() instanceof MicroSocketClientInvoker);
 
331
      MicroSocketClientInvoker callbackClientInvoker = (MicroSocketClientInvoker) callbackClient.getInvoker();
 
332
      field = MicroSocketClientInvoker.class.getDeclaredField("pool");
 
333
      field.setAccessible(true);
 
334
      LinkedList pool = (LinkedList) field.get(callbackClientInvoker);
 
335
      assertEquals(1, pool.size());
 
336
      Object o = pool.iterator().next();
 
337
      assertTrue(o instanceof ClientSocketWrapper);
 
338
      ClientSocketWrapper clientWrapper = (ClientSocketWrapper) o;
 
339
      assertEquals(7000, clientWrapper.getTimeout());
 
340
 
 
341
      client.removeListener(callbackHandler);
 
342
      client.disconnect();
 
343
      connector.stop();
 
344
   }
 
345
 
 
346
 
 
347
   /**
 
348
    * Verifies that "timeout" value is used in absense of "callbackTimeout".
 
349
    * "timeout" value is specified in Client.addListener() metadata map.
 
350
    */
 
351
   public void testNoCallbackTimeoutMetadata() throws Throwable
 
352
   {
 
353
      log.info("entering " + getName());
 
354
 
 
355
      // Start server.
 
356
      String host = InetAddress.getLocalHost().getHostAddress();
 
357
      port = PortUtil.findFreePort(host);
 
358
      String locatorURI = getTransport() + "://" + host + ":" + port; 
 
359
      serverLocator = new InvokerLocator(locatorURI);
 
360
      log.info("Starting remoting server with locator uri of: " + locatorURI);
 
361
      HashMap config = new HashMap();
 
362
      config.put(InvokerLocator.FORCE_REMOTE, "true");
 
363
      addExtraServerConfig(config);
 
364
      connector = new Connector(serverLocator, config);
 
365
      connector.create();
 
366
      invocationHandler = new TestInvocationHandler();
 
367
      connector.addInvocationHandler("sample", invocationHandler);
 
368
      connector.start();
 
369
 
 
370
      // Create client.
 
371
      HashMap clientConfig = new HashMap();
 
372
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
373
      addExtraClientConfig(clientConfig);
 
374
      final Client client = new Client(serverLocator, clientConfig);
 
375
      client.connect();
 
376
      assertEquals("abc", client.invoke("abc"));
 
377
      log.info("client is connected");
 
378
 
 
379
      // Add callback handler.
 
380
      TestInvokerCallbackHandler callbackHandler = new TestInvokerCallbackHandler();
 
381
      Map metadata = new HashMap();
 
382
      metadata.put(ServerInvoker.TIMEOUT, "3000");
 
383
      client.addListener(callbackHandler, metadata);
 
384
      client.invoke(CALLBACK_TEST);
 
385
      assertEquals(1, callbackHandler.counter);
 
386
      log.info("callback handler is installed");
 
387
 
 
388
      // Verify that "timeout" is used correctly.
 
389
      ServerInvoker serverInvoker = connector.getServerInvoker();
 
390
      Field field = ServerInvoker.class.getDeclaredField("callbackHandlers");
 
391
      field.setAccessible(true);
 
392
      Map callbackHandlers = (Map) field.get(serverInvoker);
 
393
      assertEquals(1, callbackHandlers.size());
 
394
      ServerInvokerCallbackHandler serverInvokerCallbackHandler;
 
395
      serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) callbackHandlers.values().iterator().next();
 
396
      Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
 
397
      assertTrue(callbackClient.getInvoker() instanceof MicroSocketClientInvoker);
 
398
      MicroSocketClientInvoker callbackClientInvoker = (MicroSocketClientInvoker) callbackClient.getInvoker();
 
399
      field = MicroSocketClientInvoker.class.getDeclaredField("pool");
 
400
      field.setAccessible(true);
 
401
      LinkedList pool = (LinkedList) field.get(callbackClientInvoker);
 
402
      assertEquals(1, pool.size());
 
403
      Object o = pool.iterator().next();
 
404
      assertTrue(o instanceof ClientSocketWrapper);
 
405
      ClientSocketWrapper clientWrapper = (ClientSocketWrapper) o;
 
406
      assertEquals(3000, clientWrapper.getTimeout());
 
407
 
 
408
      client.removeListener(callbackHandler);
 
409
      client.disconnect();
 
410
      connector.stop();
 
411
   }
 
412
 
 
413
 
 
414
   /**
 
415
    * Verifies that "callbackTimeout" value overrides "timeout" value.
 
416
    * "callbackTimeout" is specified in Client.addListener() metadata map.
 
417
    */
 
418
   public void testDistinctCallbackTimeoutMetadata() throws Throwable
 
419
   {
 
420
      log.info("entering " + getName());
 
421
 
 
422
      // Start server.
 
423
      String host = InetAddress.getLocalHost().getHostAddress();
 
424
      port = PortUtil.findFreePort(host);
 
425
      String locatorURI = getTransport() + "://" + host + ":" + port; 
 
426
      serverLocator = new InvokerLocator(locatorURI);
 
427
      log.info("Starting remoting server with locator uri of: " + locatorURI);
 
428
      HashMap config = new HashMap();
 
429
      config.put(InvokerLocator.FORCE_REMOTE, "true");
 
430
      addExtraServerConfig(config);
 
431
      connector = new Connector(serverLocator, config);
 
432
      connector.create();
 
433
      invocationHandler = new TestInvocationHandler();
 
434
      connector.addInvocationHandler("sample", invocationHandler);
 
435
      connector.start();
 
436
 
 
437
      // Create client.
 
438
      HashMap clientConfig = new HashMap();
 
439
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
440
      addExtraClientConfig(clientConfig);
 
441
      final Client client = new Client(serverLocator, clientConfig);
 
442
      client.connect();
 
443
      assertEquals("abc", client.invoke("abc"));
 
444
      log.info("client is connected");
 
445
 
 
446
      // Add callback handler.
 
447
      TestInvokerCallbackHandler callbackHandler = new TestInvokerCallbackHandler();
 
448
      Map metadata = new HashMap();
 
449
      metadata.put(ServerInvokerCallbackHandler.CALLBACK_TIMEOUT, "7000");
 
450
      client.addListener(callbackHandler, metadata);
 
451
      client.invoke(CALLBACK_TEST);
 
452
      assertEquals(1, callbackHandler.counter);
 
453
      log.info("callback handler is installed");
 
454
 
 
455
      // Verify that "callbackTimeout" is used correctly.
 
456
      SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
 
457
      Field field = ServerInvoker.class.getDeclaredField("callbackHandlers");
 
458
      field.setAccessible(true);
 
459
      Map callbackHandlers = (Map) field.get(serverInvoker);
 
460
      assertEquals(1, callbackHandlers.size());
 
461
      ServerInvokerCallbackHandler serverInvokerCallbackHandler;
 
462
      serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) callbackHandlers.values().iterator().next();
 
463
      Client callbackClient = serverInvokerCallbackHandler.getCallbackClient();
 
464
      assertTrue(callbackClient.getInvoker() instanceof MicroSocketClientInvoker);
 
465
      MicroSocketClientInvoker callbackClientInvoker = (MicroSocketClientInvoker) callbackClient.getInvoker();
 
466
      field = MicroSocketClientInvoker.class.getDeclaredField("pool");
 
467
      field.setAccessible(true);
 
468
      LinkedList pool = (LinkedList) field.get(callbackClientInvoker);
 
469
      assertEquals(1, pool.size());
 
470
      Object o = pool.iterator().next();
 
471
      assertTrue(o instanceof ClientSocketWrapper);
 
472
      ClientSocketWrapper clientWrapper = (ClientSocketWrapper) o;
 
473
      assertEquals(7000, clientWrapper.getTimeout());
 
474
 
 
475
      client.removeListener(callbackHandler);
 
476
      client.disconnect();
 
477
      connector.stop();
 
478
   }
 
479
 
 
480
 
 
481
   protected String getTransport()
 
482
   {
 
483
      return "bisocket";
 
484
   }
 
485
   
 
486
   
 
487
   protected void addExtraClientConfig(Map config) {}
 
488
   protected void addExtraServerConfig(Map config) {}
 
489
   
 
490
 
 
491
   static class TestInvocationHandler implements ServerInvocationHandler
 
492
   {
 
493
      public Set listeners = new HashSet();
 
494
      
 
495
      public void addListener(InvokerCallbackHandler callbackHandler)
 
496
      {
 
497
         listeners.add(callbackHandler);
 
498
      }
 
499
      public Object invoke(final InvocationRequest invocation) throws Throwable
 
500
      {
 
501
         if (CALLBACK_TEST.equals(invocation.getParameter()))
 
502
         {
 
503
            Iterator it = listeners.iterator();
 
504
            while (it.hasNext())
 
505
            {
 
506
               InvokerCallbackHandler handler = (InvokerCallbackHandler) it.next();
 
507
               handler.handleCallback(new Callback("test"));
 
508
            }
 
509
         }
 
510
         return invocation.getParameter();
 
511
      }
 
512
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
 
513
      public void setMBeanServer(MBeanServer server) {}
 
514
      public void setInvoker(ServerInvoker invoker) {}
 
515
   }
 
516
   
 
517
   
 
518
   static class TestInvokerCallbackHandler implements InvokerCallbackHandler
 
519
   {
 
520
      public int counter;
 
521
      
 
522
      public void handleCallback(Callback callback) throws HandleCallbackException
 
523
      {
 
524
         counter++;
 
525
      }
 
526
   }
 
527
}
 
 
b'\\ No newline at end of file'