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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/callback/acknowledge/CallbackAcknowledgeTestCase.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
 
 
23
 
 
24
 
/**
25
 
 * Tests Callback acknowledgements.
26
 
 *
27
 
 * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
28
 
 * <p/>
29
 
 * Copyright (c) 2006
30
 
 * </p>
31
 
 */
32
 
package org.jboss.test.remoting.callback.acknowledge;
33
 
 
34
 
import java.net.InetAddress;
35
 
import java.util.HashMap;
36
 
import java.util.HashSet;
37
 
import java.util.Iterator;
38
 
import java.util.List;
39
 
import java.util.Map;
40
 
 
41
 
import javax.management.MBeanServer;
42
 
 
43
 
import junit.framework.TestCase;
44
 
 
45
 
import org.jboss.logging.Logger;
46
 
import org.jboss.remoting.Client;
47
 
import org.jboss.remoting.InvocationRequest;
48
 
import org.jboss.remoting.InvokerLocator;
49
 
import org.jboss.remoting.ServerInvocationHandler;
50
 
import org.jboss.remoting.ServerInvoker;
51
 
import org.jboss.remoting.callback.Callback;
52
 
import org.jboss.remoting.callback.CallbackListener;
53
 
import org.jboss.remoting.callback.CallbackPoller;
54
 
import org.jboss.remoting.callback.HandleCallbackException;
55
 
import org.jboss.remoting.callback.InvokerCallbackHandler;
56
 
import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
57
 
import org.jboss.remoting.transport.Connector;
58
 
import org.jboss.remoting.transport.PortUtil;
59
 
 
60
 
 
61
 
public class CallbackAcknowledgeTestCase extends TestCase
62
 
{
63
 
   private static String APPLICATION_ACKNOWLEDGEMENT_TEST = "AppAckTest";
64
 
   private static String REMOTING_ACKNOWLEDGEMENT_TEST = "remotingAckTest";
65
 
   private static Logger log = Logger.getLogger(CallbackAcknowledgeTestCase.class);
66
 
 
67
 
   private Connector connector;
68
 
   private InvokerLocator serverLocator;
69
 
   private String transport = "socket";
70
 
   private Client client;
71
 
 
72
 
 
73
 
   public void setUp() throws Exception
74
 
   {
75
 
      String host = InetAddress.getLocalHost().getHostAddress();
76
 
      int freePort = PortUtil.findFreePort(host);
77
 
      serverLocator = new InvokerLocator(transport + "://" + host + ":" + freePort);
78
 
      HashMap config = new HashMap();
79
 
      config.put(InvokerLocator.FORCE_REMOTE, "true");
80
 
      connector = new Connector(serverLocator, config);
81
 
      connector.start();
82
 
      connector.addInvocationHandler("test", new TestInvocationHandler());
83
 
 
84
 
      client = new Client(serverLocator, config);
85
 
      client.connect();
86
 
 
87
 
      TestInvocationHandler.callbacksAcknowledged = 0;
88
 
      TestInvocationHandler.callbackResponses.clear();
89
 
   }
90
 
 
91
 
 
92
 
   public void tearDown()
93
 
   {
94
 
      if (connector != null)
95
 
         connector.stop();
96
 
 
97
 
      if (client != null)
98
 
         client.disconnect();
99
 
   }
100
 
 
101
 
 
102
 
   /**
103
 
    * In this test, the connection is configured for pull callbacks, and the
104
 
    * acknowledgements should be made by an explicit call to Client.acknowledgeCallback()
105
 
    * after the callbacks have been retrieved and (presumably) processed. Two
106
 
    * InvokerCallbackHandlers are registered.
107
 
    */
108
 
   public void testNonblockingPullApplicationAckDifferentHandlers()
109
 
   {
110
 
      log.info("entering " + getName());
111
 
      try
112
 
      {
113
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
114
 
         client.addListener(callbackHandler1);
115
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
116
 
         client.addListener(callbackHandler2);
117
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
118
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
119
 
         List callbacks1 = client.getCallbacks(callbackHandler1);
120
 
         assertEquals(2, callbacks1.size());
121
 
         List callbacks2 = client.getCallbacks(callbackHandler2);
122
 
         assertEquals(2, callbacks2.size());
123
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
124
 
         assertEquals(2, client.acknowledgeCallbacks(callbackHandler1, callbacks1));
125
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
126
 
         assertEquals(2, client.acknowledgeCallbacks(callbackHandler2, callbacks2));
127
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
128
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
129
 
         Thread.sleep(1000);
130
 
         assertEquals(0, callbackHandler1.callbacksReceived);
131
 
         assertEquals(0, callbackHandler2.callbacksReceived);
132
 
         client.removeListener(callbackHandler1);
133
 
         client.removeListener(callbackHandler2);
134
 
         log.info(getName() + " PASSES");
135
 
      }
136
 
      catch (Throwable e)
137
 
      {
138
 
         log.info(getName() + " FAILS");
139
 
         e.printStackTrace();
140
 
         fail();
141
 
      }
142
 
   }
143
 
 
144
 
 
145
 
   /**
146
 
    * In this test, the connection is configured for pull callbacks, and the
147
 
    * acknowledgements should be made by an explicit call to Client.acknowledgeCallback()
148
 
    * after the callbacks have been retrieved and (presumably) processed. Two
149
 
    * InvokerCallbackHandlers are registered.
150
 
    */
151
 
   public void testBlockingPullApplicationAckDifferentHandlers()
152
 
   {
153
 
      log.info("entering " + getName());
154
 
      try
155
 
      {
156
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
157
 
         client.addListener(callbackHandler1);
158
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
159
 
         client.addListener(callbackHandler2);
160
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
161
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
162
 
         HashMap metadata = new HashMap();
163
 
         metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.BLOCKING);
164
 
         List callbacks1 = client.getCallbacks(callbackHandler1, metadata);
165
 
         assertEquals(2, callbacks1.size());
166
 
         List callbacks2 = client.getCallbacks(callbackHandler2, metadata);
167
 
         assertEquals(2, callbacks2.size());
168
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
169
 
         assertEquals(2, client.acknowledgeCallbacks(callbackHandler1, callbacks1));
170
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
171
 
         assertEquals(2, client.acknowledgeCallbacks(callbackHandler2, callbacks2));
172
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
173
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
174
 
         Thread.sleep(1000);
175
 
         assertEquals(0, callbackHandler1.callbacksReceived);
176
 
         assertEquals(0, callbackHandler2.callbacksReceived);
177
 
         client.removeListener(callbackHandler1);
178
 
         client.removeListener(callbackHandler2);
179
 
         log.info(getName() + " PASSES");
180
 
      }
181
 
      catch (Throwable e)
182
 
      {
183
 
         log.info(getName() + " FAILS");
184
 
         e.printStackTrace();
185
 
         fail();
186
 
      }
187
 
   }
188
 
 
189
 
   
190
 
   /**
191
 
    * In this test, the connection is configured for pull callbacks, and the
192
 
    * acknowledgements should be made by an explicit call to Client.acknowledgeCallback()
193
 
    * after the callbacks have been retrieved and (presumably) processed. A single
194
 
    * InvokerCallbackHandler is registered twice but treated as a single instance.
195
 
    */
196
 
   public void testNonblockingPullApplicationAckSameHandler()
197
 
   {
198
 
      log.info("entering " + getName());
199
 
      try
200
 
      {
201
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler();
202
 
         client.addListener(callbackHandler);
203
 
         client.addListener(callbackHandler);
204
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
205
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
206
 
         List callbacks = client.getCallbacks(callbackHandler);
207
 
         assertEquals(2, callbacks.size());
208
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
209
 
         assertEquals(2, client.acknowledgeCallbacks(callbackHandler, callbacks));
210
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
211
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
212
 
         Thread.sleep(1000);
213
 
         assertEquals(0, callbackHandler.callbacksReceived);
214
 
         client.removeListener(callbackHandler);
215
 
         log.info(getName() + " PASSES");
216
 
      }
217
 
      catch (Throwable e)
218
 
      {
219
 
         log.info(getName() + " FAILS");
220
 
         e.printStackTrace();
221
 
         fail();
222
 
      }
223
 
   }
224
 
 
225
 
   
226
 
   /**
227
 
    * In this test, the connection is configured for pull callbacks, and the
228
 
    * acknowledgements should be made by an explicit call to Client.acknowledgeCallback()
229
 
    * after the callbacks have been retrieved and (presumably) processed. A single
230
 
    * InvokerCallbackHandler is registered twice but treated as a single instance.
231
 
    */
232
 
   public void testBlockingPullApplicationAckSameHandler()
233
 
   {
234
 
      log.info("entering " + getName());
235
 
      try
236
 
      {
237
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler();
238
 
         client.addListener(callbackHandler);
239
 
         client.addListener(callbackHandler);
240
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
241
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
242
 
         HashMap metadata = new HashMap();
243
 
         metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.BLOCKING);
244
 
         List callbacks = client.getCallbacks(callbackHandler, metadata);
245
 
         assertEquals(2, callbacks.size());
246
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
247
 
         assertEquals(2, client.acknowledgeCallbacks(callbackHandler, callbacks));
248
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
249
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
250
 
         Thread.sleep(1000);
251
 
         assertEquals(0, callbackHandler.callbacksReceived);
252
 
         client.removeListener(callbackHandler);
253
 
         log.info(getName() + " PASSES");
254
 
      }
255
 
      catch (Throwable e)
256
 
      {
257
 
         log.info(getName() + " FAILS");
258
 
         e.printStackTrace();
259
 
         fail();
260
 
      }
261
 
   }
262
 
      
263
 
 
264
 
   /**
265
 
    * In this test, the connection is configured for pull callbacks.  The
266
 
    * server requests that Remoting handle push callback acknowledgements,
267
 
    * but that should have no effect.  Instead, callback acknowledgements
268
 
    * should be made by an explicit call to Client.acknowledgeCallback() after
269
 
    * the callback has been retrieved and (presumably) processed.
270
 
    * Two distinct InvokerCallbackHandlers are used.
271
 
    */
272
 
   public void testNonblockingPullRemotingAckDifferentHandlers()
273
 
   {
274
 
      log.info("entering " + getName());
275
 
      try
276
 
      {
277
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
278
 
         client.addListener(callbackHandler1);
279
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
280
 
         client.addListener(callbackHandler2);
281
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
282
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
283
 
         List callbacks1 = client.getCallbacks(callbackHandler1);
284
 
         assertEquals(2, callbacks1.size());
285
 
         List callbacks2 = client.getCallbacks(callbackHandler2);
286
 
         assertEquals(2, callbacks2.size());
287
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
288
 
         assertEquals(2, client.acknowledgeCallbacks(callbackHandler1, callbacks1));
289
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
290
 
         assertEquals(2, client.acknowledgeCallbacks(callbackHandler2, callbacks2));
291
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
292
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
293
 
         Thread.sleep(1000);
294
 
         assertEquals(0, callbackHandler1.callbacksReceived);
295
 
         client.removeListener(callbackHandler1);
296
 
         client.removeListener(callbackHandler2);
297
 
         log.info(getName() + " PASSES");
298
 
      }
299
 
      catch (Throwable e)
300
 
      {
301
 
         log.info(getName() + " FAILS");
302
 
         e.printStackTrace();
303
 
         fail();
304
 
      }
305
 
   }
306
 
 
307
 
   
308
 
   /**
309
 
    * In this test, the connection is configured for pull callbacks.  The
310
 
    * server requests that Remoting handle push callback acknowledgements,
311
 
    * but that should have no effect.  Instead, callback acknowledgements
312
 
    * should be made by an explicit call to Client.acknowledgeCallback() after
313
 
    * the callback has been retrieved and (presumably) processed.
314
 
    * Two distinct InvokerCallbackHandlers are used.
315
 
    */
316
 
   public void testPullRemotingAckDifferentHandlers()
317
 
   {
318
 
      log.info("entering " + getName());
319
 
      try
320
 
      {
321
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
322
 
         client.addListener(callbackHandler1);
323
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
324
 
         client.addListener(callbackHandler2);
325
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
326
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
327
 
         HashMap metadata = new HashMap();
328
 
         metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.BLOCKING);
329
 
         List callbacks1 = client.getCallbacks(callbackHandler1, metadata);
330
 
         assertEquals(2, callbacks1.size());
331
 
         List callbacks2 = client.getCallbacks(callbackHandler2, metadata);
332
 
         assertEquals(2, callbacks2.size());
333
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
334
 
         assertEquals(2, client.acknowledgeCallbacks(callbackHandler1, callbacks1));
335
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
336
 
         assertEquals(2, client.acknowledgeCallbacks(callbackHandler2, callbacks2));
337
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
338
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
339
 
         Thread.sleep(1000);
340
 
         assertEquals(0, callbackHandler1.callbacksReceived);
341
 
         client.removeListener(callbackHandler1);
342
 
         client.removeListener(callbackHandler2);
343
 
         log.info(getName() + " PASSES");
344
 
      }
345
 
      catch (Throwable e)
346
 
      {
347
 
         log.info(getName() + " FAILS");
348
 
         e.printStackTrace();
349
 
         fail();
350
 
      }
351
 
   }
352
 
   
353
 
   
354
 
   /**
355
 
    * In this test, the connection is configured pull callbacks.  The
356
 
    * server requests that Remoting handle push callback acknowledgements,
357
 
    * but that should have no effect. Instead, acknowledgements should be made
358
 
    * by an explicit call to Client.acknowledgeCallback() after the callback
359
 
    * has been retrieved and (presumably) processed. A single InvokerCallbackHandler
360
 
    * is registered twice but treated as a single instance.
361
 
    */
362
 
   public void testNonblockingPullRemotingAckSameHandler()
363
 
   {
364
 
      log.info("entering " + getName());
365
 
      try
366
 
      {
367
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler();
368
 
         client.addListener(callbackHandler);
369
 
         client.addListener(callbackHandler);
370
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
371
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
372
 
         List callbacks = client.getCallbacks(callbackHandler);
373
 
         assertEquals(2, callbacks.size());
374
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
375
 
         assertEquals(2, client.acknowledgeCallbacks(callbackHandler, callbacks));
376
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
377
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
378
 
         Thread.sleep(1000);
379
 
         assertEquals(0, callbackHandler.callbacksReceived);
380
 
         client.removeListener(callbackHandler);
381
 
         log.info(getName() + " PASSES");
382
 
      }
383
 
      catch (Throwable e)
384
 
      {
385
 
         log.info(getName() + " FAILS");
386
 
         e.printStackTrace();
387
 
         fail();
388
 
      }
389
 
   }
390
 
   
391
 
   
392
 
   /**
393
 
    * In this test, the connection is configured pull callbacks.  The
394
 
    * server requests that Remoting handle push callback acknowledgements,
395
 
    * but that should have no effect. Instead, acknowledgements should be made
396
 
    * by an explicit call to Client.acknowledgeCallback() after the callback
397
 
    * has been retrieved and (presumably) processed. A single InvokerCallbackHandler
398
 
    * is registered twice but treated as a single instance.
399
 
    */
400
 
   public void testBlockingPullRemotingAckSameHandler()
401
 
   {
402
 
      log.info("entering " + getName());
403
 
      try
404
 
      {
405
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler();
406
 
         client.addListener(callbackHandler);
407
 
         client.addListener(callbackHandler);
408
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
409
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
410
 
         HashMap metadata = new HashMap();
411
 
         metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.BLOCKING);
412
 
         List callbacks = client.getCallbacks(callbackHandler, metadata);
413
 
         assertEquals(2, callbacks.size());
414
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
415
 
         assertEquals(2, client.acknowledgeCallbacks(callbackHandler, callbacks));
416
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
417
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
418
 
         Thread.sleep(1000);
419
 
         assertEquals(0, callbackHandler.callbacksReceived);
420
 
         client.removeListener(callbackHandler);
421
 
         log.info(getName() + " PASSES");
422
 
      }
423
 
      catch (Throwable e)
424
 
      {
425
 
         log.info(getName() + " FAILS");
426
 
         e.printStackTrace();
427
 
         fail();
428
 
      }
429
 
   }
430
 
 
431
 
 
432
 
   /**
433
 
    * In this test the connection is configured for push callbacks implemented in
434
 
    * Remoting by polling the server for callbacks and pushing them (on the client
435
 
    * side) to the InvokerCallbackHandler.  The acknowledgements should be made
436
 
    * explicitly by the InvokerCallbackHandler.  Two distinct InvokerCallbackHandlers
437
 
    * are registered.
438
 
    */
439
 
   public void testNonblockingPollApplicationAckDifferentHandlers()
440
 
   {
441
 
      log.info("entering " + getName());
442
 
      try
443
 
      {
444
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler(client, 1);
445
 
         HashMap metadata = new HashMap();
446
 
         metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "100");
447
 
         metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.NONBLOCKING);
448
 
         client.addListener(callbackHandler1, metadata);
449
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler(client, 2);
450
 
         client.addListener(callbackHandler2, metadata);
451
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
452
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
453
 
         Thread.sleep(2000);
454
 
         assertEquals(2, callbackHandler1.callbacksReceived);
455
 
         assertEquals(2, callbackHandler2.callbacksReceived);
456
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
457
 
         //key: message #: handler id: callbacks received
458
 
         String response111 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 1: 1";
459
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response111));
460
 
         String response212 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 1: 2";
461
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response212));
462
 
         String response121 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 2: 1";
463
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response121));
464
 
         String response222 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 2: 2";
465
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response222));
466
 
         client.removeListener(callbackHandler1);
467
 
         client.removeListener(callbackHandler2);
468
 
         log.info(getName() + " PASSES");
469
 
      }
470
 
      catch (Throwable e)
471
 
      {
472
 
         log.info(getName() + " FAILS");
473
 
         e.printStackTrace();
474
 
         fail();
475
 
      }
476
 
   }
477
 
 
478
 
 
479
 
   /**
480
 
    * In this test the connection is configured for push callbacks implemented in
481
 
    * Remoting by polling the server for callbacks and pushing them (on the client
482
 
    * side) to the InvokerCallbackHandler.  The acknowledgements should be made
483
 
    * explicitly by the InvokerCallbackHandler.  Two distinct InvokerCallbackHandlers
484
 
    * are registered.
485
 
    */
486
 
   public void testBlockingPollApplicationAckDifferentHandlers()
487
 
   {
488
 
      log.info("entering " + getName());
489
 
      try
490
 
      {
491
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler(client, 1);
492
 
         HashMap metadata = new HashMap();
493
 
         metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.BLOCKING);
494
 
         client.addListener(callbackHandler1, metadata);
495
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler(client, 2);
496
 
         client.addListener(callbackHandler2, metadata);
497
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
498
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
499
 
         Thread.sleep(3000);
500
 
         assertEquals(2, callbackHandler1.callbacksReceived);
501
 
         assertEquals(2, callbackHandler2.callbacksReceived);
502
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
503
 
         //key: message #: handler id: callbacks received
504
 
         String response111 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 1: 1";
505
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response111));
506
 
         String response212 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 1: 2";
507
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response212));
508
 
         String response121 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 2: 1";
509
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response121));
510
 
         String response222 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 2: 2";
511
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response222));
512
 
         client.removeListener(callbackHandler1);
513
 
         client.removeListener(callbackHandler2);
514
 
         log.info(getName() + " PASSES");
515
 
      }
516
 
      catch (Throwable e)
517
 
      {
518
 
         log.info(getName() + " FAILS");
519
 
         e.printStackTrace();
520
 
         fail();
521
 
      }
522
 
   }
523
 
 
524
 
 
525
 
   /**
526
 
    * In this test the connection is configured for push callbacks implemented in
527
 
    * Remoting by polling the server for callbacks and pushing them (on the client
528
 
    * side) to the InvokerCallbackHandler.  A single InvokerCallbackHandler is
529
 
    * registered twice but the Client treats it as a single instance.  The
530
 
    * acknowledgements should be made explicitly by the InvokerCallbackHandler.
531
 
    */
532
 
   public void testNonblockingPollApplicationAckSameHandler()
533
 
   {
534
 
      log.info("entering " + getName());
535
 
      try
536
 
      {
537
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler(client);
538
 
         HashMap metadata = new HashMap();
539
 
         metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "100");
540
 
         metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.NONBLOCKING);
541
 
         client.addListener(callbackHandler, metadata);
542
 
         client.addListener(callbackHandler, metadata);
543
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
544
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
545
 
         Thread.sleep(1000);
546
 
         assertEquals(2, callbackHandler.callbacksReceived);
547
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
548
 
         //key: message #: handler id: callbacks received
549
 
         String response101 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 0: 1";
550
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response101));
551
 
         String response202 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 0: 2";
552
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response202));
553
 
         client.removeListener(callbackHandler);
554
 
         Thread.sleep(4000);
555
 
         log.info(getName() + " PASSES");
556
 
      }
557
 
      catch (Throwable e)
558
 
      {
559
 
         log.info(getName() + " FAILS");
560
 
         e.printStackTrace();
561
 
         fail();
562
 
      }
563
 
   }
564
 
 
565
 
 
566
 
   /**
567
 
    * In this test the connection is configured for push callbacks implemented in
568
 
    * Remoting by polling the server for callbacks and pushing them (on the client
569
 
    * side) to the InvokerCallbackHandler.  A single InvokerCallbackHandler is
570
 
    * registered twice but the Client treats it as a single instance.  The
571
 
    * acknowledgements should be made explicitly by the InvokerCallbackHandler.
572
 
    */
573
 
   public void testBlockingPollApplicationAckSameHandler()
574
 
   {
575
 
      log.info("entering " + getName());
576
 
      try
577
 
      {
578
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler(client);
579
 
         HashMap metadata = new HashMap();
580
 
         metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.BLOCKING);
581
 
         client.addListener(callbackHandler, metadata);
582
 
         client.addListener(callbackHandler, metadata);
583
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
584
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
585
 
         Thread.sleep(1000);
586
 
         assertEquals(2, callbackHandler.callbacksReceived);
587
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
588
 
         //key: message #: handler id: callbacks received
589
 
         String response101 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 0: 1";
590
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response101));
591
 
         String response202 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 0: 2";
592
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response202));
593
 
         client.removeListener(callbackHandler);
594
 
         Thread.sleep(4000);
595
 
         log.info(getName() + " PASSES");
596
 
      }
597
 
      catch (Throwable e)
598
 
      {
599
 
         log.info(getName() + " FAILS");
600
 
         e.printStackTrace();
601
 
         fail();
602
 
      }
603
 
   }
604
 
 
605
 
   
606
 
   /**
607
 
    * In this test the connection is configured for push callbacks implemented in
608
 
    * Remoting by polling the server for callbacks and pushing them (on the client
609
 
    * side) to the InvokerCallbackHandler.  The acknowledgement should be made
610
 
    * implicitly by CallbackPoller, which it does by calling Client.acknowledgeCallback()
611
 
    * after it has pushed the callback to the InvokerCallbackHandler.  Two
612
 
    * distinct InvokerCallbackHandlers are registered.
613
 
    */
614
 
   public void testNonblockingPollRemotingAckDifferentHandlers()
615
 
   {
616
 
      log.info("entering " + getName());
617
 
      try
618
 
      {
619
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
620
 
         HashMap metadata = new HashMap();
621
 
         metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "100");
622
 
         metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.NONBLOCKING);
623
 
         client.addListener(callbackHandler1, metadata);
624
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
625
 
         client.addListener(callbackHandler2, metadata);
626
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
627
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
628
 
         Thread.sleep(2000);
629
 
         assertEquals(2, callbackHandler1.callbacksReceived);
630
 
         assertEquals(2, callbackHandler2.callbacksReceived);
631
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
632
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
633
 
         client.removeListener(callbackHandler1);
634
 
         client.removeListener(callbackHandler2);
635
 
         log.info(getName() + " PASSES");
636
 
      }
637
 
      catch (Throwable e)
638
 
      {
639
 
         log.info(getName() + " FAILS");
640
 
         e.printStackTrace();
641
 
         fail();
642
 
      }
643
 
   }
644
 
 
645
 
   
646
 
   /**
647
 
    * In this test the connection is configured for push callbacks implemented in
648
 
    * Remoting by polling the server for callbacks and pushing them (on the client
649
 
    * side) to the InvokerCallbackHandler.  The acknowledgement should be made
650
 
    * implicitly by CallbackPoller, which it does by calling Client.acknowledgeCallback()
651
 
    * after it has pushed the callback to the InvokerCallbackHandler.  Two
652
 
    * distinct InvokerCallbackHandlers are registered.
653
 
    */
654
 
   public void testBlockingPollRemotingAckDifferentHandlers()
655
 
   {
656
 
      log.info("entering " + getName());
657
 
      try
658
 
      {
659
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
660
 
         HashMap metadata = new HashMap();
661
 
         metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.BLOCKING);
662
 
         client.addListener(callbackHandler1, metadata);
663
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
664
 
         client.addListener(callbackHandler2, metadata);
665
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
666
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
667
 
         Thread.sleep(1000);
668
 
         assertEquals(2, callbackHandler1.callbacksReceived);
669
 
         assertEquals(2, callbackHandler2.callbacksReceived);
670
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
671
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
672
 
         client.removeListener(callbackHandler1);
673
 
         client.removeListener(callbackHandler2);
674
 
         log.info(getName() + " PASSES");
675
 
      }
676
 
      catch (Throwable e)
677
 
      {
678
 
         log.info(getName() + " FAILS");
679
 
         e.printStackTrace();
680
 
         fail();
681
 
      }
682
 
   }
683
 
 
684
 
   
685
 
   /**
686
 
    * In this test the connection is configured for push callbacks implemented in
687
 
    * Remoting by polling the server for callbacks and pushing them (on the client
688
 
    * side) to the InvokerCallbackHandler.  The acknowledgement should be made
689
 
    * implicitly by CallbackPoller, which it does by calling Client.acknowledgeCallback()
690
 
    * after it has pushed the callback to the InvokerCallbackHandler.  A single
691
 
    * InvokerCallbackHandler is registered twice, but the Client recognizes only a
692
 
    * single instance.
693
 
    */
694
 
   public void testNonblockingPollRemotingAckSameHandler()
695
 
   {
696
 
      log.info("entering " + getName());
697
 
      try
698
 
      {
699
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler();
700
 
         HashMap metadata = new HashMap();
701
 
         metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "100");
702
 
         metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.NONBLOCKING);
703
 
         client.addListener(callbackHandler, metadata);
704
 
         client.addListener(callbackHandler, metadata);
705
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
706
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
707
 
         Thread.sleep(1000);
708
 
         assertEquals(2, callbackHandler.callbacksReceived);
709
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
710
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
711
 
         client.removeListener(callbackHandler);
712
 
         log.info(getName() + " PASSES");
713
 
      }
714
 
      catch (Throwable e)
715
 
      {
716
 
         log.info(getName() + " FAILS");
717
 
         e.printStackTrace();
718
 
         fail();
719
 
      }
720
 
   }
721
 
 
722
 
   
723
 
   /**
724
 
    * In this test the connection is configured for push callbacks implemented in
725
 
    * Remoting by polling the server for callbacks and pushing them (on the client
726
 
    * side) to the InvokerCallbackHandler.  The acknowledgement should be made
727
 
    * implicitly by CallbackPoller, which it does by calling Client.acknowledgeCallback()
728
 
    * after it has pushed the callback to the InvokerCallbackHandler.  A single
729
 
    * InvokerCallbackHandler is registered twice, but the Client recognizes only a
730
 
    * single instance.
731
 
    */
732
 
   public void testBlockingPollRemotingAckSameHandler()
733
 
   {
734
 
      log.info("entering " + getName());
735
 
      try
736
 
      {
737
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler();
738
 
         HashMap metadata = new HashMap();
739
 
         metadata.put(ServerInvoker.BLOCKING_MODE, ServerInvoker.BLOCKING);
740
 
         client.addListener(callbackHandler, metadata);
741
 
         client.addListener(callbackHandler, metadata);
742
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
743
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
744
 
         Thread.sleep(1000);
745
 
         assertEquals(2, callbackHandler.callbacksReceived);
746
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
747
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
748
 
         client.removeListener(callbackHandler);
749
 
         log.info(getName() + " PASSES");
750
 
      }
751
 
      catch (Throwable e)
752
 
      {
753
 
         log.info(getName() + " FAILS");
754
 
         e.printStackTrace();
755
 
         fail();
756
 
      }
757
 
   }
758
 
 
759
 
 
760
 
   /**
761
 
    * In this test the connection is configured for true push callbacks, and the
762
 
    * acknowledgements should be made on the client side by the InvokerCallbackHandler.
763
 
    * Two distinct InvokerCallbackHandlers are registered.
764
 
    */
765
 
   public void testPushApplicationAckDifferentHandlers()
766
 
   {
767
 
      log.info("entering " + getName());
768
 
      try
769
 
      {
770
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler(client, 1);
771
 
         client.addListener(callbackHandler1, null, null, true);
772
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler(client, 2);
773
 
         client.addListener(callbackHandler2, null, null, true);
774
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
775
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
776
 
         assertEquals(2, callbackHandler1.callbacksReceived);
777
 
         assertEquals(2, callbackHandler2.callbacksReceived);
778
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
779
 
         //key: message #: handler id: callbacks received
780
 
         String response111 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 1: 1";
781
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response111));
782
 
         String response212 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 1: 2";
783
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response212));
784
 
         String response121 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 2: 1";
785
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response121));
786
 
         String response222 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 2: 2";
787
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response222));
788
 
         client.removeListener(callbackHandler1);
789
 
         client.removeListener(callbackHandler2);
790
 
         log.info(getName() + " PASSES");
791
 
      }
792
 
      catch (Throwable e)
793
 
      {
794
 
         log.info(getName() + " FAILS");
795
 
         e.printStackTrace();
796
 
         fail();
797
 
      }
798
 
   }
799
 
 
800
 
 
801
 
   /**
802
 
    * In this test the connection is configured for true push callbacks, and the
803
 
    * acknowledgement should be made on the client side by the InvokerCallbackHandler.
804
 
    * A single InvokerCallbackHandler is shared by two callback Connectors.
805
 
    */
806
 
   public void testPushApplicationAckSameHandler()
807
 
   {
808
 
      log.info("entering " + getName());
809
 
      try
810
 
      {
811
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler(client);
812
 
         client.addListener(callbackHandler, null, null, true);
813
 
         client.addListener(callbackHandler, null, null, true);
814
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
815
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
816
 
         assertEquals(4, callbackHandler.callbacksReceived);
817
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
818
 
         //key: message #: handler id: callbacks received
819
 
         String response101 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 0: 1";
820
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response101));
821
 
         String response202 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 0: 2";
822
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response202));
823
 
         String response103 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 0: 3";
824
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response103));
825
 
         String response204 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 0: 4";
826
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response204));
827
 
         client.removeListener(callbackHandler);
828
 
         log.info(getName() + " PASSES");
829
 
      }
830
 
      catch (Throwable e)
831
 
      {
832
 
         log.info(getName() + " FAILS");
833
 
         e.printStackTrace();
834
 
         fail();
835
 
      }
836
 
   }
837
 
 
838
 
 
839
 
   /**
840
 
    * In this test the connection is configured for true push callbacks, and the
841
 
    * acknowledgements should be made by ServerInvokerCallbackHandler.handleCallback()
842
 
    * after it has pushed the Callback to the client.  Two distinct
843
 
    * InvokerCallbackHandlers are registered.
844
 
    */
845
 
   public void testPushRemotingAckDifferentHandlers()
846
 
   {
847
 
      log.info("entering " + getName());
848
 
      try
849
 
      {
850
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
851
 
         client.addListener(callbackHandler1, null, null, true);
852
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
853
 
         client.addListener(callbackHandler2, null, null, true);
854
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
855
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
856
 
         assertEquals(2, callbackHandler1.callbacksReceived);
857
 
         assertEquals(2, callbackHandler2.callbacksReceived);
858
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
859
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
860
 
         client.removeListener(callbackHandler1);
861
 
         client.removeListener(callbackHandler2);
862
 
         log.info(getName() + " PASSES");
863
 
      }
864
 
      catch (Throwable e)
865
 
      {
866
 
         log.info(getName() + " FAILS");
867
 
         e.printStackTrace();
868
 
         fail();
869
 
      }
870
 
   }
871
 
 
872
 
 
873
 
   /**
874
 
    * In this test the connection is configured for true push callbacks, and the
875
 
    * acknowledgements should be made by ServerInvokerCallbackHandler.handleCallback()
876
 
    * after it has pushed the Callback to the client.  A single InvokerCallbackHandler
877
 
    * is registered twice, and each is treated as a distinct instance.
878
 
    */
879
 
   public void testPushRemotingAckSameHandler()
880
 
   {
881
 
      log.info("entering " + getName());
882
 
      try
883
 
      {
884
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler();
885
 
         client.addListener(callbackHandler, null, null, true);
886
 
         client.addListener(callbackHandler, null, null, true);
887
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
888
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
889
 
         assertEquals(4, callbackHandler.callbacksReceived);
890
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
891
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
892
 
         client.removeListener(callbackHandler);
893
 
         log.info(getName() + " PASSES");
894
 
      }
895
 
      catch (Throwable e)
896
 
      {
897
 
         log.info(getName() + " FAILS");
898
 
         e.printStackTrace();
899
 
         fail();
900
 
      }
901
 
   }
902
 
 
903
 
 
904
 
   /**
905
 
    * In this test the connection is configured for true push callbacks by creating a
906
 
    * Connector and passing its InvokerLocator when the InvokerCallbackHandlers are
907
 
    * registered.  Acknowledgements should be made on the client side by the
908
 
    * InvokerCallbackHandler. Two distinct InvokerCallbackHandlers are registered with
909
 
    * a single Connector.
910
 
    */
911
 
   public void testPushApplicationAckDifferentHandlersPassLocator()
912
 
   {
913
 
      log.info("entering " + getName());
914
 
      try
915
 
      {
916
 
         String host = InetAddress.getLocalHost().getHostAddress();
917
 
         int freePort = PortUtil.findFreePort(host);
918
 
         InvokerLocator callbackLocator = new InvokerLocator(transport + "://" + host + ":" + freePort);
919
 
         HashMap config = new HashMap();
920
 
         config.put(InvokerLocator.FORCE_REMOTE, "true");
921
 
         Connector connector = new Connector(callbackLocator, config);
922
 
         connector.start();
923
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler(client, 1);
924
 
         client.addListener(callbackHandler1, callbackLocator);
925
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler(client, 2);
926
 
         client.addListener(callbackHandler2, callbackLocator);
927
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
928
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
929
 
         assertEquals(2, callbackHandler1.callbacksReceived);
930
 
         assertEquals(2, callbackHandler2.callbacksReceived);
931
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
932
 
         //key: message #: handler id: callbacks received
933
 
         String response111 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 1: 1";
934
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response111));
935
 
         String response212 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 1: 2";
936
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response212));
937
 
         String response121 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 2: 1";
938
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response121));
939
 
         String response222 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 2: 2";
940
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response222));
941
 
         client.removeListener(callbackHandler1);
942
 
         client.removeListener(callbackHandler2);
943
 
         log.info(getName() + " PASSES");
944
 
      }
945
 
      catch (Throwable e)
946
 
      {
947
 
         log.info(getName() + " FAILS");
948
 
         e.printStackTrace();
949
 
         fail();
950
 
      }
951
 
   }
952
 
 
953
 
 
954
 
   /**
955
 
    * In this test the connection is configured for true push callbacks by creating a
956
 
    * Connector and passing its InvokerLocator when the InvokerCallbackHandlers are
957
 
    * registered.  Acknowledgements should be made on the client side by the
958
 
    * InvokerCallbackHandler. A InvokerCallbackHandler is registered twice with
959
 
    * a single Connector and treated as a single instance.
960
 
    */
961
 
   public void testPushApplicationAckSameHandlerPassLocator()
962
 
   {
963
 
      log.info("entering " + getName());
964
 
      try
965
 
      {
966
 
         String host = InetAddress.getLocalHost().getHostAddress();
967
 
         int freePort = PortUtil.findFreePort(host);
968
 
         InvokerLocator callbackLocator = new InvokerLocator(transport + "://" + host + ":" + freePort);
969
 
         HashMap config = new HashMap();
970
 
         config.put(InvokerLocator.FORCE_REMOTE, "true");
971
 
         Connector connector = new Connector(callbackLocator, config);
972
 
         connector.start();
973
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler(client);
974
 
         client.addListener(callbackHandler, callbackLocator);
975
 
         client.addListener(callbackHandler, callbackLocator);
976
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
977
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
978
 
         assertEquals(2, callbackHandler.callbacksReceived);
979
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
980
 
         //key: message #: handler id: callbacks received
981
 
         String response101 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 0: 1";
982
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response101));
983
 
         String response202 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 0: 2";
984
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response202));
985
 
         client.removeListener(callbackHandler);
986
 
         log.info(getName() + " PASSES");
987
 
      }
988
 
      catch (Throwable e)
989
 
      {
990
 
         log.info(getName() + " FAILS");
991
 
         e.printStackTrace();
992
 
         fail();
993
 
      }
994
 
   }
995
 
 
996
 
 
997
 
   /**
998
 
    * In this test the connection is configured for true push callbacks by creating
999
 
    * two Connectors and passing their InvokerLocator when the InvokerCallbackHandlers
1000
 
    * are registered.  Acknowledgements should be made on the client side by the
1001
 
    * InvokerCallbackHandler. Each of two distinct InvokerCallbackHandlers is
1002
 
    * registered with a distinct Connector
1003
 
    */
1004
 
   public void testPushApplicationAckDifferentHandlersPassTwoLocators()
1005
 
   {
1006
 
      log.info("entering " + getName());
1007
 
      try
1008
 
      {
1009
 
         String host = InetAddress.getLocalHost().getHostAddress();
1010
 
         int freePort = PortUtil.findFreePort(host);
1011
 
         InvokerLocator callbackLocator1 = new InvokerLocator(transport + "://" + host + ":" + freePort);
1012
 
         HashMap config = new HashMap();
1013
 
         config.put(InvokerLocator.FORCE_REMOTE, "true");
1014
 
         Connector connector1 = new Connector(callbackLocator1, config);
1015
 
         connector1.start();
1016
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler(client, 1);
1017
 
         client.addListener(callbackHandler1, callbackLocator1);
1018
 
         freePort = PortUtil.findFreePort(host);
1019
 
         InvokerLocator callbackLocator2 = new InvokerLocator(transport + "://" + host + ":" + freePort);
1020
 
         Connector connector2 = new Connector(callbackLocator2, config);
1021
 
         connector2.start();
1022
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler(client, 2);
1023
 
         client.addListener(callbackHandler2, callbackLocator2);
1024
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
1025
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
1026
 
         assertEquals(2, callbackHandler1.callbacksReceived);
1027
 
         assertEquals(2, callbackHandler2.callbacksReceived);
1028
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
1029
 
         //key: message #: handler id: callbacks received
1030
 
         String response111 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 1: 1";
1031
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response111));
1032
 
         String response212 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 1: 2";
1033
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response212));
1034
 
         String response121 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 2: 1";
1035
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response121));
1036
 
         String response222 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 2: 2";
1037
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response222));
1038
 
         client.removeListener(callbackHandler1);
1039
 
         client.removeListener(callbackHandler2);
1040
 
         log.info(getName() + " PASSES");
1041
 
      }
1042
 
      catch (Throwable e)
1043
 
      {
1044
 
         log.info(getName() + " FAILS");
1045
 
         e.printStackTrace();
1046
 
         fail();
1047
 
      }
1048
 
   }
1049
 
 
1050
 
 
1051
 
   /**
1052
 
    * In this test the connection is configured for true push callbacks by creating
1053
 
    * two Connectors and passing their InvokerLocator when the InvokerCallbackHandlers
1054
 
    * are registered.  Acknowledgements should be made on the client side by the
1055
 
    * InvokerCallbackHandler. A single InvokerCallbackHandlers is registered with
1056
 
    * two distinct Connectors.
1057
 
    */
1058
 
   public void testPushApplicationAckSameHandlerPassTwoLocators()
1059
 
   {
1060
 
      log.info("entering " + getName());
1061
 
      try
1062
 
      {
1063
 
         String host = InetAddress.getLocalHost().getHostAddress();
1064
 
         int freePort = PortUtil.findFreePort(host);
1065
 
         InvokerLocator callbackLocator1 = new InvokerLocator(transport + "://" + host + ":" + freePort);
1066
 
         HashMap config = new HashMap();
1067
 
         config.put(InvokerLocator.FORCE_REMOTE, "true");
1068
 
         Connector connector1 = new Connector(callbackLocator1, config);
1069
 
         connector1.start();
1070
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler(client);
1071
 
         client.addListener(callbackHandler, callbackLocator1);
1072
 
         freePort = PortUtil.findFreePort(host);
1073
 
         InvokerLocator callbackLocator2 = new InvokerLocator(transport + "://" + host + ":" + freePort);
1074
 
         Connector connector2 = new Connector(callbackLocator2, config);
1075
 
         connector2.start();
1076
 
         client.addListener(callbackHandler, callbackLocator2);
1077
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
1078
 
         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
1079
 
         assertEquals(4, callbackHandler.callbacksReceived);
1080
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
1081
 
         //key: message #: handler id: callbacks received
1082
 
         String response101 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 0: 1";
1083
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response101));
1084
 
         String response202 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 0: 2";
1085
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response202));
1086
 
         String response103 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 0: 3";
1087
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response103));
1088
 
         String response204 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 0: 4";
1089
 
         assertTrue(TestInvocationHandler.callbackResponses.contains(response204));
1090
 
         client.removeListener(callbackHandler);
1091
 
         log.info(getName() + " PASSES");
1092
 
      }
1093
 
      catch (Throwable e)
1094
 
      {
1095
 
         log.info(getName() + " FAILS");
1096
 
         e.printStackTrace();
1097
 
         fail();
1098
 
      }
1099
 
   }
1100
 
 
1101
 
 
1102
 
   /**
1103
 
    * In this test the connection is configured for true push callbacks by creating a
1104
 
    * Connector and passing its InvokerLocator when the InvokerCallbackHandlers are
1105
 
    * registered.  Acknowledgements should be made implicitly on the server side by the
1106
 
    * ServerInvokerCallbackHandler. Two distinct InvokerCallbackHandlers are registered
1107
 
    * with a single Connector.
1108
 
    */
1109
 
   public void testPushRemotingAckDifferentHandlersPassLocator()
1110
 
   {
1111
 
      log.info("entering " + getName());
1112
 
      try
1113
 
      {
1114
 
         String host = InetAddress.getLocalHost().getHostAddress();
1115
 
         int freePort = PortUtil.findFreePort(host);
1116
 
         InvokerLocator callbackLocator = new InvokerLocator(transport + "://" + host + ":" + freePort);
1117
 
         HashMap config = new HashMap();
1118
 
         config.put(InvokerLocator.FORCE_REMOTE, "true");
1119
 
         Connector connector = new Connector(callbackLocator, config);
1120
 
         connector.start();
1121
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler(client, 1);
1122
 
         client.addListener(callbackHandler1, callbackLocator);
1123
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler(client, 2);
1124
 
         client.addListener(callbackHandler2, callbackLocator);
1125
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
1126
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
1127
 
         assertEquals(2, callbackHandler1.callbacksReceived);
1128
 
         assertEquals(2, callbackHandler2.callbacksReceived);
1129
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
1130
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
1131
 
         client.removeListener(callbackHandler1);
1132
 
         client.removeListener(callbackHandler2);
1133
 
         log.info(getName() + " PASSES");
1134
 
      }
1135
 
      catch (Throwable e)
1136
 
      {
1137
 
         log.info(getName() + " FAILS");
1138
 
         e.printStackTrace();
1139
 
         fail();
1140
 
      }
1141
 
   }
1142
 
 
1143
 
 
1144
 
   /**
1145
 
    * In this test the connection is configured for true push callbacks by creating a
1146
 
    * Connector and passing its InvokerLocator when the InvokerCallbackHandlers are
1147
 
    * registered.  Acknowledgements should be made implicitly on the server side by the
1148
 
    * ServerInvokerCallbackHandler. A InvokerCallbackHandler is registered twice with
1149
 
    * a single Connector and treated as a single instance.
1150
 
    */
1151
 
   public void testPushRemotingAckSameHandlerPassLocator()
1152
 
   {
1153
 
      log.info("entering " + getName());
1154
 
      try
1155
 
      {
1156
 
         String host = InetAddress.getLocalHost().getHostAddress();
1157
 
         int freePort = PortUtil.findFreePort(host);
1158
 
         InvokerLocator callbackLocator = new InvokerLocator(transport + "://" + host + ":" + freePort);
1159
 
         HashMap config = new HashMap();
1160
 
         config.put(InvokerLocator.FORCE_REMOTE, "true");
1161
 
         Connector connector = new Connector(callbackLocator, config);
1162
 
         connector.start();
1163
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler(client);
1164
 
         client.addListener(callbackHandler, callbackLocator);
1165
 
         client.addListener(callbackHandler, callbackLocator);
1166
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
1167
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
1168
 
         assertEquals(2, callbackHandler.callbacksReceived);
1169
 
         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
1170
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
1171
 
         client.removeListener(callbackHandler);
1172
 
         log.info(getName() + " PASSES");
1173
 
      }
1174
 
      catch (Throwable e)
1175
 
      {
1176
 
         log.info(getName() + " FAILS");
1177
 
         e.printStackTrace();
1178
 
         fail();
1179
 
      }
1180
 
   }
1181
 
 
1182
 
 
1183
 
   /**
1184
 
    * In this test the connection is configured for true push callbacks by creating
1185
 
    * two Connectors and passing their InvokerLocator when the InvokerCallbackHandlers
1186
 
    * are registered.  Acknowledgements should be made implicitly on the server side by the
1187
 
    * ServerInvokerCallbackHandler. Each of two distinct InvokerCallbackHandlers is
1188
 
    * registered with a distinct Connector
1189
 
    */
1190
 
   public void testPushRemotingAckDifferentHandlersPassTwoLocators()
1191
 
   {
1192
 
      log.info("entering " + getName());
1193
 
      try
1194
 
      {
1195
 
         String host = InetAddress.getLocalHost().getHostAddress();
1196
 
         int freePort = PortUtil.findFreePort(host);
1197
 
         InvokerLocator callbackLocator1 = new InvokerLocator(transport + "://" + host + ":" + freePort);
1198
 
         HashMap config = new HashMap();
1199
 
         config.put(InvokerLocator.FORCE_REMOTE, "true");
1200
 
         Connector connector1 = new Connector(callbackLocator1, config);
1201
 
         connector1.start();
1202
 
         TestCallbackHandler callbackHandler1 = new TestCallbackHandler(client, 1);
1203
 
         client.addListener(callbackHandler1, callbackLocator1);
1204
 
         freePort = PortUtil.findFreePort(host);
1205
 
         InvokerLocator callbackLocator2 = new InvokerLocator(transport + "://" + host + ":" + freePort);
1206
 
         Connector connector2 = new Connector(callbackLocator2, config);
1207
 
         connector2.start();
1208
 
         TestCallbackHandler callbackHandler2 = new TestCallbackHandler(client, 2);
1209
 
         client.addListener(callbackHandler2, callbackLocator2);
1210
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
1211
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
1212
 
         assertEquals(2, callbackHandler1.callbacksReceived);
1213
 
         assertEquals(2, callbackHandler2.callbacksReceived);
1214
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
1215
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
1216
 
         client.removeListener(callbackHandler1);
1217
 
         client.removeListener(callbackHandler2);
1218
 
         log.info(getName() + " PASSES");
1219
 
      }
1220
 
      catch (Throwable e)
1221
 
      {
1222
 
         log.info(getName() + " FAILS");
1223
 
         e.printStackTrace();
1224
 
         fail();
1225
 
      }
1226
 
   }
1227
 
 
1228
 
 
1229
 
   /**
1230
 
    * In this test the connection is configured for true push callbacks by creating
1231
 
    * two Connectors and passing their InvokerLocator when the InvokerCallbackHandlers
1232
 
    * are registered.  Acknowledgements should be made implicitly on the server side by the
1233
 
    * ServerInvokerCallbackHandler. A single InvokerCallbackHandlers is registered with
1234
 
    * two distinct Connectors.
1235
 
    */
1236
 
   public void testPushRemotingAckSameHandlerPassTwoLocators()
1237
 
   {
1238
 
      log.info("entering " + getName());
1239
 
      try
1240
 
      {
1241
 
         String host = InetAddress.getLocalHost().getHostAddress();
1242
 
         int freePort = PortUtil.findFreePort(host);
1243
 
         InvokerLocator callbackLocator1 = new InvokerLocator(transport + "://" + host + ":" + freePort);
1244
 
         HashMap config = new HashMap();
1245
 
         config.put(InvokerLocator.FORCE_REMOTE, "true");
1246
 
         Connector connector1 = new Connector(callbackLocator1, config);
1247
 
         connector1.start();
1248
 
         TestCallbackHandler callbackHandler = new TestCallbackHandler(client);
1249
 
         client.addListener(callbackHandler, callbackLocator1);
1250
 
         freePort = PortUtil.findFreePort(host);
1251
 
         InvokerLocator callbackLocator2 = new InvokerLocator(transport + "://" + host + ":" + freePort);
1252
 
         Connector connector2 = new Connector(callbackLocator2, config);
1253
 
         connector2.start();
1254
 
         client.addListener(callbackHandler, callbackLocator2);
1255
 
         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
1256
 
         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
1257
 
         assertEquals(4, callbackHandler.callbacksReceived);
1258
 
         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
1259
 
         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
1260
 
         client.removeListener(callbackHandler);
1261
 
         log.info(getName() + " PASSES");
1262
 
      }
1263
 
      catch (Throwable e)
1264
 
      {
1265
 
         log.info(getName() + " FAILS");
1266
 
         e.printStackTrace();
1267
 
         fail();
1268
 
      }
1269
 
   }
1270
 
 
1271
 
 
1272
 
   static class TestInvocationHandler implements ServerInvocationHandler, CallbackListener
1273
 
   {
1274
 
      static int callbacksAcknowledged;
1275
 
      static HashSet callbackResponses = new HashSet();
1276
 
 
1277
 
      HashSet callbackHandlers = new HashSet();
1278
 
 
1279
 
      public void setMBeanServer(MBeanServer server) {}
1280
 
      public void setInvoker(ServerInvoker invoker) {}
1281
 
 
1282
 
      public Object invoke(InvocationRequest invocation) throws Throwable
1283
 
      {
1284
 
         String command = (String) invocation.getParameter();
1285
 
         System.out.println("command: " + command);
1286
 
 
1287
 
         for (Iterator it = callbackHandlers.iterator(); it.hasNext(); )
1288
 
         {
1289
 
            InvokerCallbackHandler callbackHandler = (InvokerCallbackHandler) it.next();
1290
 
            Callback cb1 = new Callback(command + "1");
1291
 
            HashMap returnPayload1 = new HashMap();
1292
 
            returnPayload1.put(ServerInvokerCallbackHandler.CALLBACK_ID, command + "1");
1293
 
            returnPayload1.put(ServerInvokerCallbackHandler.CALLBACK_LISTENER, this);
1294
 
            cb1.setReturnPayload(returnPayload1);
1295
 
            if (REMOTING_ACKNOWLEDGEMENT_TEST.equals(command))
1296
 
            {
1297
 
               returnPayload1.put(ServerInvokerCallbackHandler.REMOTING_ACKNOWLEDGES_PUSH_CALLBACKS, "true");
1298
 
            }
1299
 
            else
1300
 
            {
1301
 
               returnPayload1.put(APPLICATION_ACKNOWLEDGEMENT_TEST, "true");
1302
 
            }
1303
 
            callbackHandler.handleCallback(cb1);
1304
 
 
1305
 
            Callback cb2 = new Callback(command + "2");
1306
 
            HashMap returnPayload2 = new HashMap();
1307
 
            returnPayload2.put(ServerInvokerCallbackHandler.CALLBACK_ID, command + "2");
1308
 
            returnPayload2.put(ServerInvokerCallbackHandler.CALLBACK_LISTENER, this);
1309
 
            cb2.setReturnPayload(returnPayload2);
1310
 
            if (REMOTING_ACKNOWLEDGEMENT_TEST.equals(command))
1311
 
            {
1312
 
               returnPayload2.put(ServerInvokerCallbackHandler.REMOTING_ACKNOWLEDGES_PUSH_CALLBACKS, "true");
1313
 
            }
1314
 
            else
1315
 
            {
1316
 
               returnPayload2.put(APPLICATION_ACKNOWLEDGEMENT_TEST, "true");
1317
 
            }
1318
 
            callbackHandler.handleCallback(cb2);
1319
 
         }
1320
 
         return null;
1321
 
      }
1322
 
 
1323
 
      public void addListener(InvokerCallbackHandler callbackHandler)
1324
 
      {
1325
 
         callbackHandlers.add(callbackHandler);
1326
 
      }
1327
 
 
1328
 
      public void removeListener(InvokerCallbackHandler callbackHandler)
1329
 
      {
1330
 
      }
1331
 
 
1332
 
      public void acknowledgeCallback(InvokerCallbackHandler callbackHandler,
1333
 
                                      Object callbackId, Object response)
1334
 
      {
1335
 
         callbacksAcknowledged++;
1336
 
         if (response != null)
1337
 
            callbackResponses.add(response);
1338
 
      }
1339
 
   }
1340
 
 
1341
 
   static class TestCallbackHandler implements InvokerCallbackHandler
1342
 
   {
1343
 
      public int callbacksReceived;
1344
 
      private Client client;
1345
 
      private int id;
1346
 
 
1347
 
      public TestCallbackHandler()
1348
 
      {
1349
 
         this(null);
1350
 
      }
1351
 
      public TestCallbackHandler(Client client)
1352
 
      {
1353
 
         this(client, 0);
1354
 
      }
1355
 
      public TestCallbackHandler(Client client, int id)
1356
 
      {
1357
 
         this.client = client;
1358
 
         this.id = id;
1359
 
      }
1360
 
 
1361
 
      public void handleCallback(Callback callback) throws HandleCallbackException
1362
 
      {
1363
 
         log.info("entering handleCallback()");
1364
 
         callbacksReceived++;
1365
 
 
1366
 
         Map returnMap = callback.getReturnPayload();
1367
 
         if (returnMap.get(APPLICATION_ACKNOWLEDGEMENT_TEST) == null)
1368
 
            return;
1369
 
 
1370
 
         String test = (String) callback.getParameter();
1371
 
         try
1372
 
         {
1373
 
            client.acknowledgeCallback(this, callback, test + ": " + id + ": " + callbacksReceived);
1374
 
         }
1375
 
         catch (Throwable e)
1376
 
         {
1377
 
            log.error(e);
1378
 
            e.printStackTrace();
1379
 
            throw new HandleCallbackException(e.getMessage());
1380
 
         }
1381
 
      }
1382
 
   }
1383
 
}