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

Tom Elrod tom.elrod at jboss.com
Mon Oct 30 23:37:53 EST 2006


  User: telrod  
  Date: 06/10/30 23:37:53

  Modified:    src/tests/org/jboss/test/remoting/transport/socket/connection     
                        SocketTestClient.java SocketTestServer.java
  Added:       src/tests/org/jboss/test/remoting/transport/socket/connection     
                        SocketConnectionCheckTestCase.java
                        SocketConnectionCheckTestClient.java
                        SocketConnectionCheckTestServer.java
  Log:
  JBREM-597 - changed to raw socket stream passed to marshaller and unmarshaller instead of being wrapped in object stream beforehand.
  
  Revision  Changes    Path
  1.5       +10 -4     JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/connection/SocketTestClient.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SocketTestClient.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/connection/SocketTestClient.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- SocketTestClient.java	21 May 2006 04:47:33 -0000	1.4
  +++ SocketTestClient.java	31 Oct 2006 04:37:53 -0000	1.5
  @@ -24,7 +24,6 @@
   import junit.framework.TestCase;
   import org.jboss.remoting.Client;
   import org.jboss.remoting.InvokerLocator;
  -import org.jboss.remoting.transport.socket.SocketServerInvoker;
   
   /**
    * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
  @@ -34,18 +33,25 @@
      // Default locator values
      private static String transport = "socket";
      private static String host = "localhost";
  +//   private static String host = "192.168.1.100";
      private static int port = 5400;
   
  +   private int numOfCalls = 10000;
  +//   private int numOfCalls = 2;
  +
      public void testInvocations() throws Throwable
      {
  +//      System.setProperty(Version.PRE_2_0_COMPATIBLE, "true");
  +
         Client remotingClient = null;
   
         try
         {
   
   
  -         String locatorURI = transport + "://" + host + ":" + port + "/?" + SocketServerInvoker.CHECK_CONNECTION_KEY + "=" + Boolean.TRUE;
  -         //String locatorURI = transport + "://" + host + ":" + port;
  +         //String locatorURI = transport + "://" + host + ":" + port + "/?" + SocketServerInvoker.CHECK_CONNECTION_KEY + "=" + Boolean.TRUE;
  +         //String locatorURI = transport + "://" + host + ":" + port + "/?" + InvokerLocator.SERIALIZATIONTYPE + "=jboss";
  +         String locatorURI = transport + "://" + host + ":" + port;
   
            // create InvokerLocator with the url type string
            // indicating the target remoting server to call upon.
  @@ -59,7 +65,7 @@
   
            long startTime = System.currentTimeMillis();
   
  -         int numOfCalls = 10000;
  +
            Object response = null;
            for(int x = 0; x < numOfCalls; x++)
            {
  
  
  
  1.4       +6 -3      JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/connection/SocketTestServer.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SocketTestServer.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/connection/SocketTestServer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- SocketTestServer.java	14 May 2006 05:29:58 -0000	1.3
  +++ SocketTestServer.java	31 Oct 2006 04:37:53 -0000	1.4
  @@ -28,7 +28,6 @@
   import org.jboss.remoting.ServerInvoker;
   import org.jboss.remoting.callback.InvokerCallbackHandler;
   import org.jboss.remoting.transport.Connector;
  -import org.jboss.remoting.transport.socket.SocketServerInvoker;
   
   import javax.management.MBeanServer;
   
  @@ -40,6 +39,7 @@
      // Default locator values
      private static String transport = "socket";
      private static String host = "localhost";
  +//   private static String host = "192.168.1.100";
      private static int port = 5400;
   
      private static int callCounter = 0;
  @@ -48,6 +48,8 @@
   
      public void setupServer(String locatorURI) throws Exception
      {
  +//      System.setProperty(Version.PRE_2_0_COMPATIBLE, "true");
  +
         // create the InvokerLocator based on url string format
         // to indicate the transport, host, and port to use for the
         // server invoker.
  @@ -79,8 +81,9 @@
   
      public void setUp() throws Exception
      {
  -      String locatorURI = transport + "://" + host + ":" + port + "/?" + SocketServerInvoker.CHECK_CONNECTION_KEY + "=" + Boolean.TRUE;
  -      //String locatorURI = transport + "://" + host + ":" + port;
  +      //String locatorURI = transport + "://" + host + ":" + port + "/?" + SocketServerInvoker.CHECK_CONNECTION_KEY + "=" + Boolean.TRUE;
  +      //String locatorURI = transport + "://" + host + ":" + port + "/?" + InvokerLocator.SERIALIZATIONTYPE + "=jboss";
  +      String locatorURI = transport + "://" + host + ":" + port;
         setupServer(locatorURI);
      }
   
  
  
  
  1.2       +83 -0     JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/connection/SocketConnectionCheckTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SocketConnectionCheckTestCase.java
  ===================================================================
  RCS file: SocketConnectionCheckTestCase.java
  diff -N SocketConnectionCheckTestCase.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ SocketConnectionCheckTestCase.java	31 Oct 2006 04:37:53 -0000	1.2
  @@ -0,0 +1,83 @@
  +/*
  +* JBoss, a division of Red Hat
  +* Copyright 2006, Red Hat Middleware, LLC, 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.socket.connection;
  +
  +import org.apache.log4j.Level;
  +import org.jboss.test.remoting.transport.InvokerTestDriver;
  +
  +/**
  + * @author <a href="mailto:tom at jboss.org">Tom Elrod</a>
  + */
  +public class SocketConnectionCheckTestCase extends InvokerTestDriver
  +{
  +   public void declareTestClasses()
  +   {
  +      addTestClasses(SocketConnectionCheckTestClient.class.getName(),
  +                     1,
  +                     SocketConnectionCheckTestServer.class.getName());
  +   }
  +
  +   protected Level getTestHarnessLogLevel()
  +   {
  +      return Level.DEBUG;
  +   }
  +
  +   protected Level getTestLogLevel()
  +   {
  +      return Level.DEBUG;
  +   }
  +
  +   /**
  +    * How long to wait for test results to be returned from the client(s).  If goes longer than the
  +    * specified limit, will throw an exception and kill the running test cases.  Default value is
  +    * RESULTS_TIMEOUT.
  +    *
  +    * @return
  +    */
  +   protected long getResultsTimeout()
  +   {
  +      return 600000;
  +   }
  +
  +   /**
  +    * How long for the server test case to wait for tear down message.  If exceeds timeout,
  +    * will throw exception.  The default value is TEARDOWN_TIMEOUT.
  +    *
  +    * @return
  +    */
  +   protected long getTearDownTimeout()
  +   {
  +      return 600000;
  +   }
  +
  +   /**
  +    * How long to allow each of the test cases to run their tests.  If exceeds this timeout
  +    * will throw exception and kill tests.  The default value is RUN_TEST_TIMEOUT.
  +    *
  +    * @return
  +    */
  +   protected long getRunTestTimeout()
  +   {
  +      return 600000;
  +   }
  +
  +}
  
  
  
  1.2       +95 -0     JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/connection/SocketConnectionCheckTestClient.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SocketConnectionCheckTestClient.java
  ===================================================================
  RCS file: SocketConnectionCheckTestClient.java
  diff -N SocketConnectionCheckTestClient.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ SocketConnectionCheckTestClient.java	31 Oct 2006 04:37:53 -0000	1.2
  @@ -0,0 +1,95 @@
  +package org.jboss.test.remoting.transport.socket.connection;
  +
  +import junit.framework.TestCase;
  +import org.jboss.remoting.Client;
  +import org.jboss.remoting.InvokerLocator;
  +import org.jboss.remoting.transport.socket.SocketServerInvoker;
  +
  +/**
  + * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
  + */
  +public class SocketConnectionCheckTestClient extends TestCase
  +{
  +   // Default locator values
  +   private static String transport = "socket";
  +   private static String host = "localhost";
  +   private static int port = 5400;
  +
  +   public void testInvocations() throws Throwable
  +   {
  +      Client remotingClient = null;
  +
  +      try
  +      {
  +
  +
  +         String locatorURI = transport + "://" + host + ":" + port + "/?" + SocketServerInvoker.CHECK_CONNECTION_KEY + "=" + Boolean.TRUE;
  +
  +         // create InvokerLocator with the url type string
  +         // indicating the target remoting server to call upon.
  +         InvokerLocator locator = new InvokerLocator(locatorURI);
  +         System.out.println("Calling remoting server with locator uri of: " + locatorURI);
  +
  +         remotingClient = new Client(locator);
  +         remotingClient.connect();
  +         String request = "Do something";
  +         System.out.println("Invoking server with request of '" + request + "'");
  +
  +         long startTime = System.currentTimeMillis();
  +
  +         int numOfCalls = 10000;
  +         Object response = null;
  +         for(int x = 0; x < numOfCalls; x++)
  +         {
  +            response = remotingClient.invoke(request);
  +            System.out.println("Invocation response: " + response);
  +         }
  +
  +         long endTime = System.currentTimeMillis();
  +         System.out.println("Time to make " + numOfCalls + " was " + (endTime -startTime) + " milliseconds.");
  +
  +         int callValue = 0;
  +         if(response instanceof Integer)
  +         {
  +            callValue = ((Integer) response).intValue();
  +         }
  +         assertEquals(numOfCalls, callValue);
  +
  +      }
  +      finally
  +      {
  +         if(remotingClient != null)
  +         {
  +            remotingClient.disconnect();
  +         }
  +      }
  +
  +   }
  +
  +   /**
  +    * Can pass transport and port to be used as parameters.
  +    * Valid transports are 'rmi' and 'socket'.
  +    *
  +    * @param args
  +    */
  +   public static void main(String[] args)
  +   {
  +      if(args != null && args.length == 3)
  +      {
  +         transport = args[0];
  +         host = args[1];
  +         port = Integer.parseInt(args[2]);
  +      }
  +      SocketConnectionCheckTestClient client = new SocketConnectionCheckTestClient();
  +      try
  +      {
  +         client.testInvocations();
  +      }
  +      catch(Throwable e)
  +      {
  +         e.printStackTrace();
  +      }
  +   }
  +
  +
  +}
  
  
  
  1.2       +164 -0    JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/connection/SocketConnectionCheckTestServer.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SocketConnectionCheckTestServer.java
  ===================================================================
  RCS file: SocketConnectionCheckTestServer.java
  diff -N SocketConnectionCheckTestServer.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ SocketConnectionCheckTestServer.java	31 Oct 2006 04:37:53 -0000	1.2
  @@ -0,0 +1,164 @@
  +package org.jboss.test.remoting.transport.socket.connection;
  +
  +import org.jboss.jrunit.extensions.ServerTestCase;
  +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.socket.SocketServerInvoker;
  +
  +import javax.management.MBeanServer;
  +
  +/**
  + * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
  + */
  +public class SocketConnectionCheckTestServer extends ServerTestCase
  +{
  +   // Default locator values
  +   private static String transport = "socket";
  +   private static String host = "localhost";
  +   private static int port = 5400;
  +
  +   private static int callCounter = 0;
  +
  +   private Connector connector = null;
  +
  +   public void setupServer(String locatorURI) throws Exception
  +   {
  +      // create the InvokerLocator based on url string format
  +      // to indicate the transport, host, and port to use for the
  +      // server invoker.
  +      InvokerLocator locator = new InvokerLocator(locatorURI);
  +      System.out.println("Starting remoting server with locator uri of: " + locatorURI);
  +      connector = new Connector(locator);
  +      // creates all the connector's needed resources, such as the server invoker
  +      connector.create();
  +
  +      // create the handler to receive the invocation request from the client for processing
  +      SampleInvocationHandler invocationHandler = new SampleInvocationHandler();
  +      // first parameter is sub-system name.  can be any String value.
  +      connector.addInvocationHandler("sample", invocationHandler);
  +
  +      // start with a new non daemon thread so
  +      // server will wait for request and not exit
  +      connector.start();
  +
  +   }
  +
  +   public void tearDown()
  +   {
  +      if(connector != null)
  +      {
  +         connector.stop();
  +         connector.destroy();
  +      }
  +   }
  +
  +   public void setUp() throws Exception
  +   {
  +      String locatorURI = transport + "://" + host + ":" + port + "/?" + SocketServerInvoker.CHECK_CONNECTION_KEY + "=" + Boolean.TRUE;
  +      setupServer(locatorURI);
  +   }
  +
  +   /**
  +    * Can pass transport and port to be used as parameters.
  +    * Valid transports are 'rmi' and 'socket'.
  +    *
  +    * @param args
  +    */
  +   public static void main(String[] args)
  +   {
  +      if(args != null && args.length == 3)
  +      {
  +         transport = args[0];
  +         host = args[1];
  +         port = Integer.parseInt(args[2]);
  +      }
  +      SocketConnectionCheckTestServer server = new SocketConnectionCheckTestServer();
  +      try
  +      {
  +         server.setUp();
  +
  +         // wait forever, let the user kill us at any point (at which point, the client will detect we went down)
  +         while(true)
  +         {
  +            Thread.sleep(1000);
  +         }
  +
  +      }
  +      catch(Exception e)
  +      {
  +         e.printStackTrace();
  +      }
  +   }
  +
  +   /**
  +    * Simple invocation handler implementation.
  +    * This is the code that will be called with the invocation payload from the client.
  +    */
  +   public static class SampleInvocationHandler implements ServerInvocationHandler
  +   {
  +      /**
  +       * called to handle a specific invocation
  +       *
  +       * @param invocation
  +       * @return
  +       * @throws Throwable
  +       */
  +      public Object invoke(InvocationRequest invocation) throws Throwable
  +      {
  +         // Print out the invocation request
  +         System.out.println("Invocation request is: " + invocation.getParameter());
  +         Integer resp = new Integer(++SocketConnectionCheckTestServer.callCounter);
  +         System.out.println("Returning response of: " + resp);
  +         // Just going to return static string as this is just simple example code.
  +         return resp;
  +      }
  +
  +      /**
  +       * Adds a callback handler that will listen for callbacks from
  +       * the server invoker handler.
  +       *
  +       * @param callbackHandler
  +       */
  +      public void addListener(InvokerCallbackHandler callbackHandler)
  +      {
  +         // NO OP as do not handling callback listeners in this example
  +      }
  +
  +      /**
  +       * Removes the callback handler that was listening for callbacks
  +       * from the server invoker handler.
  +       *
  +       * @param callbackHandler
  +       */
  +      public void removeListener(InvokerCallbackHandler callbackHandler)
  +      {
  +         // NO OP as do not handling callback listeners in this example
  +      }
  +
  +      /**
  +       * set the mbean server that the handler can reference
  +       *
  +       * @param server
  +       */
  +      public void setMBeanServer(MBeanServer server)
  +      {
  +         // NO OP as do not need reference to MBeanServer for this handler
  +      }
  +
  +      /**
  +       * set the invoker that owns this handler
  +       *
  +       * @param invoker
  +       */
  +      public void setInvoker(ServerInvoker invoker)
  +      {
  +         // NO OP as do not need reference back to the server invoker
  +      }
  +
  +   }
  +
  +}
  
  
  



More information about the jboss-cvs-commits mailing list