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.
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.
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.
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.
25
* Tests Callback acknowledgements.
27
* @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
32
package org.jboss.test.remoting.callback.acknowledge;
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;
41
import javax.management.MBeanServer;
43
import junit.framework.TestCase;
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;
61
public class CallbackAcknowledgeTestCase extends TestCase
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);
67
private Connector connector;
68
private InvokerLocator serverLocator;
69
private String transport = "socket";
70
private Client client;
73
public void setUp() throws Exception
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);
82
connector.addInvocationHandler("test", new TestInvocationHandler());
84
client = new Client(serverLocator, config);
87
TestInvocationHandler.callbacksAcknowledged = 0;
88
TestInvocationHandler.callbackResponses.clear();
92
public void tearDown()
94
if (connector != null)
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.
108
public void testNonblockingPullApplicationAckDifferentHandlers()
110
log.info("entering " + getName());
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());
130
assertEquals(0, callbackHandler1.callbacksReceived);
131
assertEquals(0, callbackHandler2.callbacksReceived);
132
client.removeListener(callbackHandler1);
133
client.removeListener(callbackHandler2);
134
log.info(getName() + " PASSES");
138
log.info(getName() + " FAILS");
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.
151
public void testBlockingPullApplicationAckDifferentHandlers()
153
log.info("entering " + getName());
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());
175
assertEquals(0, callbackHandler1.callbacksReceived);
176
assertEquals(0, callbackHandler2.callbacksReceived);
177
client.removeListener(callbackHandler1);
178
client.removeListener(callbackHandler2);
179
log.info(getName() + " PASSES");
183
log.info(getName() + " FAILS");
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.
196
public void testNonblockingPullApplicationAckSameHandler()
198
log.info("entering " + getName());
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());
213
assertEquals(0, callbackHandler.callbacksReceived);
214
client.removeListener(callbackHandler);
215
log.info(getName() + " PASSES");
219
log.info(getName() + " FAILS");
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.
232
public void testBlockingPullApplicationAckSameHandler()
234
log.info("entering " + getName());
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());
251
assertEquals(0, callbackHandler.callbacksReceived);
252
client.removeListener(callbackHandler);
253
log.info(getName() + " PASSES");
257
log.info(getName() + " FAILS");
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.
272
public void testNonblockingPullRemotingAckDifferentHandlers()
274
log.info("entering " + getName());
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());
294
assertEquals(0, callbackHandler1.callbacksReceived);
295
client.removeListener(callbackHandler1);
296
client.removeListener(callbackHandler2);
297
log.info(getName() + " PASSES");
301
log.info(getName() + " FAILS");
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.
316
public void testPullRemotingAckDifferentHandlers()
318
log.info("entering " + getName());
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());
340
assertEquals(0, callbackHandler1.callbacksReceived);
341
client.removeListener(callbackHandler1);
342
client.removeListener(callbackHandler2);
343
log.info(getName() + " PASSES");
347
log.info(getName() + " FAILS");
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.
362
public void testNonblockingPullRemotingAckSameHandler()
364
log.info("entering " + getName());
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());
379
assertEquals(0, callbackHandler.callbacksReceived);
380
client.removeListener(callbackHandler);
381
log.info(getName() + " PASSES");
385
log.info(getName() + " FAILS");
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.
400
public void testBlockingPullRemotingAckSameHandler()
402
log.info("entering " + getName());
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());
419
assertEquals(0, callbackHandler.callbacksReceived);
420
client.removeListener(callbackHandler);
421
log.info(getName() + " PASSES");
425
log.info(getName() + " FAILS");
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
439
public void testNonblockingPollApplicationAckDifferentHandlers()
441
log.info("entering " + getName());
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);
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");
472
log.info(getName() + " FAILS");
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
486
public void testBlockingPollApplicationAckDifferentHandlers()
488
log.info("entering " + getName());
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);
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");
518
log.info(getName() + " FAILS");
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.
532
public void testNonblockingPollApplicationAckSameHandler()
534
log.info("entering " + getName());
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);
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);
555
log.info(getName() + " PASSES");
559
log.info(getName() + " FAILS");
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.
573
public void testBlockingPollApplicationAckSameHandler()
575
log.info("entering " + getName());
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);
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);
595
log.info(getName() + " PASSES");
599
log.info(getName() + " FAILS");
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.
614
public void testNonblockingPollRemotingAckDifferentHandlers()
616
log.info("entering " + getName());
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);
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");
639
log.info(getName() + " FAILS");
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.
654
public void testBlockingPollRemotingAckDifferentHandlers()
656
log.info("entering " + getName());
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);
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");
678
log.info(getName() + " FAILS");
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
694
public void testNonblockingPollRemotingAckSameHandler()
696
log.info("entering " + getName());
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);
708
assertEquals(2, callbackHandler.callbacksReceived);
709
assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
710
assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
711
client.removeListener(callbackHandler);
712
log.info(getName() + " PASSES");
716
log.info(getName() + " FAILS");
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
732
public void testBlockingPollRemotingAckSameHandler()
734
log.info("entering " + getName());
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);
745
assertEquals(2, callbackHandler.callbacksReceived);
746
assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
747
assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
748
client.removeListener(callbackHandler);
749
log.info(getName() + " PASSES");
753
log.info(getName() + " FAILS");
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.
765
public void testPushApplicationAckDifferentHandlers()
767
log.info("entering " + getName());
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");
794
log.info(getName() + " FAILS");
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.
806
public void testPushApplicationAckSameHandler()
808
log.info("entering " + getName());
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");
832
log.info(getName() + " FAILS");
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.
845
public void testPushRemotingAckDifferentHandlers()
847
log.info("entering " + getName());
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");
866
log.info(getName() + " FAILS");
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.
879
public void testPushRemotingAckSameHandler()
881
log.info("entering " + getName());
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");
897
log.info(getName() + " FAILS");
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.
911
public void testPushApplicationAckDifferentHandlersPassLocator()
913
log.info("entering " + getName());
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);
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");
947
log.info(getName() + " FAILS");
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.
961
public void testPushApplicationAckSameHandlerPassLocator()
963
log.info("entering " + getName());
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);
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");
990
log.info(getName() + " FAILS");
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
1004
public void testPushApplicationAckDifferentHandlersPassTwoLocators()
1006
log.info("entering " + getName());
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);
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);
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");
1044
log.info(getName() + " FAILS");
1045
e.printStackTrace();
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.
1058
public void testPushApplicationAckSameHandlerPassTwoLocators()
1060
log.info("entering " + getName());
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);
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);
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");
1095
log.info(getName() + " FAILS");
1096
e.printStackTrace();
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.
1109
public void testPushRemotingAckDifferentHandlersPassLocator()
1111
log.info("entering " + getName());
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);
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");
1137
log.info(getName() + " FAILS");
1138
e.printStackTrace();
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.
1151
public void testPushRemotingAckSameHandlerPassLocator()
1153
log.info("entering " + getName());
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);
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");
1176
log.info(getName() + " FAILS");
1177
e.printStackTrace();
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
1190
public void testPushRemotingAckDifferentHandlersPassTwoLocators()
1192
log.info("entering " + getName());
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);
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);
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");
1222
log.info(getName() + " FAILS");
1223
e.printStackTrace();
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.
1236
public void testPushRemotingAckSameHandlerPassTwoLocators()
1238
log.info("entering " + getName());
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);
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);
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");
1265
log.info(getName() + " FAILS");
1266
e.printStackTrace();
1272
static class TestInvocationHandler implements ServerInvocationHandler, CallbackListener
1274
static int callbacksAcknowledged;
1275
static HashSet callbackResponses = new HashSet();
1277
HashSet callbackHandlers = new HashSet();
1279
public void setMBeanServer(MBeanServer server) {}
1280
public void setInvoker(ServerInvoker invoker) {}
1282
public Object invoke(InvocationRequest invocation) throws Throwable
1284
String command = (String) invocation.getParameter();
1285
System.out.println("command: " + command);
1287
for (Iterator it = callbackHandlers.iterator(); it.hasNext(); )
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))
1297
returnPayload1.put(ServerInvokerCallbackHandler.REMOTING_ACKNOWLEDGES_PUSH_CALLBACKS, "true");
1301
returnPayload1.put(APPLICATION_ACKNOWLEDGEMENT_TEST, "true");
1303
callbackHandler.handleCallback(cb1);
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))
1312
returnPayload2.put(ServerInvokerCallbackHandler.REMOTING_ACKNOWLEDGES_PUSH_CALLBACKS, "true");
1316
returnPayload2.put(APPLICATION_ACKNOWLEDGEMENT_TEST, "true");
1318
callbackHandler.handleCallback(cb2);
1323
public void addListener(InvokerCallbackHandler callbackHandler)
1325
callbackHandlers.add(callbackHandler);
1328
public void removeListener(InvokerCallbackHandler callbackHandler)
1332
public void acknowledgeCallback(InvokerCallbackHandler callbackHandler,
1333
Object callbackId, Object response)
1335
callbacksAcknowledged++;
1336
if (response != null)
1337
callbackResponses.add(response);
1341
static class TestCallbackHandler implements InvokerCallbackHandler
1343
public int callbacksReceived;
1344
private Client client;
1347
public TestCallbackHandler()
1351
public TestCallbackHandler(Client client)
1355
public TestCallbackHandler(Client client, int id)
1357
this.client = client;
1361
public void handleCallback(Callback callback) throws HandleCallbackException
1363
log.info("entering handleCallback()");
1364
callbacksReceived++;
1366
Map returnMap = callback.getReturnPayload();
1367
if (returnMap.get(APPLICATION_ACKNOWLEDGEMENT_TEST) == null)
1370
String test = (String) callback.getParameter();
1373
client.acknowledgeCallback(this, callback, test + ": " + id + ": " + callbacksReceived);
1378
e.printStackTrace();
1379
throw new HandleCallbackException(e.getMessage());