[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/callback/acknowledge ...

Ron Sigal ron_sigal at yahoo.com
Thu Nov 16 02:10:58 EST 2006


  User: rsigal  
  Date: 06/11/16 02:10:58

  Modified:    src/tests/org/jboss/test/remoting/callback/acknowledge  Tag:
                        remoting_2_x CallbackAcknowledgeTestCase.java
  Log:
  JBREM-605:  (1) Removed preprocess acknowledgements and (2) add acknowledgement responses.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.2   +713 -178  JBossRemoting/src/tests/org/jboss/test/remoting/callback/acknowledge/CallbackAcknowledgeTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CallbackAcknowledgeTestCase.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/callback/acknowledge/CallbackAcknowledgeTestCase.java,v
  retrieving revision 1.2.2.1
  retrieving revision 1.2.2.2
  diff -u -b -r1.2.2.1 -r1.2.2.2
  --- CallbackAcknowledgeTestCase.java	6 Nov 2006 07:12:47 -0000	1.2.2.1
  +++ CallbackAcknowledgeTestCase.java	16 Nov 2006 07:10:58 -0000	1.2.2.2
  @@ -33,7 +33,10 @@
   
   import java.net.InetAddress;
   import java.util.HashMap;
  +import java.util.HashSet;
  +import java.util.Iterator;
   import java.util.List;
  +import java.util.Map;
   
   import javax.management.MBeanServer;
   
  @@ -57,9 +60,8 @@
   
   public class CallbackAcknowledgeTestCase extends TestCase
   {
  -   private static String PREPROCESS_TEST = "preprocessTest";
  -   private static String POSTPROCESS_TEST = "postprocessTest";
  -   private static String PRE_AND_POSTPROCESS_TEST = "preAndPostprocessTest";
  +   private static String APPLICATION_ACKNOWLEDGEMENT_TEST = "AppAckTest";
  +   private static String REMOTING_ACKNOWLEDGEMENT_TEST = "remotingAckTest";
      private static Logger log = Logger.getLogger(CallbackAcknowledgeTestCase.class);
      
      private Connector connector;
  @@ -73,18 +75,17 @@
         String host = InetAddress.getLocalHost().getHostAddress();
         int freePort = PortUtil.findFreePort(host);
         serverLocator = new InvokerLocator(transport + "://" + host + ":" + freePort);
  -      connector = new Connector(serverLocator);
  -      connector.start();
  -      connector.addInvocationHandler("test", new TestInvoocationHandler());
  -      
         HashMap config = new HashMap();
         config.put(InvokerLocator.FORCE_REMOTE, "true");
  +      connector = new Connector(serverLocator, config);
  +      connector.start();
  +      connector.addInvocationHandler("test", new TestInvocationHandler());
  +      
         client = new Client(serverLocator, config);
         client.connect();
         
  -      TestInvoocationHandler.acknowledgedPreprocess = false;
  -      TestInvoocationHandler.acknowledgedPostprocess = false;
  -      TestCallbackHandler.callbacksReceived = 0;
  +      TestInvocationHandler.callbacksAcknowledged = 0;
  +      TestInvocationHandler.callbackResponses.clear();
      }
      
      
  @@ -99,30 +100,37 @@
   
      
      /**
  -    * In this test the connection is configured for true pull callbacks, and
  -    * the acknowledgement should be made implicitly by ServerInvokerCallbackHandler
  -    * during the call to getCallbacks() (before the callbacks are retrieved by
  -    * the client).
  +    * In this test, the connection is configured for pull callbacks, and the 
  +    * acknowledgements should be made by an explicit call to Client.acknowledgeCallback()
  +    * after the callbacks have been retrieved and (presumably) processed. Two 
  +    * InvokerCallbackHandlers are registered.
       */
  -   public void testPullCallbackPreprocessAcknowledgement()
  +   public void testPullApplicationAckDifferentHandlers()
      {
         log.info("entering " + getName());
         try
         {
  -         TestCallbackHandler callbackHandler = new TestCallbackHandler();
  -         client.addListener(callbackHandler);
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  -         client.invoke(PREPROCESS_TEST);
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  -         List callbacks = client.getCallbacks(callbackHandler);
  -         assertEquals(2, callbacks.size());
  -         assertTrue(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  +         TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
  +         client.addListener(callbackHandler1);
  +         TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
  +         client.addListener(callbackHandler2);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
  +         List callbacks1 = client.getCallbacks(callbackHandler1);
  +         assertEquals(2, callbacks1.size());
  +         List callbacks2 = client.getCallbacks(callbackHandler2);
  +         assertEquals(2, callbacks2.size());
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         assertEquals(2, client.acknowledgeCallbacks(callbackHandler1, callbacks1));
  +         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
  +         assertEquals(2, client.acknowledgeCallbacks(callbackHandler2, callbacks2));
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
            Thread.sleep(1000);
  -         assertEquals(0, TestCallbackHandler.callbacksReceived);
  -         client.removeListener(callbackHandler);
  +         assertEquals(0, callbackHandler1.callbacksReceived);
  +         assertEquals(0, callbackHandler2.callbacksReceived);
  +         client.removeListener(callbackHandler1);
  +         client.removeListener(callbackHandler2);
            log.info(getName() + " PASSES");
         }
         catch (Throwable e)
  @@ -135,29 +143,29 @@
      
      
      /**
  -    * In this test, the connection is configured for true pull callbacks, and the 
  -    * acknowledgement should be made by an explicit call to Client.acknowledgeCallback()
  -    * after the callback has been retrieved and (presumably) processed.
  +    * In this test, the connection is configured for pull callbacks, and the 
  +    * acknowledgements should be made by an explicit call to Client.acknowledgeCallback()
  +    * after the callbacks have been retrieved and (presumably) processed. A single
  +    * InvokerCallbackHandler is registered twice but treated as a single instance.
       */
  -   public void testPullCallbackPostprocessAcknowledgement()
  +   public void testPullApplicationAckSameHandler()
      {
         log.info("entering " + getName());
         try
         {
            TestCallbackHandler callbackHandler = new TestCallbackHandler();
            client.addListener(callbackHandler);
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  -         client.invoke(POSTPROCESS_TEST);
  +         client.addListener(callbackHandler);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
            List callbacks = client.getCallbacks(callbackHandler);
            assertEquals(2, callbacks.size());
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
            assertEquals(2, client.acknowledgeCallbacks(callbackHandler, callbacks));
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertTrue(TestInvoocationHandler.acknowledgedPostprocess);
  +         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
  +         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
            Thread.sleep(1000);
  -         assertEquals(0, TestCallbackHandler.callbacksReceived);
  +         assertEquals(0, callbackHandler.callbacksReceived);
            client.removeListener(callbackHandler);
            log.info(getName() + " PASSES");
         }
  @@ -171,31 +179,75 @@
      
      
      /**
  -    * In this test, the connection is configured for true pull callbacks, and the 
  -    * acknowledgements should be made implicitly by ServerInvokerCallbackHandler
  -    * during the call to getCallbacks() (before the callbacks are retrieved by
  -    * the client) and later by an explicit call to Client.acknowledgeCallback()
  -    * after the callback has been retrieved and (presumably) processed.
  +    * In this test, the connection is configured for pull callbacks.  The
  +    * server requests that Remoting handle push callback acknowledgements,
  +    * but that should have no effect.  Instead, callback acknowledgements
  +    * should be made by an explicit call to Client.acknowledgeCallback() after
  +    * the callback has been retrieved and (presumably) processed.
  +    * Two distinct InvokerCallbackHandlers are used.
       */
  -   public void testPullCallbackPreAndPostprocessAcknowledgement()
  +   public void testPullRemotingAckDifferentHandlers()
  +   {
  +      log.info("entering " + getName());
  +      try
  +      {
  +         TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
  +         client.addListener(callbackHandler1);
  +         TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
  +         client.addListener(callbackHandler2);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
  +         List callbacks1 = client.getCallbacks(callbackHandler1);
  +         assertEquals(2, callbacks1.size());
  +         List callbacks2 = client.getCallbacks(callbackHandler2);
  +         assertEquals(2, callbacks2.size());
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         assertEquals(2, client.acknowledgeCallbacks(callbackHandler1, callbacks1));
  +         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
  +         assertEquals(2, client.acknowledgeCallbacks(callbackHandler2, callbacks2));
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
  +         Thread.sleep(1000);
  +         assertEquals(0, callbackHandler1.callbacksReceived);
  +         client.removeListener(callbackHandler1);
  +         client.removeListener(callbackHandler2);
  +         log.info(getName() + " PASSES");
  +      }
  +      catch (Throwable e)
  +      {
  +         log.info(getName() + " FAILS");
  +         e.printStackTrace();
  +         fail();
  +      }
  +   }
  +   
  +   
  +   /**
  +    * In this test, the connection is configured pull callbacks.  The
  +    * server requests that Remoting handle push callback acknowledgements,
  +    * but that should have no effect. Instead, acknowledgements should be made
  +    * by an explicit call to Client.acknowledgeCallback() after the callback
  +    * has been retrieved and (presumably) processed. A single InvokerCallbackHandler
  +    * is registered twice but treated as a single instance.
  +    */
  +   public void testPullRemotingAckSameHandler()
      {
         log.info("entering " + getName());
         try
         {
            TestCallbackHandler callbackHandler = new TestCallbackHandler();
            client.addListener(callbackHandler);
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  -         client.invoke(PRE_AND_POSTPROCESS_TEST);
  +         client.addListener(callbackHandler);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
            List callbacks = client.getCallbacks(callbackHandler);
            assertEquals(2, callbacks.size());
  -         assertTrue(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
            assertEquals(2, client.acknowledgeCallbacks(callbackHandler, callbacks));
  -         assertTrue(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertTrue(TestInvoocationHandler.acknowledgedPostprocess);
  +         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
  +         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
            Thread.sleep(1000);
  -         assertEquals(0, TestCallbackHandler.callbacksReceived);
  +         assertEquals(0, callbackHandler.callbacksReceived);
            client.removeListener(callbackHandler);
            log.info(getName() + " PASSES");
         }
  @@ -211,26 +263,76 @@
      /**
       * In this test the connection is configured for push callbacks implemented in
       * Remoting by polling the server for callbacks and pushing them (on the client 
  -    * side) to the InvokerCallbackHandler.  The acknowledgement should be made
  -    * implicitly by ServerInvokerCallbackHandler during the call to getCallbacks()
  -    * (before the callbacks are retrieved by the client).
  +    * side) to the InvokerCallbackHandler.  The acknowledgements should be made
  +    * explicitly by the InvokerCallbackHandler.  Two distinct InvokerCallbackHandlers
  +    * are registered.
       */
  -   public void testPollCallbackPreprocessAcknowledgement()
  +   public void testPollApplicationAckDifferentHandlers()
      {
         log.info("entering " + getName());
         try
         {
  -         TestCallbackHandler callbackHandler = new TestCallbackHandler();
  +         TestCallbackHandler callbackHandler1 = new TestCallbackHandler(client, 1);
            HashMap metadata = new HashMap();
            metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "100");
  +         client.addListener(callbackHandler1, metadata);
  +         TestCallbackHandler callbackHandler2 = new TestCallbackHandler(client, 2);
  +         client.addListener(callbackHandler2, metadata);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
  +         Thread.sleep(1000);
  +         assertEquals(2, callbackHandler1.callbacksReceived);
  +         assertEquals(2, callbackHandler2.callbacksReceived);
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         //key: message #: handler id: callbacks received
  +         String response111 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 1: 1";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response111));
  +         String response212 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 1: 2";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response212));
  +         String response121 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 2: 1";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response121));
  +         String response222 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 2: 2";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response222));
  +         client.removeListener(callbackHandler1);
  +         client.removeListener(callbackHandler2);
  +         log.info(getName() + " PASSES");
  +      }
  +      catch (Throwable e)
  +      {
  +         log.info(getName() + " FAILS");
  +         e.printStackTrace();
  +         fail();
  +      }
  +   }
  +   
  +   
  +   /**
  +    * In this test the connection is configured for push callbacks implemented in
  +    * Remoting by polling the server for callbacks and pushing them (on the client 
  +    * side) to the InvokerCallbackHandler.  A single InvokerCallbackHandler is
  +    * registered twice but the Client treats it as a single instance.  The
  +    * acknowledgements should be made explicitly by the InvokerCallbackHandler.
  +    */
  +   public void testPollApplicationAckSameHandler()
  +   {
  +      log.info("entering " + getName());
  +      try
  +      {
  +         TestCallbackHandler callbackHandler = new TestCallbackHandler(client);
  +         HashMap metadata = new HashMap();
  +         metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "100");
  +         client.addListener(callbackHandler, metadata);
            client.addListener(callbackHandler, metadata);
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  -         client.invoke(PREPROCESS_TEST);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
            Thread.sleep(1000);
  -         assertTrue(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  -         assertEquals(2, TestCallbackHandler.callbacksReceived);
  +         assertEquals(2, callbackHandler.callbacksReceived);
  +         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
  +         //key: message #: handler id: callbacks received
  +         String response101 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 0: 1";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response101));
  +         String response202 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 0: 2";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response202));
            client.removeListener(callbackHandler);
            log.info(getName() + " PASSES");
         }
  @@ -248,25 +350,29 @@
       * Remoting by polling the server for callbacks and pushing them (on the client 
       * side) to the InvokerCallbackHandler.  The acknowledgement should be made
       * implicitly by CallbackPoller, which it does by calling Client.acknowledgeCallback()
  -    * after it has pushed the callback to the InvokerCallbackHandler.
  +    * after it has pushed the callback to the InvokerCallbackHandler.  Two
  +    * distinct InvokerCallbackHandlers are registered.
       */
  -   public void testPollCallbackPostprocessAcknowledgement()
  +   public void testPollRemotingAckDifferentHandlers()
      {
         log.info("entering " + getName());
         try
         {
  -         TestCallbackHandler callbackHandler = new TestCallbackHandler();
  +         TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
            HashMap metadata = new HashMap();
            metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "100");
  -         client.addListener(callbackHandler, metadata);
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  -         client.invoke(POSTPROCESS_TEST);
  +         client.addListener(callbackHandler1, metadata);
  +         TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
  +         client.addListener(callbackHandler2, metadata);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
            Thread.sleep(1000);
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertTrue(TestInvoocationHandler.acknowledgedPostprocess); 
  -         assertEquals(2, TestCallbackHandler.callbacksReceived);
  -         client.removeListener(callbackHandler);
  +         assertEquals(2, callbackHandler1.callbacksReceived);
  +         assertEquals(2, callbackHandler2.callbacksReceived);
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
  +         client.removeListener(callbackHandler1);
  +         client.removeListener(callbackHandler2);
            log.info(getName() + " PASSES");
         }
         catch (Throwable e)
  @@ -281,13 +387,13 @@
      /**
       * In this test the connection is configured for push callbacks implemented in
       * Remoting by polling the server for callbacks and pushing them (on the client 
  -    * side) to the InvokerCallbackHandler.  The acknowledgements should be made
  -    * implicitly by ServerInvokerCallbackHandler during the call to getCallbacks()
  -    * (before the callbacks are retrieved by the client), and then
  +    * side) to the InvokerCallbackHandler.  The acknowledgement should be made
       * implicitly by CallbackPoller, which it does by calling Client.acknowledgeCallback()
  -    * after it has pushed the callback to the InvokerCallbackHandler.
  +    * after it has pushed the callback to the InvokerCallbackHandler.  A single
  +    * InvokerCallbackHandler is registered twice, but the Client recognizes only a
  +    * single instance.
       */
  -   public void testPollCallbackPreAndPostprocessAcknowledgement()
  +   public void testPollRemotingAckSameHandler()
      {
         log.info("entering " + getName());
         try
  @@ -296,13 +402,13 @@
            HashMap metadata = new HashMap();
            metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "100");
            client.addListener(callbackHandler, metadata);
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  -         client.invoke(PRE_AND_POSTPROCESS_TEST);
  +         client.addListener(callbackHandler, metadata);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
            Thread.sleep(1000);
  -         assertTrue(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertTrue(TestInvoocationHandler.acknowledgedPostprocess); 
  -         assertEquals(2, TestCallbackHandler.callbacksReceived);
  +         assertEquals(2, callbackHandler.callbacksReceived);
  +         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
  +         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
            client.removeListener(callbackHandler);
            log.info(getName() + " PASSES");
         }
  @@ -317,23 +423,34 @@
      
      /**
       * In this test the connection is configured for true push callbacks, and the
  -    * acknowledgement should be made by ServerInvokerCallbackHandler.handleCallback()
  -    * after it has pushed the Callback to the client.
  +    * acknowledgements should be made on the client side by the InvokerCallbackHandler.
  +    * Two distinct InvokerCallbackHandlers are registered.
       */
  -   public void testPushCallbackPreprocessAcknowledgement()
  +   public void testPushApplicationAckDifferentHandlers()
      {
         log.info("entering " + getName());
         try
         {
  -         TestCallbackHandler callbackHandler = new TestCallbackHandler();
  -         client.addListener(callbackHandler, null, null, true);
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  -         client.invoke(PREPROCESS_TEST);
  -         assertTrue(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  -         assertEquals(2, TestCallbackHandler.callbacksReceived);
  -         client.removeListener(callbackHandler);
  +         TestCallbackHandler callbackHandler1 = new TestCallbackHandler(client, 1);
  +         client.addListener(callbackHandler1, null, null, true);
  +         TestCallbackHandler callbackHandler2 = new TestCallbackHandler(client, 2);
  +         client.addListener(callbackHandler2, null, null, true);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
  +         assertEquals(2, callbackHandler1.callbacksReceived);
  +         assertEquals(2, callbackHandler2.callbacksReceived);
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         //key: message #: handler id: callbacks received
  +         String response111 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 1: 1";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response111));
  +         String response212 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 1: 2";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response212));
  +         String response121 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 2: 1";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response121));
  +         String response222 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 2: 2";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response222));
  +         client.removeListener(callbackHandler1);
  +         client.removeListener(callbackHandler2);
            log.info(getName() + " PASSES");
         }
         catch (Throwable e)
  @@ -347,22 +464,30 @@
      
      /**
       * In this test the connection is configured for true push callbacks, and the
  -    * acknowledgement should be made by ServerInvokerCallbackHandler.handleCallback()
  -    * after it has pushed the Callback to the client.
  +    * acknowledgement should be made on the client side by the InvokerCallbackHandler.
  +    * A single InvokerCallbackHandler is shared by two callback Connectors.
       */
  -   public void testPushCallbackPostprocessAcknowledgement()
  +   public void testPushApplicationAckSameHandler()
      {
         log.info("entering " + getName());
         try
         {
  -         TestCallbackHandler callbackHandler = new TestCallbackHandler();
  +         TestCallbackHandler callbackHandler = new TestCallbackHandler(client);
  +         client.addListener(callbackHandler, null, null, true);
            client.addListener(callbackHandler, null, null, true);
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  -         client.invoke(POSTPROCESS_TEST);
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertTrue(TestInvoocationHandler.acknowledgedPostprocess);
  -         assertEquals(2, TestCallbackHandler.callbacksReceived);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
  +         assertEquals(4, callbackHandler.callbacksReceived);
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         //key: message #: handler id: callbacks received
  +         String response101 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 0: 1";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response101));
  +         String response202 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 0: 2";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response202));
  +         String response103 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 0: 3";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response103));
  +         String response204 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 0: 4";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response204));
            client.removeListener(callbackHandler);
            log.info(getName() + " PASSES");
         }
  @@ -375,25 +500,59 @@
      }
      
      
  +   /**
  +    * In this test the connection is configured for true push callbacks, and the
  +    * acknowledgements should be made by ServerInvokerCallbackHandler.handleCallback()
  +    * after it has pushed the Callback to the client.  Two distinct
  +    * InvokerCallbackHandlers are registered.
  +    */
  +   public void testPushRemotingAckDifferentHandlers()
  +   {
  +      log.info("entering " + getName());
  +      try
  +      {
  +         TestCallbackHandler callbackHandler1 = new TestCallbackHandler();
  +         client.addListener(callbackHandler1, null, null, true);
  +         TestCallbackHandler callbackHandler2 = new TestCallbackHandler();
  +         client.addListener(callbackHandler2, null, null, true);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
  +         assertEquals(2, callbackHandler1.callbacksReceived);
  +         assertEquals(2, callbackHandler2.callbacksReceived);
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
  +         client.removeListener(callbackHandler1);
  +         client.removeListener(callbackHandler2);
  +         log.info(getName() + " PASSES");
  +      }
  +      catch (Throwable e)
  +      {
  +         log.info(getName() + " FAILS");
  +         e.printStackTrace();
  +         fail();
  +      }
  +   }
  +   
      
      /**
       * In this test the connection is configured for true push callbacks, and the
       * acknowledgements should be made by ServerInvokerCallbackHandler.handleCallback()
  -    * after it has pushed the Callback to the client.
  +    * after it has pushed the Callback to the client.  A single InvokerCallbackHandler
  +    * is registered twice, and each is treated as a distinct instance.
       */
  -   public void testPushCallbackPreAndPostprocessAcknowledgement()
  +   public void testPushRemotingAckSameHandler()
      {
         log.info("entering " + getName());
         try
         {
            TestCallbackHandler callbackHandler = new TestCallbackHandler();
            client.addListener(callbackHandler, null, null, true);
  -         assertFalse(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertFalse(TestInvoocationHandler.acknowledgedPostprocess);
  -         client.invoke(PRE_AND_POSTPROCESS_TEST);
  -         assertTrue(TestInvoocationHandler.acknowledgedPreprocess);
  -         assertTrue(TestInvoocationHandler.acknowledgedPostprocess);
  -         assertEquals(2, TestCallbackHandler.callbacksReceived);
  +         client.addListener(callbackHandler, null, null, true);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
  +         assertEquals(4, callbackHandler.callbacksReceived);
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
            client.removeListener(callbackHandler);
            log.info(getName() + " PASSES");
         }
  @@ -406,101 +565,477 @@
      }
      
      
  -   static class TestInvoocationHandler implements ServerInvocationHandler, CallbackListener
  +   /**
  +    * In this test the connection is configured for true push callbacks by creating a
  +    * Connector and passing its InvokerLocator when the InvokerCallbackHandlers are
  +    * registered.  Acknowledgements should be made on the client side by the
  +    * InvokerCallbackHandler. Two distinct InvokerCallbackHandlers are registered with
  +    * a single Connector.
  +    */
  +   public void testPushApplicationAckDifferentHandlersPassLocator()
  +   {
  +      log.info("entering " + getName());
  +      try
  +      {
  +         String host = InetAddress.getLocalHost().getHostAddress();
  +         int freePort = PortUtil.findFreePort(host);
  +         InvokerLocator callbackLocator = new InvokerLocator(transport + "://" + host + ":" + freePort);
  +         HashMap config = new HashMap();
  +         config.put(InvokerLocator.FORCE_REMOTE, "true");
  +         Connector connector = new Connector(callbackLocator, config);
  +         connector.start();
  +         TestCallbackHandler callbackHandler1 = new TestCallbackHandler(client, 1);
  +         client.addListener(callbackHandler1, callbackLocator);
  +         TestCallbackHandler callbackHandler2 = new TestCallbackHandler(client, 2);
  +         client.addListener(callbackHandler2, callbackLocator);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
  +         assertEquals(2, callbackHandler1.callbacksReceived);
  +         assertEquals(2, callbackHandler2.callbacksReceived);
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         //key: message #: handler id: callbacks received
  +         String response111 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 1: 1";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response111));
  +         String response212 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 1: 2";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response212));
  +         String response121 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 2: 1";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response121));
  +         String response222 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 2: 2";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response222));
  +         client.removeListener(callbackHandler1);
  +         client.removeListener(callbackHandler2);
  +         log.info(getName() + " PASSES");
  +      }
  +      catch (Throwable e)
      {
  -      static boolean acknowledgedPreprocess;
  -      static boolean acknowledgedPostprocess;
  +         log.info(getName() + " FAILS");
  +         e.printStackTrace();
  +         fail();
  +      }
  +   }
         
  -      InvokerCallbackHandler callbackHandler;
         
  -      public void setMBeanServer(MBeanServer server)
  +   /**
  +    * In this test the connection is configured for true push callbacks by creating a
  +    * Connector and passing its InvokerLocator when the InvokerCallbackHandlers are
  +    * registered.  Acknowledgements should be made on the client side by the
  +    * InvokerCallbackHandler. A InvokerCallbackHandler is registered twice with
  +    * a single Connector and treated as a single instance.
  +    */
  +   public void testPushApplicationAckSameHandlerPassLocator()
  +   {
  +      log.info("entering " + getName());
  +      try
         {
  +         String host = InetAddress.getLocalHost().getHostAddress();
  +         int freePort = PortUtil.findFreePort(host);
  +         InvokerLocator callbackLocator = new InvokerLocator(transport + "://" + host + ":" + freePort);
  +         HashMap config = new HashMap();
  +         config.put(InvokerLocator.FORCE_REMOTE, "true");
  +         Connector connector = new Connector(callbackLocator, config);
  +         connector.start();
  +         TestCallbackHandler callbackHandler = new TestCallbackHandler(client);
  +         client.addListener(callbackHandler, callbackLocator);
  +         client.addListener(callbackHandler, callbackLocator);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
  +         assertEquals(2, callbackHandler.callbacksReceived);
  +         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
  +         //key: message #: handler id: callbacks received
  +         String response101 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 0: 1";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response101));
  +         String response202 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 0: 2";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response202));
  +         client.removeListener(callbackHandler);
  +         log.info(getName() + " PASSES");
  +      }
  +      catch (Throwable e)
  +      {
  +         log.info(getName() + " FAILS");
  +         e.printStackTrace();
  +         fail();
  +      }
         }
   
  -      public void setInvoker(ServerInvoker invoker)
  +   
  +   /**
  +    * In this test the connection is configured for true push callbacks by creating 
  +    * two Connectors and passing their InvokerLocator when the InvokerCallbackHandlers
  +    * are registered.  Acknowledgements should be made on the client side by the
  +    * InvokerCallbackHandler. Each of two distinct InvokerCallbackHandlers is
  +    * registered with a distinct Connector
  +    */
  +   public void testPushApplicationAckDifferentHandlersPassTwoLocators()
  +   {
  +      log.info("entering " + getName());
  +      try
  +      {
  +         String host = InetAddress.getLocalHost().getHostAddress();
  +         int freePort = PortUtil.findFreePort(host);
  +         InvokerLocator callbackLocator1 = new InvokerLocator(transport + "://" + host + ":" + freePort);
  +         HashMap config = new HashMap();
  +         config.put(InvokerLocator.FORCE_REMOTE, "true");
  +         Connector connector1 = new Connector(callbackLocator1, config);
  +         connector1.start();
  +         TestCallbackHandler callbackHandler1 = new TestCallbackHandler(client, 1);
  +         client.addListener(callbackHandler1, callbackLocator1);
  +         freePort = PortUtil.findFreePort(host);
  +         InvokerLocator callbackLocator2 = new InvokerLocator(transport + "://" + host + ":" + freePort);
  +         Connector connector2 = new Connector(callbackLocator2, config);
  +         connector2.start();
  +         TestCallbackHandler callbackHandler2 = new TestCallbackHandler(client, 2);
  +         client.addListener(callbackHandler2, callbackLocator2);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
  +         assertEquals(2, callbackHandler1.callbacksReceived);
  +         assertEquals(2, callbackHandler2.callbacksReceived);
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         //key: message #: handler id: callbacks received
  +         String response111 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 1: 1";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response111));
  +         String response212 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 1: 2";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response212));
  +         String response121 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 2: 1";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response121));
  +         String response222 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 2: 2";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response222));
  +         client.removeListener(callbackHandler1);
  +         client.removeListener(callbackHandler2);
  +         log.info(getName() + " PASSES");
  +      }
  +      catch (Throwable e)
         {  
  +         log.info(getName() + " FAILS");
  +         e.printStackTrace();
  +         fail();
  +      }
         }
   
  -      public Object invoke(InvocationRequest invocation) throws Throwable
  +
  +   /**
  +    * In this test the connection is configured for true push callbacks by creating 
  +    * two Connectors and passing their InvokerLocator when the InvokerCallbackHandlers
  +    * are registered.  Acknowledgements should be made on the client side by the
  +    * InvokerCallbackHandler. A single InvokerCallbackHandlers is registered with
  +    * two distinct Connectors.
  +    */
  +   public void testPushApplicationAckSameHandlerPassTwoLocators()
         {
  +      log.info("entering " + getName());
  +      try
  +      {
  +         String host = InetAddress.getLocalHost().getHostAddress();
  +         int freePort = PortUtil.findFreePort(host);
  +         InvokerLocator callbackLocator1 = new InvokerLocator(transport + "://" + host + ":" + freePort);
  +         HashMap config = new HashMap();
  +         config.put(InvokerLocator.FORCE_REMOTE, "true");
  +         Connector connector1 = new Connector(callbackLocator1, config);
  +         connector1.start();
  +         TestCallbackHandler callbackHandler = new TestCallbackHandler(client);
  +         client.addListener(callbackHandler, callbackLocator1);
  +         freePort = PortUtil.findFreePort(host);
  +         InvokerLocator callbackLocator2 = new InvokerLocator(transport + "://" + host + ":" + freePort);
  +         Connector connector2 = new Connector(callbackLocator2, config);
  +         connector2.start();
  +         client.addListener(callbackHandler, callbackLocator2);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(APPLICATION_ACKNOWLEDGEMENT_TEST);
  +         assertEquals(4, callbackHandler.callbacksReceived);
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         //key: message #: handler id: callbacks received
  +         String response101 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 0: 1";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response101));
  +         String response202 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 0: 2";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response202));
  +         String response103 = APPLICATION_ACKNOWLEDGEMENT_TEST + "1: 0: 3";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response103));
  +         String response204 = APPLICATION_ACKNOWLEDGEMENT_TEST + "2: 0: 4";
  +         assertTrue(TestInvocationHandler.callbackResponses.contains(response204));
  +         client.removeListener(callbackHandler);
  +         log.info(getName() + " PASSES");
  +      }
  +      catch (Throwable e)
  +      {
  +         log.info(getName() + " FAILS");
  +         e.printStackTrace();
  +         fail();
  +      }
  +   }
   
  -         String command = (String) invocation.getParameter();
  -         System.out.println("command: " + command);
  -         if (PREPROCESS_TEST.equals(command))
  +   
  +   /**
  +    * In this test the connection is configured for true push callbacks by creating a
  +    * Connector and passing its InvokerLocator when the InvokerCallbackHandlers are
  +    * registered.  Acknowledgements should be made implicitly on the server side by the
  +    * ServerInvokerCallbackHandler. Two distinct InvokerCallbackHandlers are registered
  +    * with a single Connector.
  +    */
  +   public void testPushRemotingAckDifferentHandlersPassLocator()
            {
  -            Callback cb1 = new Callback(PREPROCESS_TEST + "1");
  -            Callback cb2 = new Callback(PREPROCESS_TEST + "2");
  -            HashMap returnPayload = new HashMap();
  -            returnPayload.put(ServerInvokerCallbackHandler.CALLBACK_PREPROCESS_LISTENER, this);
  -            returnPayload.put(ServerInvokerCallbackHandler.CALLBACK_ID, "preprocess");
  -            cb1.setReturnPayload(returnPayload);
  -            cb2.setReturnPayload(returnPayload);
  -            callbackHandler.handleCallback(cb1);
  -            callbackHandler.handleCallback(cb2);
  +      log.info("entering " + getName());
  +      try
  +      {
  +         String host = InetAddress.getLocalHost().getHostAddress();
  +         int freePort = PortUtil.findFreePort(host);
  +         InvokerLocator callbackLocator = new InvokerLocator(transport + "://" + host + ":" + freePort);
  +         HashMap config = new HashMap();
  +         config.put(InvokerLocator.FORCE_REMOTE, "true");
  +         Connector connector = new Connector(callbackLocator, config);
  +         connector.start();
  +         TestCallbackHandler callbackHandler1 = new TestCallbackHandler(client, 1);
  +         client.addListener(callbackHandler1, callbackLocator);
  +         TestCallbackHandler callbackHandler2 = new TestCallbackHandler(client, 2);
  +         client.addListener(callbackHandler2, callbackLocator);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
  +         assertEquals(2, callbackHandler1.callbacksReceived);
  +         assertEquals(2, callbackHandler2.callbacksReceived);
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
  +         client.removeListener(callbackHandler1);
  +         client.removeListener(callbackHandler2);
  +         log.info(getName() + " PASSES");
            }
  -         else if (POSTPROCESS_TEST.equals(command))
  +      catch (Throwable e)
            {
  -            Callback cb1 = new Callback(POSTPROCESS_TEST + "1");
  -            Callback cb2 = new Callback(POSTPROCESS_TEST + "2");
  -            HashMap returnPayload = new HashMap();
  -            returnPayload.put(ServerInvokerCallbackHandler.CALLBACK_POSTPROCESS_LISTENER, this);
  -            returnPayload.put(ServerInvokerCallbackHandler.CALLBACK_ID, "postprocess");
  -            cb1.setReturnPayload(returnPayload);
  -            cb2.setReturnPayload(returnPayload);
  -            callbackHandler.handleCallback(cb1);
  -            callbackHandler.handleCallback(cb2);
  +         log.info(getName() + " FAILS");
  +         e.printStackTrace();
  +         fail();
            }
  -         else if (PRE_AND_POSTPROCESS_TEST.equals(command))
  +   }
  +   
  +   
  +   /**
  +    * In this test the connection is configured for true push callbacks by creating a
  +    * Connector and passing its InvokerLocator when the InvokerCallbackHandlers are
  +    * registered.  Acknowledgements should be made implicitly on the server side by the
  +    * ServerInvokerCallbackHandler. A InvokerCallbackHandler is registered twice with
  +    * a single Connector and treated as a single instance.
  +    */
  +   public void testPushRemotingAckSameHandlerPassLocator()
            {
  -            Callback cb1 = new Callback(PRE_AND_POSTPROCESS_TEST + "1");
  -            Callback cb2 = new Callback(PRE_AND_POSTPROCESS_TEST + "2");
  -            HashMap returnPayload = new HashMap();
  -            returnPayload.put(ServerInvokerCallbackHandler.CALLBACK_PREPROCESS_LISTENER, this);
  -            returnPayload.put(ServerInvokerCallbackHandler.CALLBACK_POSTPROCESS_LISTENER, this);
  -            returnPayload.put(ServerInvokerCallbackHandler.CALLBACK_ID, "postprocess");
  -            cb1.setReturnPayload(returnPayload);
  -            cb2.setReturnPayload(returnPayload);
  -            callbackHandler.handleCallback(cb1);
  -            callbackHandler.handleCallback(cb2);
  +      log.info("entering " + getName());
  +      try
  +      {
  +         String host = InetAddress.getLocalHost().getHostAddress();
  +         int freePort = PortUtil.findFreePort(host);
  +         InvokerLocator callbackLocator = new InvokerLocator(transport + "://" + host + ":" + freePort);
  +         HashMap config = new HashMap();
  +         config.put(InvokerLocator.FORCE_REMOTE, "true");
  +         Connector connector = new Connector(callbackLocator, config);
  +         connector.start();
  +         TestCallbackHandler callbackHandler = new TestCallbackHandler(client);
  +         client.addListener(callbackHandler, callbackLocator);
  +         client.addListener(callbackHandler, callbackLocator);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
  +         assertEquals(2, callbackHandler.callbacksReceived);
  +         assertEquals(2, TestInvocationHandler.callbacksAcknowledged);
  +         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
  +         client.removeListener(callbackHandler);
  +         log.info(getName() + " PASSES");
  +      }
  +      catch (Throwable e)
  +      {
  +         log.info(getName() + " FAILS");
  +         e.printStackTrace();
  +         fail();
  +      }
            }
            
  -         return null;
  +   
  +   /**
  +    * In this test the connection is configured for true push callbacks by creating 
  +    * two Connectors and passing their InvokerLocator when the InvokerCallbackHandlers
  +    * are registered.  Acknowledgements should be made implicitly on the server side by the
  +    * ServerInvokerCallbackHandler. Each of two distinct InvokerCallbackHandlers is
  +    * registered with a distinct Connector
  +    */
  +   public void testPushRemotingAckDifferentHandlersPassTwoLocators()
  +   {
  +      log.info("entering " + getName());
  +      try
  +      {
  +         String host = InetAddress.getLocalHost().getHostAddress();
  +         int freePort = PortUtil.findFreePort(host);
  +         InvokerLocator callbackLocator1 = new InvokerLocator(transport + "://" + host + ":" + freePort);
  +         HashMap config = new HashMap();
  +         config.put(InvokerLocator.FORCE_REMOTE, "true");
  +         Connector connector1 = new Connector(callbackLocator1, config);
  +         connector1.start();
  +         TestCallbackHandler callbackHandler1 = new TestCallbackHandler(client, 1);
  +         client.addListener(callbackHandler1, callbackLocator1);
  +         freePort = PortUtil.findFreePort(host);
  +         InvokerLocator callbackLocator2 = new InvokerLocator(transport + "://" + host + ":" + freePort);
  +         Connector connector2 = new Connector(callbackLocator2, config);
  +         connector2.start();
  +         TestCallbackHandler callbackHandler2 = new TestCallbackHandler(client, 2);
  +         client.addListener(callbackHandler2, callbackLocator2);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
  +         assertEquals(2, callbackHandler1.callbacksReceived);
  +         assertEquals(2, callbackHandler2.callbacksReceived);
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
  +         client.removeListener(callbackHandler1);
  +         client.removeListener(callbackHandler2);
  +         log.info(getName() + " PASSES");
  +      }
  +      catch (Throwable e)
  +      {
  +         log.info(getName() + " FAILS");
  +         e.printStackTrace();
  +         fail();
  +      }
         }
   
  -      public void addListener(InvokerCallbackHandler callbackHandler)
  +   
  +   /**
  +    * In this test the connection is configured for true push callbacks by creating 
  +    * two Connectors and passing their InvokerLocator when the InvokerCallbackHandlers
  +    * are registered.  Acknowledgements should be made implicitly on the server side by the
  +    * ServerInvokerCallbackHandler. A single InvokerCallbackHandlers is registered with
  +    * two distinct Connectors.
  +    */
  +   public void testPushRemotingAckSameHandlerPassTwoLocators()
  +   {
  +      log.info("entering " + getName());
  +      try
         {
  -         this.callbackHandler = callbackHandler;
  +         String host = InetAddress.getLocalHost().getHostAddress();
  +         int freePort = PortUtil.findFreePort(host);
  +         InvokerLocator callbackLocator1 = new InvokerLocator(transport + "://" + host + ":" + freePort);
  +         HashMap config = new HashMap();
  +         config.put(InvokerLocator.FORCE_REMOTE, "true");
  +         Connector connector1 = new Connector(callbackLocator1, config);
  +         connector1.start();
  +         TestCallbackHandler callbackHandler = new TestCallbackHandler(client);
  +         client.addListener(callbackHandler, callbackLocator1);
  +         freePort = PortUtil.findFreePort(host);
  +         InvokerLocator callbackLocator2 = new InvokerLocator(transport + "://" + host + ":" + freePort);
  +         Connector connector2 = new Connector(callbackLocator2, config);
  +         connector2.start();
  +         client.addListener(callbackHandler, callbackLocator2);
  +         assertEquals(0, TestInvocationHandler.callbacksAcknowledged);
  +         client.invoke(REMOTING_ACKNOWLEDGEMENT_TEST);
  +         assertEquals(4, callbackHandler.callbacksReceived);
  +         assertEquals(4, TestInvocationHandler.callbacksAcknowledged);
  +         assertTrue(TestInvocationHandler.callbackResponses.isEmpty());
  +         client.removeListener(callbackHandler);
  +         log.info(getName() + " PASSES");
  +      }
  +      catch (Throwable e)
  +      {
  +         log.info(getName() + " FAILS");
  +         e.printStackTrace();
  +         fail();
  +      }
         }
   
  -      public void removeListener(InvokerCallbackHandler callbackHandler)
  +   
  +   static class TestInvocationHandler implements ServerInvocationHandler, CallbackListener
  +   {
  +      static int callbacksAcknowledged;
  +      static HashSet callbackResponses = new HashSet();
  +      
  +      HashSet callbackHandlers = new HashSet();
  +      
  +      public void setMBeanServer(MBeanServer server) {}
  +      public void setInvoker(ServerInvoker invoker) {}
  +
  +      public Object invoke(InvocationRequest invocation) throws Throwable
         {
  +         String command = (String) invocation.getParameter();
  +         System.out.println("command: " + command);
  +
  +         for (Iterator it = callbackHandlers.iterator(); it.hasNext(); )
  +         {
  +            InvokerCallbackHandler callbackHandler = (InvokerCallbackHandler) it.next();
  +            Callback cb1 = new Callback(command + "1");
  +            HashMap returnPayload1 = new HashMap();
  +            returnPayload1.put(ServerInvokerCallbackHandler.CALLBACK_ID, command + "1");
  +            returnPayload1.put(ServerInvokerCallbackHandler.CALLBACK_LISTENER, this);
  +            cb1.setReturnPayload(returnPayload1);           
  +            if (REMOTING_ACKNOWLEDGEMENT_TEST.equals(command))
  +            {
  +               returnPayload1.put(ServerInvokerCallbackHandler.REMOTING_ACKNOWLEDGES_PUSH_CALLBACKS, "true");
         }
  +            callbackHandler.handleCallback(cb1);
   
  -      public void callbackSent(Object callbackId, int preOrPost)
  +            Callback cb2 = new Callback(command + "2");
  +            HashMap returnPayload2 = new HashMap();
  +            returnPayload2.put(ServerInvokerCallbackHandler.CALLBACK_ID, command + "2");
  +            returnPayload2.put(ServerInvokerCallbackHandler.CALLBACK_LISTENER, this);
  +            cb2.setReturnPayload(returnPayload2);   
  +            if (REMOTING_ACKNOWLEDGEMENT_TEST.equals(command))
         {
  -         if (ServerInvokerCallbackHandler.CALLBACK_ACK_PREPROCESS == preOrPost)
  +               returnPayload2.put(ServerInvokerCallbackHandler.REMOTING_ACKNOWLEDGES_PUSH_CALLBACKS, "true");
  +            }
  +            callbackHandler.handleCallback(cb2);
  +         }
  +         return null;
  +      }
  +
  +      public void addListener(InvokerCallbackHandler callbackHandler)
            {
  -            log.info("received preprocess acknowledgment");
  -            acknowledgedPreprocess = true;
  +         callbackHandlers.add(callbackHandler);
            }
  -         else  if (ServerInvokerCallbackHandler.CALLBACK_ACK_POSTPROCESS == preOrPost)
  +
  +      public void removeListener(InvokerCallbackHandler callbackHandler)
            {
  -            log.info("received postprocess acknowledgment");
  -            acknowledgedPostprocess = true;
            }
  -         else
  -            log.error("unrecognized callback");
  +
  +      public void acknowledgeCallback(InvokerCallbackHandler callbackHandler,
  +                                      Object callbackId, Object response)
  +      {
  +         callbacksAcknowledged++;
  +         if (response != null)
  +            callbackResponses.add(response);
         }
      }
      
      static class TestCallbackHandler implements InvokerCallbackHandler
      {
  -      public static int callbacksReceived;
  +      public int callbacksReceived;
  +      private Client client;
  +      private int id;
  +      
  +      public TestCallbackHandler()
  +      {
  +         this(null);
  +      }
  +      public TestCallbackHandler(Client client)
  +      {
  +         this(client, 0);
  +      }
  +      public TestCallbackHandler(Client client, int id)
  +      {
  +         this.client = client;
  +         this.id = id;
  +      }
         
         public void handleCallback(Callback callback) throws HandleCallbackException
         {
            log.info("entering handleCallback()");
            callbacksReceived++;
  +         
  +         Map returnMap = callback.getReturnPayload();
  +         Object o = returnMap.get(ServerInvokerCallbackHandler.REMOTING_ACKNOWLEDGES_PUSH_CALLBACKS);
  +         if (o instanceof String  && Boolean.parseBoolean((String)o) ||
  +             o instanceof Boolean && (Boolean) o)
  +            return;
  +         
  +         String test = (String) callback.getParameter();
  +         try
  +         {
  +            client.acknowledgeCallback(this, callback, test + ": " + id + ": " + callbacksReceived);
  +         }
  +         catch (Throwable e)
  +         {
  +            log.error(e);
  +            e.printStackTrace();
  +            throw new HandleCallbackException(e.getMessage());
  +         }
         }
      }
   }
  
  
  



More information about the jboss-cvs-commits mailing list