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

Ron Sigal ron_sigal at yahoo.com
Wed Apr 11 19:49:46 EDT 2007


  User: rsigal  
  Date: 07/04/11 19:49:46

  Modified:    src/tests/org/jboss/test/remoting/transport/bisocket  Tag:
                        remoting_2_2_0_GA BisocketTestCase.java
  Log:
  JBREM-731, JBREM-732, JBREM-734:  (1) Test new parameters in testConfiguration(); (2) added testXMLConfiguration().
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.12.2.1 +288 -10   JBossRemoting/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BisocketTestCase.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketTestCase.java,v
  retrieving revision 1.1.2.12
  retrieving revision 1.1.2.12.2.1
  diff -u -b -r1.1.2.12 -r1.1.2.12.2.1
  --- BisocketTestCase.java	15 Mar 2007 22:24:10 -0000	1.1.2.12
  +++ BisocketTestCase.java	11 Apr 2007 23:49:46 -0000	1.1.2.12.2.1
  @@ -21,6 +21,7 @@
   */
   package org.jboss.test.remoting.transport.bisocket;
   
  +import java.io.ByteArrayInputStream;
   import java.lang.reflect.Field;
   import java.net.InetAddress;
   import java.net.Socket;
  @@ -32,6 +33,7 @@
   import java.util.Map;
   import java.util.Set;
   import javax.management.MBeanServer;
  +import javax.xml.parsers.DocumentBuilderFactory;
   
   import junit.framework.TestCase;
   
  @@ -60,11 +62,12 @@
   import org.jboss.remoting.transport.socket.ServerThread;
   import org.jboss.remoting.transport.socket.SocketServerInvoker;
   import org.jboss.remoting.transport.socket.SocketWrapper;
  +import org.w3c.dom.Document;
   
   
   /** 
    * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
  - * @version $Revision: 1.1.2.12 $
  + * @version $Revision: 1.1.2.12.2.1 $
    * <p>
    * Copyright Nov 25, 2006
    * </p>
  @@ -83,8 +86,12 @@
      private static final int    TEST_PING_FREQUENCY = 1000;
      private static final String TEST_PING_WINDOW_FACTOR_STRING = "3";
      private static final int    TEST_PING_WINDOW_FACTOR = 3;
  -   private static final String TEST_MAX_POOL_SIZE_STRING = "5";
  -   private static final int    TEST_MAX_POOL_SIZE = 5;
  +   private static final String TEST_MAX_RETRIES_STRING = "5";
  +   private static final int    TEST_MAX_RETRIES = 5;
  +   private static final String TEST_CONTROL_CONNECTION_RESTARTS_STRING = "7";
  +   private static final int    TEST_CONTROL_CONNECTION_RESTARTS = 7;
  +   private static final String TEST_MAX_POOL_SIZE_STRING = "9";
  +   private static final int    TEST_MAX_POOL_SIZE = 9;
      
      private static boolean firstTime = true;
      
  @@ -157,7 +164,7 @@
         HashMap serverConfig = new HashMap();
         serverConfig.put(InvokerLocator.FORCE_REMOTE, "true");
         serverConfig.put(Bisocket.PING_FREQUENCY, TEST_PING_FREQUENCY_STRING);
  -      serverConfig.put(Bisocket.PING_WINDOW_FACTOR, TEST_PING_WINDOW_FACTOR_STRING);
  +      serverConfig.put(Bisocket.MAX_RETRIES, TEST_MAX_RETRIES_STRING);
         addExtraServerConfig(serverConfig);
         connector = new Connector(serverLocator, serverConfig);
         connector.create();
  @@ -167,31 +174,162 @@
         
         HashMap clientConfig = new HashMap();
         clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
  +      clientConfig.put(Bisocket.IS_CALLBACK_SERVER, "true");
         clientConfig.put(Bisocket.PING_FREQUENCY, TEST_PING_FREQUENCY_STRING);
  +      clientConfig.put(Bisocket.PING_WINDOW_FACTOR, TEST_PING_WINDOW_FACTOR_STRING);
  +      clientConfig.put(Bisocket.MAX_RETRIES, TEST_MAX_RETRIES_STRING);
  +      clientConfig.put(Bisocket.MAX_CONTROL_CONNECTION_RESTARTS, TEST_CONTROL_CONNECTION_RESTARTS_STRING);
  +
         addExtraClientConfig(clientConfig);
         Client client = new Client(serverLocator, clientConfig);
         client.connect();
         log.info("client is connected");
         
  +      SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
  +      client.addListener(callbackHandler, new HashMap());
  +      log.info("client added callback handler");
  +      
         Integer count = new Integer(17);
         HashMap metadata = new HashMap();
         metadata.put(COUNTER, count);
         Integer response = (Integer) client.invoke(INVOCATION_TEST, metadata);
         assertEquals(17, response.intValue());
         
  +      // Test server invoker configuration.
  +      // Actually, none of these parameters are used by the server invoker.
  +      
  +      // Test callback client invoker configuration.
  +      Set callbackHandlers = invocationHandler.callbackHandlers;
  +      assertEquals(1, callbackHandlers.size());
  +      ServerInvokerCallbackHandler sich = (ServerInvokerCallbackHandler) callbackHandlers.iterator().next();
  +      Client callbackClient = sich.getCallbackClient();
  +      assertTrue(callbackClient.getInvoker() instanceof BisocketClientInvoker);
  +      BisocketClientInvoker callbackClientInvoker = (BisocketClientInvoker) callbackClient.getInvoker();
  +      assertEquals(TEST_PING_FREQUENCY, callbackClientInvoker.getPingFrequency());
  +      assertEquals(TEST_MAX_RETRIES, callbackClientInvoker.getMaxRetries());
  +
  +      // Test client invoker configuration.
  +      assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
  +      BisocketClientInvoker clientInvoker = (BisocketClientInvoker) client.getInvoker();
  +      assertEquals(TEST_PING_FREQUENCY, clientInvoker.getPingFrequency());
  +      assertEquals(TEST_MAX_RETRIES, clientInvoker.getMaxRetries());
  +      
  +      // Test callback server invoker configuration.
  +      Field field = Client.class.getDeclaredField("callbackConnectors");
  +      field.setAccessible(true);
  +      Map callbackConnectorsMap = (Map) field.get(client);
  +      assertEquals(1, callbackConnectorsMap.size());
  +      Set callbackConnectorsSet = (Set) callbackConnectorsMap.values().iterator().next();
  +      assertEquals(1, callbackConnectorsSet.size());
  +      Connector callbackConnector = (Connector) callbackConnectorsSet.iterator().next();
         assertTrue(connector.getServerInvoker() instanceof BisocketServerInvoker);
  -      BisocketServerInvoker serverInvoker = (BisocketServerInvoker) connector.getServerInvoker();
  -      assertEquals(TEST_PING_FREQUENCY, serverInvoker.getPingFrequency());
  -      assertEquals(TEST_PING_WINDOW_FACTOR, serverInvoker.getPingWindowFactor());
  -      Field field = BisocketServerInvoker.class.getDeclaredField("pingWindow");
  +      BisocketServerInvoker callbackServerInvoker = (BisocketServerInvoker) callbackConnector.getServerInvoker();
  +      assertEquals(TEST_PING_FREQUENCY, callbackServerInvoker.getPingFrequency());
  +      assertEquals(TEST_PING_WINDOW_FACTOR, callbackServerInvoker.getPingWindowFactor());
  +      field = BisocketServerInvoker.class.getDeclaredField("pingWindow");
         field.setAccessible(true);
  -      int pingWindow = ((Integer) field.get(serverInvoker)).intValue();
  +      int pingWindow = ((Integer) field.get(callbackServerInvoker)).intValue();
         assertEquals(TEST_PING_WINDOW_FACTOR * TEST_PING_FREQUENCY, pingWindow);
  +      assertEquals(TEST_MAX_RETRIES, callbackServerInvoker.getSocketCreationRetries());
  +      assertEquals(TEST_CONTROL_CONNECTION_RESTARTS, callbackServerInvoker.getControlConnectionRestarts());
  + 
  +      client.removeListener(callbackHandler);
  +      client.disconnect();
  +   }
  +
  +   
  +   public void testXMLConfiguration() throws Throwable
  +   {
  +      log.info("entering " + getName());
  +      connector.stop();
  +      
  +      String host = InetAddress.getLocalHost().getHostAddress();
  +      int port = PortUtil.findFreePort(host);
  +      HashMap serverConfig = new HashMap();
  +      serverConfig.put(InvokerLocator.FORCE_REMOTE, "true");
  +      addExtraServerConfig(serverConfig);
  +      connector = new Connector(serverConfig);
  +      
  +      StringBuffer buf = new StringBuffer();
  +      buf.append("<?xml version=\"1.0\"?>\n");
  +      buf.append("<config>");
  +      buf.append("   <invoker transport=\"" + getTransport() + "\">");
  +      buf.append("      <attribute name=\"serverBindAddress\">" + host + "</attribute>");
  +      buf.append("      <attribute name=\"serverBindPort\">" + port + "</attribute>");
  +      buf.append("      <attribute name=\"pingFrequency\" isParam=\"true\">" + TEST_PING_FREQUENCY_STRING + "</attribute>");
  +      buf.append("      <attribute name=\"pingWindowFactor\" isParam=\"true\">" + TEST_PING_WINDOW_FACTOR_STRING + "</attribute>");
  +      buf.append("      <attribute name=\"maxRetries\" isParam=\"true\">" + TEST_MAX_RETRIES_STRING + "</attribute>");
  +      buf.append("      <attribute name=\"maxControlConnectionRestarts\" isParam=\"true\">" + TEST_CONTROL_CONNECTION_RESTARTS_STRING + "</attribute>");
  +      buf.append("   </invoker>");
  +      buf.append("</config>");
  +      log.info(buf);
  +      ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
  +      Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
  +      connector.setConfiguration(xml.getDocumentElement());
  +      connector.create();
  +      invocationHandler = new SampleInvocationHandler();
  +      connector.addInvocationHandler("sample", invocationHandler);
  +      connector.start();
  +      InvokerLocator serverLocator = connector.getLocator();
  +      System.out.println("started connector with locator uri of: " + serverLocator);
  +      
  +      HashMap clientConfig = new HashMap();
  +      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
  +      clientConfig.put(Bisocket.IS_CALLBACK_SERVER, "true");
  +      addExtraClientConfig(clientConfig);
  +      Client client = new Client(serverLocator, clientConfig);
  +      client.connect();
  +      log.info("client is connected");
  +      
  +      SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
  +      client.addListener(callbackHandler, new HashMap());
  +      log.info("client added callback handler");
  +      
  +      Integer count = new Integer(17);
  +      HashMap metadata = new HashMap();
  +      metadata.put(COUNTER, count);
  +      Integer response = (Integer) client.invoke(INVOCATION_TEST, metadata);
  +      assertEquals(17, response.intValue());
  +      
  +      // Test server invoker configuration.
  +      // Actually, none of these parameters are used by the server invoker.
            
  +      // Test callback client invoker configuration.
  +      Set callbackHandlers = invocationHandler.callbackHandlers;
  +      assertEquals(1, callbackHandlers.size());
  +      ServerInvokerCallbackHandler sich = (ServerInvokerCallbackHandler) callbackHandlers.iterator().next();
  +      Client callbackClient = sich.getCallbackClient();
  +      assertTrue(callbackClient.getInvoker() instanceof BisocketClientInvoker);
  +      BisocketClientInvoker callbackClientInvoker = (BisocketClientInvoker) callbackClient.getInvoker();
  +      assertEquals(TEST_PING_FREQUENCY, callbackClientInvoker.getPingFrequency());
  +      assertEquals(TEST_MAX_RETRIES, callbackClientInvoker.getMaxRetries());
  + 
  +      // Test client invoker configuration.
         assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
         BisocketClientInvoker clientInvoker = (BisocketClientInvoker) client.getInvoker();
         assertEquals(TEST_PING_FREQUENCY, clientInvoker.getPingFrequency());
  +      assertEquals(TEST_MAX_RETRIES, clientInvoker.getMaxRetries());
  +      
  +      // Test callback server invoker configuration.
  +      Field field = Client.class.getDeclaredField("callbackConnectors");
  +      field.setAccessible(true);
  +      Map callbackConnectorsMap = (Map) field.get(client);
  +      assertEquals(1, callbackConnectorsMap.size());
  +      Set callbackConnectorsSet = (Set) callbackConnectorsMap.values().iterator().next();
  +      assertEquals(1, callbackConnectorsSet.size());
  +      Connector callbackConnector = (Connector) callbackConnectorsSet.iterator().next();
  +      assertTrue(connector.getServerInvoker() instanceof BisocketServerInvoker);
  +      BisocketServerInvoker callbackServerInvoker = (BisocketServerInvoker) callbackConnector.getServerInvoker();
  +      assertEquals(TEST_PING_FREQUENCY, callbackServerInvoker.getPingFrequency());
  +      assertEquals(TEST_PING_WINDOW_FACTOR, callbackServerInvoker.getPingWindowFactor());
  +      field = BisocketServerInvoker.class.getDeclaredField("pingWindow");
  +      field.setAccessible(true);
  +      int pingWindow = ((Integer) field.get(callbackServerInvoker)).intValue();
  +      assertEquals(TEST_PING_WINDOW_FACTOR * TEST_PING_FREQUENCY, pingWindow);
  +      assertEquals(TEST_MAX_RETRIES, callbackServerInvoker.getSocketCreationRetries());
  +      assertEquals(TEST_CONTROL_CONNECTION_RESTARTS, callbackServerInvoker.getControlConnectionRestarts());
         
  +      client.removeListener(callbackHandler);
         client.disconnect();
      }
      
  @@ -1538,7 +1676,11 @@
      }
      
      
  -   public void testServerRestart() throws Throwable
  +   /**
  +    * This method tests the ability of a client to connect to a restarted
  +    * server after a failure has been detected on the control connection.
  +    */
  +   public void testServerSlowRestart() throws Throwable
      {
         log.info("entering " + getName());
         String host = InetAddress.getLocalHost().getHostName();
  @@ -1581,6 +1723,7 @@
         log.info("RESTARTED CONNECTOR");
         assertNotSame(connector, oldConnector);
         
  +      // Wait until a failure has been detected on the control connection.
         Thread.sleep(TEST_PING_FREQUENCY * 5);
         
         // It is beyond the scope of Remoting to fail over to a new server,
  @@ -1608,6 +1751,141 @@
      }
      
      
  +   /**
  +    * This method tests the ability of a client to connect to a restarted
  +    * server before a failure has been detected on the control connection.
  +    * It guards against the bug in JBREM-731.
  +    */
  +   public void testServerQuickRestart() throws Throwable
  +   {
  +      log.info("entering " + getName());
  +      String host = InetAddress.getLocalHost().getHostName();
  +      String locatorURI = getTransport() + "://" + host + ":" + port; 
  +      InvokerLocator serverLocator = new InvokerLocator(locatorURI);
  +      log.info("Connecting to: " + serverLocator);
  +      HashMap config = new HashMap();
  +      config.put(InvokerLocator.FORCE_REMOTE, "true");
  +      config.put(Bisocket.IS_CALLBACK_SERVER, "true");
  +      config.put(Bisocket.PING_FREQUENCY, TEST_PING_FREQUENCY_STRING);
  +      addExtraClientConfig(config);
  +      Client client = new Client(serverLocator, config);
  +      client.connect();
  +      log.info("client is connected");
  +      assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
  +      SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
  +      client.addListener(callbackHandler, new HashMap());
  +      log.info("client added callback handler");
  +      client.invoke(CALLBACK_TEST);
  +      assertEquals(1, callbackHandler.callbackCounter);
  +      
  +      Connector oldConnector = connector;
  +      SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
  +      Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
  +      field.setAccessible(true);
  +      LRUPool clientpool = (LRUPool) field.get(invoker);
  +      Set threads = clientpool.getContents();
  +      for (Iterator it = threads.iterator(); it.hasNext(); )
  +      {
  +         ServerThread t = (ServerThread) it.next();
  +         field = ServerThread.class.getDeclaredField("socketWrapper");
  +         field.setAccessible(true);
  +         SocketWrapper socketWrapper = (SocketWrapper) field.get(t);
  +         socketWrapper.close();
  +      }
  +      connector.stop();
  +      log.info("STOPPED CONNECTOR");
  +      
  +      internalSetUp(port);
  +      log.info("RESTARTED CONNECTOR");
  +      assertNotSame(connector, oldConnector);
  +      
  +      // It is beyond the scope of Remoting to fail over to a new server,
  +      // complete with registered callback handlers.
  +      log.info("adding callback handler");
  +      client.addListener(callbackHandler, new HashMap());
  +      log.info("client added callback handler");
  +      
  +      client.invoke(CALLBACK_TEST);
  +      assertEquals(2, callbackHandler.callbackCounter);
  +
  +      client.removeListener(callbackHandler);
  +      client.disconnect();
  +      
  +      // The ControlMonitorTimerTask from the first callback handler tries to recreate
  +      // its control connection, which adds an entry to
  +      // BisocketClientInvoker.listenerIdToSocketsMap which cannot be removed, which
  +      // interferes with testForLeaks().
  +      //
  +      // TODO: Should the possibility of a leak because of this phenomenon be handled?
  +      field = BisocketClientInvoker.class.getDeclaredField("listenerIdToSocketsMap");
  +      field.setAccessible(true);
  +      Map listenerIdToSocketsMap = (Map) field.get(null);
  +      listenerIdToSocketsMap.clear();
  +   }
  +   
  +   
  +   public void testDeadControlConnectionShutdown() throws Throwable
  +   {
  +      log.info("entering " + getName());
  +      String host = InetAddress.getLocalHost().getHostName();
  +      String locatorURI = getTransport() + "://" + host + ":" + port; 
  +      InvokerLocator serverLocator = new InvokerLocator(locatorURI);
  +      log.info("Connecting to: " + serverLocator);
  +      HashMap config = new HashMap();
  +      config.put(InvokerLocator.FORCE_REMOTE, "true");
  +      config.put(Bisocket.IS_CALLBACK_SERVER, "true");
  +      config.put(Bisocket.PING_FREQUENCY, TEST_PING_FREQUENCY_STRING);
  +      int MAX_RETRIES = 3;
  +      config.put(Bisocket.MAX_CONTROL_CONNECTION_RESTARTS, Integer.toString(MAX_RETRIES));
  +      addExtraClientConfig(config);
  +      Client client = new Client(serverLocator, config);
  +      client.connect();
  +      log.info("client is connected");
  +      assertTrue(client.getInvoker() instanceof BisocketClientInvoker);
  +      
  +      String callbackLocatorURI = getTransport() + "://" + host + ":1";
  +      config.put(Bisocket.IS_CALLBACK_SERVER, "true");
  +      Connector callbackConnector = new Connector(callbackLocatorURI, config);
  +      callbackConnector.start();
  +      SimpleCallbackHandler callbackHandler = new SimpleCallbackHandler();
  +      client.addListener(callbackHandler, new InvokerLocator(callbackLocatorURI));
  +      log.info("client added callback handler");
  +      client.invoke(CALLBACK_TEST);
  +      assertEquals(1, callbackHandler.callbackCounter);
  +      
  +      SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
  +      Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
  +      field.setAccessible(true);
  +      LRUPool clientpool = (LRUPool) field.get(invoker);
  +      Set threads = clientpool.getContents();
  +      for (Iterator it = threads.iterator(); it.hasNext(); )
  +      {
  +         ServerThread t = (ServerThread) it.next();
  +         field = ServerThread.class.getDeclaredField("socketWrapper");
  +         field.setAccessible(true);
  +         SocketWrapper socketWrapper = (SocketWrapper) field.get(t);
  +         socketWrapper.close();
  +      }
  +      connector.stop();
  +      log.info("STOPPED CONNECTOR");
  +      internalSetUp(port);
  +      log.info("RESTARTED CONNECTOR");
  +      
  +      // Wait until a failure has been detected on the control connection.
  +      Thread.sleep(TEST_PING_FREQUENCY * MAX_RETRIES * 8);
  +      
  +      ServerInvoker callbackServerInvoker = callbackConnector.getServerInvoker();
  +      field = BisocketServerInvoker.class.getDeclaredField("controlConnectionThreadMap");
  +      field.setAccessible(true);
  +      Map controlConnectionThreadMap = (Map) field.get(callbackServerInvoker);
  +      assertEquals(0, controlConnectionThreadMap.size());
  +      
  +      client.setDisconnectTimeout(0);
  +      client.removeListener(callbackHandler);
  +      client.disconnect();
  +   }
  +   
  +   
      public void testForLeaks() throws Throwable
      {
         log.info("entering " + getName());
  
  
  



More information about the jboss-cvs-commits mailing list