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

Ron Sigal ron_sigal at yahoo.com
Mon Aug 20 02:15:45 EDT 2007


  User: rsigal  
  Date: 07/08/20 02:15:45

  Added:       src/tests/org/jboss/test/remoting/transport/bisocket  Tag:
                        remoting_2_2_2_experimental
                        SecondaryPortTestCase.java
  Log:
  JBREM-749:  New unit test.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +324 -0    JBossRemoting/src/tests/org/jboss/test/remoting/transport/bisocket/Attic/SecondaryPortTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SecondaryPortTestCase.java
  ===================================================================
  RCS file: SecondaryPortTestCase.java
  diff -N SecondaryPortTestCase.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ SecondaryPortTestCase.java	20 Aug 2007 06:15:45 -0000	1.1.2.1
  @@ -0,0 +1,324 @@
  +/*
  +* JBoss, Home of Professional Open Source
  +* Copyright 2005, JBoss Inc., and individual contributors as indicated
  +* by the @authors tag. See the copyright.txt in the distribution for a
  +* full listing of individual contributors.
  +*
  +* This is free software; you can redistribute it and/or modify it
  +* under the terms of the GNU Lesser General Public License as
  +* published by the Free Software Foundation; either version 2.1 of
  +* the License, or (at your option) any later version.
  +*
  +* This software is distributed in the hope that it will be useful,
  +* but WITHOUT ANY WARRANTY; without even the implied warranty of
  +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  +* Lesser General Public License for more details.
  +*
  +* You should have received a copy of the GNU Lesser General Public
  +* License along with this software; if not, write to the Free
  +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  +* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  +*/
  +package org.jboss.test.remoting.transport.bisocket;
  +
  +import java.io.ByteArrayInputStream;
  +import java.lang.reflect.Field;
  +import java.net.InetAddress;
  +import java.net.ServerSocket;
  +import java.util.HashMap;
  +import java.util.Map;
  +
  +import javax.management.MBeanServer;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +
  +import junit.framework.TestCase;
  +
  +import org.apache.log4j.ConsoleAppender;
  +import org.apache.log4j.Level;
  +import org.apache.log4j.Logger;
  +import org.apache.log4j.PatternLayout;
  +import org.jboss.remoting.Client;
  +import org.jboss.remoting.InvocationRequest;
  +import org.jboss.remoting.InvokerLocator;
  +import org.jboss.remoting.ServerInvocationHandler;
  +import org.jboss.remoting.ServerInvoker;
  +import org.jboss.remoting.callback.InvokerCallbackHandler;
  +import org.jboss.remoting.transport.Connector;
  +import org.jboss.remoting.transport.PortUtil;
  +import org.jboss.remoting.transport.bisocket.Bisocket;
  +import org.jboss.remoting.transport.bisocket.BisocketServerInvoker;
  +import org.w3c.dom.Document;
  +
  +
  +public class SecondaryPortTestCase extends TestCase
  +{
  +   public static int port;
  +   
  +   private static Logger log = Logger.getLogger(SecondaryPortTestCase.class);
  +   private static boolean firstTime = true;
  +   
  +   // remoting server connector
  +   private Connector connector;
  +   private InvokerLocator serverLocator;
  +   private TestInvocationHandler invocationHandler;
  +
  +   
  +   /**
  +    * Sets up target remoting server.
  +    */
  +   public void setUp() throws Exception
  +   {
  +      if (firstTime)
  +      {
  +         firstTime = false;
  +         Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
  +         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
  +         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
  +         PatternLayout layout = new PatternLayout(pattern);
  +         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
  +         Logger.getRootLogger().addAppender(consoleAppender);  
  +      }
  +   }
  +
  +   
  +   public void tearDown()
  +   {
  +   }
  +   
  +   
  +   /**
  +    * Verify that secondary port is correctly set when specifed in InvokerLocator.
  +    */
  +   public void xtestSetSecondaryPortByInvokerLocator() throws Throwable
  +   {
  +      log.info("entering " + getName());
  +      
  +      // Start server.
  +      int PORT = 5445;
  +      String host = InetAddress.getLocalHost().getHostAddress();
  +      port = PortUtil.findFreePort(host);
  +      String locatorURI = getTransport() + "://" + host + ":" + port;
  +      locatorURI += "/?" + Bisocket.SECONDARY_PORT + "=" + PORT;
  +      serverLocator = new InvokerLocator(locatorURI);
  +      log.info("Starting remoting server with locator uri of: " + locatorURI);
  +      HashMap config = new HashMap();
  +      config.put(InvokerLocator.FORCE_REMOTE, "true");
  +      addExtraServerConfig(config);
  +      connector = new Connector(serverLocator, config);
  +      connector.create();
  +      invocationHandler = new TestInvocationHandler();
  +      connector.addInvocationHandler("sample", invocationHandler);
  +      connector.start();
  +      
  +      // Create client.
  +      HashMap clientConfig = new HashMap();
  +      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
  +      addExtraClientConfig(clientConfig);
  +      Client client = new Client(serverLocator, clientConfig);
  +      client.connect();
  +      assertEquals("abc", client.invoke("abc"));
  +      log.info("client is connected");
  +      
  +      // Verify secondary ServerSocket port is set correctly.
  +      ServerInvoker serverInvoker = connector.getServerInvoker();
  +      assertTrue(serverInvoker instanceof BisocketServerInvoker);
  +      Field field = BisocketServerInvoker.class.getDeclaredField("secondaryPort");
  +      field.setAccessible(true);
  +      Integer secondaryPort = (Integer) field.get(serverInvoker);
  +      assertEquals(PORT, secondaryPort.intValue());
  +      field = BisocketServerInvoker.class.getDeclaredField("secondaryServerSocket");
  +      field.setAccessible(true);
  +      ServerSocket serverSocket = (ServerSocket) field.get(serverInvoker);
  +      assertEquals(PORT, serverSocket.getLocalPort());
  +
  +      client.disconnect();
  +      connector.stop();
  +   }
  +   
  +   
  +   /**
  +    * Verify that secondary port is correctly set when specifed in config map.
  +    */
  +   public void testSetSecondaryPortByConfigMap() throws Throwable
  +   {
  +      log.info("entering " + getName());
  +      
  +      // Start server.
  +      int PORT = 5446;
  +      String host = InetAddress.getLocalHost().getHostAddress();
  +      port = PortUtil.findFreePort(host);
  +      String locatorURI = getTransport() + "://" + host + ":" + port;
  +      serverLocator = new InvokerLocator(locatorURI);
  +      log.info("Starting remoting server with locator uri of: " + locatorURI);
  +      HashMap config = new HashMap();
  +      config.put(InvokerLocator.FORCE_REMOTE, "true");
  +      config.put(Bisocket.SECONDARY_PORT, Integer.toString(PORT));
  +      addExtraServerConfig(config);
  +      connector = new Connector(serverLocator, config);
  +      connector.create();
  +      invocationHandler = new TestInvocationHandler();
  +      connector.addInvocationHandler("sample", invocationHandler);
  +      connector.start();
  +      
  +      // Create client.
  +      HashMap clientConfig = new HashMap();
  +      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
  +      addExtraClientConfig(clientConfig);
  +      Client client = new Client(serverLocator, clientConfig);
  +      client.connect();
  +      assertEquals("abc", client.invoke("abc"));
  +      log.info("client is connected");
  +      
  +      // Verify secondary ServerSocket port is set correctly.
  +      ServerInvoker serverInvoker = connector.getServerInvoker();
  +      assertTrue(serverInvoker instanceof BisocketServerInvoker);
  +      Field field = BisocketServerInvoker.class.getDeclaredField("secondaryPort");
  +      field.setAccessible(true);
  +      Integer secondaryPort = (Integer) field.get(serverInvoker);
  +      assertEquals(PORT, secondaryPort.intValue());
  +      field = BisocketServerInvoker.class.getDeclaredField("secondaryServerSocket");
  +      field.setAccessible(true);
  +      ServerSocket serverSocket = (ServerSocket) field.get(serverInvoker);
  +      assertEquals(PORT, serverSocket.getLocalPort());
  +
  +      client.disconnect();
  +      connector.stop();
  +   }
  +   
  +   
  +   /**
  +    * Verify that secondary port is correctly set by
  +    * BisocketServerInvoker.setSecondaryPort.
  +    */
  +   public void xtestSetSecondaryPortBySetter() throws Throwable
  +   {
  +      log.info("entering " + getName());
  +      
  +      // Start server.
  +      int PORT = 5447;
  +      String host = InetAddress.getLocalHost().getHostAddress();
  +      port = PortUtil.findFreePort(host);
  +      String locatorURI = getTransport() + "://" + host + ":" + port;
  +      serverLocator = new InvokerLocator(locatorURI);
  +      log.info("Starting remoting server with locator uri of: " + locatorURI);
  +      HashMap config = new HashMap();
  +      config.put(InvokerLocator.FORCE_REMOTE, "true");
  +      addExtraServerConfig(config);
  +      connector = new Connector(serverLocator, config);
  +      connector.create();
  +      assertTrue(connector.getServerInvoker() instanceof BisocketServerInvoker);
  +      BisocketServerInvoker serverInvoker = (BisocketServerInvoker) connector.getServerInvoker();
  +      serverInvoker.setSecondaryPort(PORT);
  +      invocationHandler = new TestInvocationHandler();
  +      connector.addInvocationHandler("sample", invocationHandler);
  +      connector.start();
  +      
  +      // Create client.
  +      HashMap clientConfig = new HashMap();
  +      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
  +      addExtraClientConfig(clientConfig);
  +      Client client = new Client(serverLocator, clientConfig);
  +      client.connect();
  +      assertEquals("abc", client.invoke("abc"));
  +      log.info("client is connected");
  +      
  +      // Verify secondary ServerSocket port is set correctly.
  +      Field field = BisocketServerInvoker.class.getDeclaredField("secondaryPort");
  +      field.setAccessible(true);
  +      Integer secondaryPort = (Integer) field.get(serverInvoker);
  +      assertEquals(PORT, secondaryPort.intValue());
  +      field = BisocketServerInvoker.class.getDeclaredField("secondaryServerSocket");
  +      field.setAccessible(true);
  +      ServerSocket serverSocket = (ServerSocket) field.get(serverInvoker);
  +      assertEquals(PORT, serverSocket.getLocalPort());
  +
  +      client.disconnect();
  +      connector.stop();
  +   }
  +   
  +   
  +   /**
  +    * Verify that secondary port is correctly set by when specified in XML document.
  +    */
  +   public void xtestSetSecondaryPortByXMLConfig() throws Throwable
  +   {
  +      log.info("entering " + getName());
  +      
  +      // Start server.
  +      int PORT = 5448;
  +      String host = InetAddress.getLocalHost().getHostAddress();
  +      port = PortUtil.findFreePort(host);
  +      String locatorURI = getTransport() + "://" + host + ":" + port;
  +      serverLocator = new InvokerLocator(locatorURI);
  +      log.info("Starting remoting server with locator uri of: " + locatorURI);
  +      HashMap config = new HashMap();
  +      config.put(InvokerLocator.FORCE_REMOTE, "true");
  +      addExtraServerConfig(config);
  +      connector = new Connector(config);
  +      
  +      // Create and set xml configuration document.
  +      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=\"secondaryPort\">" + PORT + "</attribute>");
  +      buf.append("   </invoker>");
  +      buf.append("</config>");
  +      ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
  +      Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
  +      connector.setConfiguration(xml.getDocumentElement());
  +      connector.create();
  +      invocationHandler = new TestInvocationHandler();
  +      connector.addInvocationHandler("sample", invocationHandler);
  +      connector.start();
  +      
  +      // Create client.
  +      HashMap clientConfig = new HashMap();
  +      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
  +      addExtraClientConfig(clientConfig);
  +      Client client = new Client(serverLocator, clientConfig);
  +      client.connect();
  +      assertEquals("abc", client.invoke("abc"));
  +      log.info("client is connected");
  +      
  +      // Verify secondary ServerSocket port is set correctly.
  +      ServerInvoker serverInvoker = connector.getServerInvoker();
  +      assertTrue(serverInvoker instanceof BisocketServerInvoker);
  +      Field field = BisocketServerInvoker.class.getDeclaredField("secondaryPort");
  +      field.setAccessible(true);
  +      Integer secondaryPort = (Integer) field.get(serverInvoker);
  +      assertEquals(PORT, secondaryPort.intValue());
  +      field = BisocketServerInvoker.class.getDeclaredField("secondaryServerSocket");
  +      field.setAccessible(true);
  +      ServerSocket serverSocket = (ServerSocket) field.get(serverInvoker);
  +      assertEquals(PORT, serverSocket.getLocalPort());
  +
  +      client.disconnect();
  +      connector.stop();
  +   }
  +   
  +   
  +   protected String getTransport()
  +   {
  +      return "bisocket";
  +   }
  +   
  +   
  +   protected void addExtraClientConfig(Map config) {}
  +   protected void addExtraServerConfig(Map config) {}
  +   
  +
  +   static class TestInvocationHandler implements ServerInvocationHandler
  +   {
  +      public void addListener(InvokerCallbackHandler callbackHandler) {}
  +      public Object invoke(final InvocationRequest invocation) throws Throwable
  +      {
  +         return invocation.getParameter();
  +      }
  +      public void removeListener(InvokerCallbackHandler callbackHandler) {}
  +      public void setMBeanServer(MBeanServer server) {}
  +      public void setInvoker(ServerInvoker invoker) {}
  +   }
  +}
  \ No newline at end of file
  
  
  



More information about the jboss-cvs-commits mailing list