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

Ron Sigal ron_sigal at yahoo.com
Wed Apr 11 04:05:00 EDT 2007


  User: rsigal  
  Date: 07/04/11 04:05:00

  Modified:    src/tests/org/jboss/test/remoting/transport/bisocket  Tag:
                        remoting_2_x 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.15  +147 -9    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.14
  retrieving revision 1.1.2.15
  diff -u -b -r1.1.2.14 -r1.1.2.15
  --- BisocketTestCase.java	7 Apr 2007 08:18:55 -0000	1.1.2.14
  +++ BisocketTestCase.java	11 Apr 2007 08:05:00 -0000	1.1.2.15
  @@ -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.14 $
  + * @version $Revision: 1.1.2.15 $
    * <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();
      }
      
  
  
  



More information about the jboss-cvs-commits mailing list