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

Ron Sigal ron_sigal at yahoo.com
Fri Aug 17 21:31:11 EDT 2007


  User: rsigal  
  Date: 07/08/17 21:31:11

  Modified:    src/tests/org/jboss/test/remoting/timeout  Tag:
                        remoting_2_2_2_experimental
                        QuickDisconnectClientParent.java
  Log:
  JBREM-757:  Synchronized with remoting_2_x branch, adding two methods for disconnectTimeout == 0.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3.10.1 +173 -4    JBossRemoting/src/tests/org/jboss/test/remoting/timeout/Attic/QuickDisconnectClientParent.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: QuickDisconnectClientParent.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/timeout/Attic/QuickDisconnectClientParent.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.3.10.1
  diff -u -b -r1.1.2.3 -r1.1.2.3.10.1
  --- QuickDisconnectClientParent.java	22 Feb 2007 21:32:08 -0000	1.1.2.3
  +++ QuickDisconnectClientParent.java	18 Aug 2007 01:31:11 -0000	1.1.2.3.10.1
  @@ -53,7 +53,7 @@
    * removeListener().
    * 
    * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
  - * @version $Revision: 1.1.2.3 $
  + * @version $Revision: 1.1.2.3.10.1 $
    * <p>
    * Copyright Jan 24, 2007
    * </p>
  @@ -97,6 +97,87 @@
      
      /**
       * This test starts a server, connects a client to it, disables the server,
  +    * and sets the client's disconnectTimeout to 0.  The client should be
  +    * able to terminate the lease and disconnect quickly even though it cannot
  +    * complete an invocation on the server.
  +    */
  +   public void testQuickDisconnectZeroTimeout() throws Throwable
  +   {
  +      log.info("entering " + getName());
  +      String host = InetAddress.getLocalHost().getHostAddress();
  +      String locatorURI = getTransport() + "://" + host + ":" + port;
  +      InvokerLocator locator = new InvokerLocator(locatorURI);
  +      
  +      HashMap config = new HashMap();
  +      config.put(InvokerLocator.FORCE_REMOTE, "true");
  +      config.put(ServerInvoker.TIMEOUT, "60000");
  +      config.put(Client.ENABLE_LEASE, "true");
  +      addClientConfig(config);
  +      final Client client = new Client(locator, config);
  +      try
  +      {
  +         client.connect();
  +      }
  +      catch (Exception e)
  +      {
  +         e.printStackTrace();
  +      }
  +      log.info("making first invocation");
  +      Object response = client.invoke("test");
  +      assertEquals("test", response);
  +      log.info("first invocation succeeds");
  +      
  +      
  +      new Thread()
  +      {
  +         public void run()
  +         {
  +            try
  +            {
  +               // Wait for the server to be disabled.
  +               Thread.sleep(10000);
  +               
  +               try
  +               {
  +               // This invocation may use up a listening connection,
  +               // depending on transport.
  +                  HashMap metadata = new HashMap();
  +                  metadata.put("timeout", shortTimeoutString());
  +                  log.info("making invocation");
  +                  client.invoke("test", metadata);
  +                  log.info("made invocation");
  +               }
  +               catch (Exception e)
  +               {
  +                  log.info("client.invoke(\"test\") failed (that's OK)");
  +               }
  +               
  +               
  +               // Set disconnectTimeout to 0.
  +               log.info("calling client.disconnect()");
  +               client.setDisconnectTimeout(0);
  +               client.disconnect();
  +               log.info("returned from client.disconnect()");
  +            }
  +            catch (Throwable e)
  +            {
  +               log.info("error in client.disconnect()", e);
  +            }
  +         }
  +      }.start();
  +      
  +      // It should take the Client a little while for LeasePinger's attempts to contact
  +      // the server to time out.  Wait for about 4 seconds after the call to
  +      // Client.disconnect() and then verify that the Client has successfully
  +      // disconnected even though the server is disabled.
  +      Thread.sleep(16000);
  +      assertFalse(client.isConnected());
  +      log.info(getName() + " PASSES");
  +   }
  +   
  +   
  +   /**
  +    * This test starts a server, connects a client to it, disables the server,
       * and sets the client's disconnectTimeout to 1 second.  The client should be
       * able to terminate the lease and disconnect quickly even though it cannot
       * complete an invocation on the server.
  @@ -262,6 +343,95 @@
      }
      
      
  +   /**
  +    * This test starts a server, connects a client to it, disables the server,
  +    * and sets the client's disconnectTimeout to 0.  The client should be
  +    * able to remove the callback handler quickly even though it cannot
  +    * complete an invocation on the server.
  +    */
  +   public void testQuickRemoveListenerZeroTimeout() throws Throwable
  +   {
  +      log.info("entering " + getName());
  +      String host = InetAddress.getLocalHost().getHostAddress();
  +      String locatorURI = getTransport() + "://" + host + ":" + port;
  +      InvokerLocator locator = new InvokerLocator(locatorURI);
  +      HashMap config = new HashMap();
  +      config.put(InvokerLocator.FORCE_REMOTE, "true");
  +      config.put(ServerInvoker.TIMEOUT, "60000");
  +      config.put(Client.ENABLE_LEASE, "true");
  +      addClientConfig(config);
  +      final Client client = new Client(locator, config);
  +      try
  +      {
  +         client.connect();
  +      }
  +      catch (Exception e)
  +      {
  +         e.printStackTrace();
  +      }
  +      log.info("making first invocation");
  +      Object response = client.invoke("test");
  +      assertEquals("test", response);
  +      log.info("first invocation succeeds");
  +      final InvokerCallbackHandler callbackHandler = new TestCallbackHandler();
  +      client.addListener(callbackHandler, new HashMap(), null, true);
  +      
  +      final Holder removeListener = new Holder();
  +      new Thread()
  +      {
  +         public void run()
  +         {
  +            try
  +            {
  +               // Wait for the server to be disabled.
  +               Thread.sleep(10000);
  +               
  +               try
  +               {
  +               // This invocation may use up a listening connection,
  +               // depending on transport.
  +                  HashMap metadata = new HashMap();
  +                  metadata.put("timeout", shortTimeoutString());
  +                  log.info("making invocation");
  +                  client.invoke("test", metadata);
  +                  log.info("made invocation");
  +               }
  +               catch (Exception e)
  +               {
  +                  log.info("client.invoke(\"test\") failed (that's OK)");
  +               }
  +               
  +               // Set disconnectTimeout to 0.
  +               client.setDisconnectTimeout(0);
  +               client.removeListener(callbackHandler);
  +               removeListener.done = true;
  +               log.info("returned from client.removeListener()");
  +            }
  +            catch (Throwable e)
  +            {
  +               log.info("error in client.removeListener()", e);
  +            }
  +         }
  +      }.start();
  +      
  +      
  +      // Verify that a callback Connector has been created.
  +      Field field = Client.class.getDeclaredField("callbackConnectors");
  +      field.setAccessible(true);
  +      Map callbackConnectors = (Map) field.get(client);
  +      assertEquals(1, callbackConnectors.size());
  +      
  +      // Wait for about 4 seconds after the call to Client.removeListener() and then
  +      // verify that the Client has successfully removed the callback handler even
  +      // though the server is disabled.
  +      Thread.sleep(16000);
  +      assertEquals(0, callbackConnectors.size());
  +      
  +      // Verify that attempt to remove callback handler on server has timed out and
  +      // client was able to complete call to removeListener().
  +      assertTrue(removeListener.done);
  +      log.info(getName() + " PASSES");
  +   }
   
      
      /**
  @@ -324,6 +494,7 @@
                  
                  // Set disconnectTimeout to 1 second.
                  client.setDisconnectTimeout(shortTimeout());
  +               log.info("calling client.removeListener()");
                  client.removeListener(callbackHandler);
                  removeListener.done = true;
                  log.info("returned from client.removeListener()");
  @@ -355,8 +526,6 @@
      }
      
      
  -
  -   
      /**
       * This test is identical to testQuickRemoveListener() except that the
       * disconnectTimeout value is not set on the client.  Therefore, the client
  
  
  



More information about the jboss-cvs-commits mailing list