[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/oneway ...

Ron Sigal ron_sigal at yahoo.com
Fri Jul 6 02:24:31 EDT 2007


  User: rsigal  
  Date: 07/07/06 02:24:31

  Modified:    src/tests/org/jboss/test/remoting/transport/socket/oneway 
                        Tag: remoting_2_x
                        OnewayConnectionManagerTestCase.java
  Log:
  JBREM-706:  Made changes to confrom to new oneway connection handling mechanism.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +109 -36   JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/oneway/Attic/OnewayConnectionManagerTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OnewayConnectionManagerTestCase.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/oneway/Attic/OnewayConnectionManagerTestCase.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -b -r1.1.2.2 -r1.1.2.3
  --- OnewayConnectionManagerTestCase.java	30 Jun 2007 07:47:45 -0000	1.1.2.2
  +++ OnewayConnectionManagerTestCase.java	6 Jul 2007 06:24:31 -0000	1.1.2.3
  @@ -46,13 +46,14 @@
   import org.jboss.remoting.transport.Connector;
   import org.jboss.remoting.transport.PortUtil;
   import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
  +import org.jboss.remoting.transport.socket.SocketWrapper;
   
   
   /**
    * Tests the oneway connection timer task in MicroSocketClientInvoker.
    * 
    * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
  - * @version $Revision: 1.1.2.2 $
  + * @version $Revision: 1.1.2.3 $
    * <p>
    * Copyright Jun 23, 2007
    * </p>
  @@ -83,9 +84,9 @@
      
      
      /**
  -    * Connections time out.  Uses default parameters.
  +    * Connections time out.  Uses default oneway timeout.
       */
  -   public void testDefaultParametersWithTimeouts() throws Throwable
  +   public void testDefaultTimeoutWithTimeouts() throws Throwable
      { 
         log.info("entering " + getName());
         String host = InetAddress.getLocalHost().getHostAddress();
  @@ -118,7 +119,7 @@
         
         int INVOCATIONS = 5;
         HashMap metadata = new HashMap();
  -      metadata.put(DELAY, "14000");
  +      metadata.put(DELAY, "4000");
         long start = System.currentTimeMillis();
         for (int i = 0; i < INVOCATIONS; i++)
         {
  @@ -131,14 +132,13 @@
         assertEquals(INVOCATIONS, usedPool);
         assertEquals(0, pool.size());
         assertEquals(INVOCATIONS, handler.startedCount);
  -      Thread.sleep(10000);
  +      Thread.sleep(4000);
         
  -      // All sockets should have timed out by now.  Each timeout takes 1 second.
  +      // All sockets should have timed out by now.
         usedPool = ((Long) field.get(invoker)).longValue();
         assertEquals(0, usedPool);
         assertEquals(0, pool.size());
  -      assertEquals(0, handler.finishedCount);
  -      Thread.sleep(5000);
  +      Thread.sleep(1000);
         
         // All invocations should be done by now.
         usedPool = ((Long) field.get(invoker)).longValue();
  @@ -153,9 +153,9 @@
      
      
      /**
  -    * Connections don't time out.  Uses default parameters.
  +    * Connections don't time out.  Uses default oneway timeout.
       */
  -   public void testDefaultParametersWithNoTimeouts() throws Throwable
  +   public void testDefaultTimeoutWithNoTimeouts() throws Throwable
      {
         log.info("entering " + getName());
         String host = InetAddress.getLocalHost().getHostAddress();
  @@ -188,7 +188,7 @@
         
         int INVOCATIONS = 5;
         HashMap metadata = new HashMap();
  -      metadata.put(DELAY, "2000");
  +      metadata.put(DELAY, "1000");
         long start = System.currentTimeMillis();
         for (int i = 0; i < INVOCATIONS; i++)
         {
  @@ -196,12 +196,12 @@
         }
   
         assertTrue((System.currentTimeMillis() - start < 1000));
  -      Thread.sleep(1000);
  +      Thread.sleep(500);
         usedPool = ((Long) field.get(invoker)).longValue();
         assertEquals(INVOCATIONS, usedPool);
         assertEquals(0, pool.size());
         assertEquals(INVOCATIONS, handler.startedCount);
  -      Thread.sleep(6000);
  +      Thread.sleep(2000);
         
         // All invocations should have finished by now, and all sockets should
         // have been returned to the pool.
  @@ -217,9 +217,9 @@
      
   
      /**
  -    * Connections time out.  Uses configured parameters.
  +    * Connections time out.  Uses configured oneway timeout.
       */
  -   public void testConfiguredParametersWithTimeouts() throws Throwable
  +   public void testConfiguredTimeoutWithTimeouts() throws Throwable
      {
         log.info("entering " + getName());
         String host = InetAddress.getLocalHost().getHostAddress();
  @@ -236,8 +236,7 @@
         config.put(InvokerLocator.FORCE_REMOTE, "true");
         config.put(Client.MAX_NUM_ONEWAY_THREADS, "5");
         config.put(Client.MAX_ONEWAY_THREAD_POOL_QUEUE_SIZE, "1");
  -      config.put(MicroSocketClientInvoker.ONEWAY_CONNECTION_DELAY, "1000");
  -      config.put(MicroSocketClientInvoker.ONEWAY_CONNECTION_TIMEOUT, "100");
  +      config.put(MicroSocketClientInvoker.ONEWAY_CONNECTION_TIMEOUT, "500");
         Client client = new Client(locator, config);
         client.connect();
         
  @@ -254,7 +253,7 @@
         
         int INVOCATIONS = 5;
         HashMap metadata = new HashMap();
  -      metadata.put(DELAY, "2000");
  +      metadata.put(DELAY, "1000");
         long start = System.currentTimeMillis();
         for (int i = 0; i < INVOCATIONS; i++)
         {
  @@ -262,14 +261,15 @@
         }
   
         assertTrue((System.currentTimeMillis() - start < 1000));
  -      Thread.sleep(500);
  +      Thread.sleep(100);
         usedPool = ((Long) field.get(invoker)).longValue();
         assertEquals(INVOCATIONS, usedPool);
         assertEquals(0, pool.size());
         assertEquals(INVOCATIONS, handler.startedCount);
         Thread.sleep(2000);
         
  -      // All sockets should have timed out by now.  Each timeout takes 100 ms.
  +      // All sockets should have timed out by now.  Note that they would not have
  +      // timed out with default oneway timeout.
         usedPool = ((Long) field.get(invoker)).longValue();
         assertEquals(0, usedPool);
         assertEquals(0, pool.size());
  @@ -288,9 +288,9 @@
      
      
      /**
  -    * Connections time out.  Uses configured parameters.
  +    * Connections don't time out.  Uses configured oneway timeout.
       */
  -   public void testConfiguredParametersWithNoTimeouts() throws Throwable
  +   public void testConfiguredTimeoutWithNoTimeouts() throws Throwable
      {
         log.info("entering " + getName());
         String host = InetAddress.getLocalHost().getHostAddress();
  @@ -307,8 +307,7 @@
         config.put(InvokerLocator.FORCE_REMOTE, "true");
         config.put(Client.MAX_NUM_ONEWAY_THREADS, "5");
         config.put(Client.MAX_ONEWAY_THREAD_POOL_QUEUE_SIZE, "1");
  -      config.put(MicroSocketClientInvoker.ONEWAY_CONNECTION_DELAY, "5000");
  -      config.put(MicroSocketClientInvoker.ONEWAY_CONNECTION_TIMEOUT, "5000");
  +      config.put(MicroSocketClientInvoker.ONEWAY_CONNECTION_TIMEOUT, "6000");
         Client client = new Client(locator, config);
         client.connect();
         
  @@ -325,7 +324,7 @@
         
         int INVOCATIONS = 5;
         HashMap metadata = new HashMap();
  -      metadata.put(DELAY, "8000");
  +      metadata.put(DELAY, "4000");
         long start = System.currentTimeMillis();
         for (int i = 0; i < INVOCATIONS; i++)
         {
  @@ -338,10 +337,11 @@
         assertEquals(INVOCATIONS, usedPool);
         assertEquals(0, pool.size());
         assertEquals(INVOCATIONS, handler.startedCount);
  -      Thread.sleep(11000);
  +      Thread.sleep(5000);
         
         // All invocations should have finished by now, and all sockets should
  -      // have been returned to the pool.
  +      // have been returned to the pool.  Note that sockets would have timeed out
  +      // if the default oneway timeout value were used.
         assertEquals(INVOCATIONS, handler.finishedCount);
         usedPool = ((Long) field.get(invoker)).longValue();
         assertEquals(0, usedPool);
  @@ -441,8 +441,8 @@
         clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
         clientConfig.put(Client.MAX_NUM_ONEWAY_THREADS, "100");
         clientConfig.put(Client.MAX_ONEWAY_THREAD_POOL_QUEUE_SIZE, "100");
  -      clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "200");
  -      clientConfig.put(MicroSocketClientInvoker.ONEWAY_CONNECTION_DELAY, "1000");
  +      clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "100");
  +      clientConfig.put(MicroSocketClientInvoker.ONEWAY_CONNECTION_TIMEOUT, "1000");
         Client client = new Client(locator, clientConfig);
         client.connect();
         
  @@ -467,14 +467,15 @@
         }
         
         go = true;
  -      Thread.sleep(2000);
  +      Thread.sleep(1000);
         
         // Verify first set of invocations were received.
  -      assertEquals(200, handler.startedCount);
  -      Thread.sleep(12000);
  +      assertEquals(100, handler.startedCount);
  +      Thread.sleep(7000);
         
         // Verify rest of invocations were received.
         assertEquals(INVOCATIONS, handler.startedCount);
  +      Thread.sleep(5000);
         
         // All invocations should be complete by now.
         for (int i = 0; i < INVOCATIONS; i++)
  @@ -482,7 +483,6 @@
            assertTrue("failure in thread: " + i, threads[i].ok);
         }
         
  -      Thread.sleep(4000);
         usedPool = ((Long) field.get(invoker)).longValue();
         assertEquals(0, usedPool);
         
  @@ -514,8 +514,8 @@
         clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
         clientConfig.put(Client.MAX_NUM_ONEWAY_THREADS, "100");
         clientConfig.put(Client.MAX_ONEWAY_THREAD_POOL_QUEUE_SIZE, "100");
  -      clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "200");
  -      clientConfig.put(MicroSocketClientInvoker.ONEWAY_CONNECTION_DELAY, "1000");
  +      clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "100");
  +      clientConfig.put(MicroSocketClientInvoker.ONEWAY_CONNECTION_TIMEOUT, "1000");
         Client client = new Client(locator, clientConfig);
         client.connect();
         
  @@ -540,7 +540,7 @@
         }
         
         go = true;
  -      Thread.sleep(8000);
  +      Thread.sleep(4000);
         
         // Verify invocations were received.
         assertEquals(INVOCATIONS, handler.startedCount);
  @@ -553,6 +553,79 @@
         
         usedPool = ((Long) field.get(invoker)).longValue();
         assertEquals(0, usedPool);
  +      assertEquals(100, pool.size());
  +      
  +      client.disconnect();
  +      connector.stop();
  +      log.info(getName() + " PASSES");
  +   }
  +   
  +   
  +   /**
  +    * Make sure timeout value is reset before socket is returned to pool.
  +    */
  +   public void testTimeoutReset() throws Throwable
  +   {
  +      log.info("entering " + getName());
  +      String host = InetAddress.getLocalHost().getHostAddress();
  +      int port = PortUtil.findFreePort(host);
  +      String locatorURI = "socket://" + host + ":" + port;
  +      InvokerLocator locator = new InvokerLocator(locatorURI);
  +      Connector connector = new Connector(locator);
  +      connector.create();
  +      TestHandler handler = new TestHandler();
  +      connector.addInvocationHandler("test", handler);
  +      connector.start();
  +      
  +      HashMap config = new HashMap();
  +      config.put(InvokerLocator.FORCE_REMOTE, "true");
  +      config.put(Client.MAX_NUM_ONEWAY_THREADS, "5");
  +      config.put(Client.MAX_ONEWAY_THREAD_POOL_QUEUE_SIZE, "1");
  +      config.put(ServerInvoker.TIMEOUT, "5000");
  +      config.put(MicroSocketClientInvoker.ONEWAY_CONNECTION_TIMEOUT, "7000");
  +      Client client = new Client(locator, config);
  +      client.connect();
  +      
  +      ClientInvoker invoker = client.getInvoker();
  +      assertTrue(invoker instanceof MicroSocketClientInvoker); 
  +      Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
  +      field.setAccessible(true);
  +      LinkedList pool = (LinkedList) field.get(invoker);
  +      assertEquals(0, pool.size());
  +      field = MicroSocketClientInvoker.class.getDeclaredField("usedPooled");
  +      field.setAccessible(true);
  +      long usedPool = ((Long) field.get(invoker)).longValue();
  +      assertEquals(0, usedPool);
  +      
  +      int INVOCATIONS = 5;
  +      HashMap metadata = new HashMap();
  +      metadata.put(DELAY, "1000");
  +      long start = System.currentTimeMillis();
  +      for (int i = 0; i < INVOCATIONS; i++)
  +      {
  +         client.invokeOneway(SLOW + i, metadata, true);
  +      }
  +
  +      assertTrue((System.currentTimeMillis() - start < 1000));
  +      Thread.sleep(500);
  +      usedPool = ((Long) field.get(invoker)).longValue();
  +      assertEquals(INVOCATIONS, usedPool);
  +      assertEquals(0, pool.size());
  +      assertEquals(INVOCATIONS, handler.startedCount);
  +      Thread.sleep(2000);
  +      
  +      // All invocations should have finished by now, and all sockets should
  +      // have been returned to the pool.
  +      assertEquals(INVOCATIONS, handler.finishedCount);
  +      usedPool = ((Long) field.get(invoker)).longValue();
  +      assertEquals(0, usedPool);
  +      assertEquals(INVOCATIONS, pool.size());
  +      
  +      for (int i = 0; i < INVOCATIONS; i++)
  +      {
  +         SocketWrapper wrapper = (SocketWrapper) pool.get(i);
  +         assertEquals("invalid timeout value: socket" + i, 5000, wrapper.getTimeout());
  +      }
         
         client.disconnect();
         connector.stop();
  
  
  



More information about the jboss-cvs-commits mailing list