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

Ovidiu Feodorov ovidiu.feodorov at jboss.com
Sat Jan 13 07:42:36 EST 2007


  User: ovidiu  
  Date: 07/01/13 07:42:36

  Added:       src/tests/org/jboss/test/remoting/transport/socket/serverlockup    
                        Tag: remoting_2_x ServerLockupClientTest.java
                        ServerLockupServerTest.java
                        ServerLockupTestDriver.java
                        SimpleServerInvocationHandler.java
  Log:
  Various logging improvments, minor reformatting and new tests in preparation 
  for a solution for http://jira.jboss.org/jira/browse/JBREM-666.
  
  Includes http://jira.jboss.org/jira/browse/JBREM-667.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +165 -0    JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/serverlockup/Attic/ServerLockupClientTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ServerLockupClientTest.java
  ===================================================================
  RCS file: ServerLockupClientTest.java
  diff -N ServerLockupClientTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ServerLockupClientTest.java	13 Jan 2007 12:42:36 -0000	1.1.2.1
  @@ -0,0 +1,165 @@
  +/**
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +package org.jboss.test.remoting.transport.socket.serverlockup;
  +
  +import junit.framework.TestCase;
  +import org.jboss.remoting.InvokerLocator;
  +import org.jboss.remoting.ServerInvocationHandler;
  +import org.jboss.remoting.Client;
  +import org.jboss.remoting.invocation.NameBasedInvocation;
  +import org.jboss.remoting.transport.Connector;
  +import org.jboss.test.remoting.TestUtil;
  +import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
  +import org.jboss.logging.Logger;
  +
  +import java.net.BindException;
  +
  +/**
  + * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  + */
  +public class ServerLockupClientTest extends TestCase
  +{
  +   // Constants ------------------------------------------------------------------------------------
  +
  +   private static final Logger log = Logger.getLogger(ServerLockupClientTest.class);
  +
  +   // Static ---------------------------------------------------------------------------------------
  +
  +   public static void main(String[] args)
  +   {
  +      ServerLockupClientTest client = new ServerLockupClientTest();
  +
  +      try
  +      {
  +         client.setUp();
  +         client.testSimplePing();
  +         client.tearDown();
  +      }
  +      catch (Throwable throwable)
  +      {
  +         throwable.printStackTrace();
  +      }
  +   }
  +
  +   // Attributes -----------------------------------------------------------------------------------
  +
  +   private int port = 9091;
  +   private int callbackPort = -1;
  +
  +   private Client client;
  +
  +   // Constructors ---------------------------------------------------------------------------------
  +
  +   // Public ---------------------------------------------------------------------------------------
  +
  +   public void testSimplePing() throws Throwable
  +   {
  +      log.debug("test simple ping");
  +      Object ret = client.invoke(new NameBasedInvocation("ping",
  +                                                         new Object[] {"hello"},
  +                                                         new String[] {"java.lang.String"}));
  +      assertEquals("pong.hello", ret);
  +
  +   }
  +
  +   // Package protected ----------------------------------------------------------------------------
  +
  +   // Protected ------------------------------------------------------------------------------------
  +
  +   protected String getTransport()
  +   {
  +      return "socket";
  +   }
  +
  +   protected String getSubsystem()
  +   {
  +      return "mock";
  +   }
  +
  +   protected ServerInvocationHandler getServerInvocationHandler()
  +   {
  +      return new MockServerInvocationHandler();
  +   }
  +
  +   protected void setUp() throws Exception
  +   {
  +//      BasicConfigurator.configure();
  +//      Category.getRoot().setLevel(Level.INFO);
  +
  +      // This is a retry hack because in some cases, can get duplicate callback server ports when
  +      // trying to find a free one.
  +
  +      int retryLimit = 3;
  +      for(int x = 0; x < retryLimit; x++)
  +      {
  +         try
  +         {
  +            initServer(callbackPort);
  +         }
  +         catch(BindException e)
  +         {
  +            if(x + 1 == retryLimit)
  +            {
  +               throw e;
  +            }
  +            else
  +            {
  +               continue;
  +            }
  +         }
  +         break;
  +      }
  +
  +      initClient();
  +   }
  +
  +   protected void tearDown() throws Exception
  +   {
  +   }
  +
  +   // Private --------------------------------------------------------------------------------------
  +
  +   private InvokerLocator initServer(int port) throws Exception
  +   {
  +      if(port < 0)
  +      {
  +         port = TestUtil.getRandomPort();
  +      }
  +
  +      log.debug("server port " + port);
  +
  +      Connector connector = new Connector();
  +
  +      InvokerLocator locator = new InvokerLocator(getTransport() + "://localhost:" + port);
  +
  +      connector.setInvokerLocator(locator.getLocatorURI());
  +      connector.create();
  +      connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler());
  +      connector.start();
  +
  +      return locator;
  +   }
  +
  +   private void initClient()
  +   {
  +      try
  +      {
  +         String locatorURI = getTransport() + "://localhost:" + port;
  +         InvokerLocator locator = new InvokerLocator(locatorURI);
  +
  +         client = new Client(locator, "mock");
  +         client.connect();
  +      }
  +      catch(Exception e)
  +      {
  +         log.error(e.getMessage(), e);
  +      }
  +   }
  +
  +   // Inner classes --------------------------------------------------------------------------------
  +
  +}
  
  
  
  1.1.2.1   +120 -0    JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/serverlockup/Attic/ServerLockupServerTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ServerLockupServerTest.java
  ===================================================================
  RCS file: ServerLockupServerTest.java
  diff -N ServerLockupServerTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ServerLockupServerTest.java	13 Jan 2007 12:42:36 -0000	1.1.2.1
  @@ -0,0 +1,120 @@
  +/**
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +package org.jboss.test.remoting.transport.socket.serverlockup;
  +
  +import org.jboss.jrunit.extensions.ServerTestCase;
  +import org.jboss.test.remoting.TestUtil;
  +import org.jboss.logging.Logger;
  +import org.jboss.remoting.transport.Connector;
  +import org.jboss.remoting.InvokerLocator;
  +import org.jboss.remoting.ServerInvocationHandler;
  +import org.apache.log4j.Level;
  +import org.apache.log4j.BasicConfigurator;
  +import org.apache.log4j.Category;
  +
  +/**
  + * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  + */
  +public class ServerLockupServerTest extends ServerTestCase
  +{
  +   // Constants ------------------------------------------------------------------------------------
  +
  +   private static final Logger log = Logger.getLogger(ServerLockupServerTest.class);
  +
  +   // Static ---------------------------------------------------------------------------------------
  +
  +   public static void main(String[] args)
  +   {
  +      BasicConfigurator.configure();
  +      Category.getRoot().setLevel(Level.INFO);
  +      Category.getInstance("org.jboss.remoting.transport.socket").setLevel(Level.DEBUG);
  +      Category.getInstance("org.jboss.test.remoting").setLevel(Level.DEBUG);
  +      Category.getInstance("org.jgroups").setLevel(Level.FATAL);
  +
  +      ServerLockupServerTest server = new ServerLockupServerTest();
  +
  +      try
  +      {
  +         server.setUp();
  +         Thread.sleep(300000);
  +         server.tearDown();
  +         System.out.println("Have torn down test.");
  +         Thread.sleep(30000);
  +      }
  +      catch(Exception e)
  +      {
  +         e.printStackTrace();
  +      }
  +   }
  +
  +   // Attributes -----------------------------------------------------------------------------------
  +
  +   private int serverPort = 9091;  // default port
  +
  +   private Connector connector;
  +
  +   // Constructors ---------------------------------------------------------------------------------
  +
  +   // Public ---------------------------------------------------------------------------------------
  +
  +   public String getTransport()
  +   {
  +      return "socket";
  +   }
  +
  +   // Package protected ----------------------------------------------------------------------------
  +
  +   // Protected ------------------------------------------------------------------------------------
  +
  +   protected String getSubsystem()
  +   {
  +      return "mock";
  +   }
  +
  +   protected ServerInvocationHandler getServerInvocationHandler()
  +   {
  +      return new SimpleServerInvocationHandler();
  +   }
  +
  +   protected void setUp() throws Exception
  +   {
  +      if(serverPort < 0)
  +      {
  +         serverPort = TestUtil.getRandomPort();
  +      }
  +
  +      log.debug("port = " + serverPort);
  +
  +      connector = new Connector();
  +      InvokerLocator locator = new InvokerLocator(getTransport() + "://localhost:" + serverPort);
  +      connector.setInvokerLocator(locator.getLocatorURI());
  +      connector.create();
  +      connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler());
  +      connector.start();
  +   }
  +
  +   protected void tearDown() throws Exception
  +   {
  +      if(connector != null)
  +      {
  +         connector.stop();
  +         connector.destroy();
  +      }
  +   }
  +
  +   // Private --------------------------------------------------------------------------------------
  +
  +   // Inner classes --------------------------------------------------------------------------------
  +
  +}
  +
  +
  +
  +
  +
  +
  +
  
  
  
  1.1.2.1   +120 -0    JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/serverlockup/Attic/ServerLockupTestDriver.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ServerLockupTestDriver.java
  ===================================================================
  RCS file: ServerLockupTestDriver.java
  diff -N ServerLockupTestDriver.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ ServerLockupTestDriver.java	13 Jan 2007 12:42:36 -0000	1.1.2.1
  @@ -0,0 +1,120 @@
  +/**
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +package org.jboss.test.remoting.transport.socket.serverlockup;
  +
  +import org.jboss.jrunit.harness.TestDriver;
  +import org.jboss.logging.XLevel;
  +import org.apache.log4j.Level;
  +
  +/**
  + * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  + */
  +public class ServerLockupTestDriver extends TestDriver
  +{
  +   // Constants ------------------------------------------------------------------------------------
  +
  +   public static final String REMOTING_METADATA = "remoting.metadata";
  +   public static final String JVM_MAX_HEAP_SIZE = "jvm.mx";
  +
  +   // Static ---------------------------------------------------------------------------------------
  +
  +   // Attributes -----------------------------------------------------------------------------------
  +
  +   // Constructors ---------------------------------------------------------------------------------
  +
  +   // TestDriver overrides -------------------------------------------------------------------------
  +
  +   public void declareTestClasses()
  +   {
  +      addTestClasses(ServerLockupClientTest.class.getName(), 1,
  +                     ServerLockupServerTest.class.getName());
  +   }
  +
  +   protected Level getTestLogLevel()
  +   {
  +      return XLevel.TRACE;
  +   }
  +
  +   protected Level getTestHarnessLogLevel()
  +   {
  +      return Level.INFO;
  +   }
  +
  +   /**
  +    * 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.
  +    */
  +   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.
  +    */
  +   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.
  +    */
  +   protected long getRunTestTimeout()
  +   {
  +      return 600000;
  +   }
  +
  +   protected String getClientJVMArguments()
  +   {
  +      String clientJVMArguments = "";
  +
  +      if (Boolean.getBoolean("clientdebug"))
  +      {
  +         clientJVMArguments +=
  +            "-Xdebug -Xnoagent -Djava.compiler=NONE " +
  +            "-Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=client";
  +      }
  +
  +      return clientJVMArguments;
  +   }
  +
  +   /**
  +    * Returns the VM arguments to be passed to the VM when creating the server test cases (actually
  +    * their harness). The default value is null.
  +    */
  +   protected String getServerJVMArguments()
  +   {
  +      String serverJVMArguments = "";
  +
  +      if (Boolean.getBoolean("serverdebug"))
  +      {
  +         serverJVMArguments +=
  +            "-Xdebug -Xnoagent -Djava.compiler=NONE " +
  +            "-Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=server";
  +      }
  +
  +      return serverJVMArguments;
  +   }
  +
  +
  +   // Public ---------------------------------------------------------------------------------------
  +
  +   // Package protected ----------------------------------------------------------------------------
  +
  +   // Protected ------------------------------------------------------------------------------------
  +
  +   // Private --------------------------------------------------------------------------------------
  +
  +   // Inner classes --------------------------------------------------------------------------------
  +
  +}
  +
  +
  
  
  
  1.1.2.1   +78 -0     JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/serverlockup/Attic/SimpleServerInvocationHandler.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SimpleServerInvocationHandler.java
  ===================================================================
  RCS file: SimpleServerInvocationHandler.java
  diff -N SimpleServerInvocationHandler.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ SimpleServerInvocationHandler.java	13 Jan 2007 12:42:36 -0000	1.1.2.1
  @@ -0,0 +1,78 @@
  +/**
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +package org.jboss.test.remoting.transport.socket.serverlockup;
  +
  +import org.jboss.remoting.ServerInvocationHandler;
  +import org.jboss.remoting.ServerInvoker;
  +import org.jboss.remoting.InvocationRequest;
  +import org.jboss.remoting.invocation.NameBasedInvocation;
  +import org.jboss.remoting.callback.InvokerCallbackHandler;
  +import org.jboss.logging.Logger;
  +
  +import javax.management.MBeanServer;
  +
  +/**
  + * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  + * @version <tt>$Revision: 1.1.2.1 $</tt>
  + *
  + * $Id: SimpleServerInvocationHandler.java,v 1.1.2.1 2007/01/13 12:42:36 ovidiu Exp $
  + */
  +public class SimpleServerInvocationHandler implements ServerInvocationHandler
  +{
  +   // Constants ------------------------------------------------------------------------------------
  +
  +   private static final Logger log = Logger.getLogger(SimpleServerInvocationHandler.class);
  +
  +   // Static ---------------------------------------------------------------------------------------
  +
  +   // Attributes -----------------------------------------------------------------------------------
  +
  +   // Constructors ---------------------------------------------------------------------------------
  +
  +   // ServerInvocationHandler implementation -------------------------------------------------------
  +
  +   public void setMBeanServer(MBeanServer server)
  +   {
  +   }
  +
  +   public void setInvoker(ServerInvoker invoker)
  +   {
  +   }
  +
  +   public Object invoke(InvocationRequest invocation) throws Throwable
  +   {
  +      NameBasedInvocation nbi = (NameBasedInvocation)invocation.getParameter();
  +
  +      String methodName = nbi.getMethodName();
  +
  +      if ("ping".equals(methodName))
  +      {
  +         return "pong." + nbi.getParameters()[0];
  +      }
  +
  +      return null;
  +   }
  +
  +   public void addListener(InvokerCallbackHandler callbackHandler)
  +   {
  +   }
  +
  +   public void removeListener(InvokerCallbackHandler callbackHandler)
  +   {
  +   }
  +
  +   // Public ---------------------------------------------------------------------------------------
  +
  +   // Package protected ----------------------------------------------------------------------------
  +
  +   // Protected ------------------------------------------------------------------------------------
  +
  +   // Private --------------------------------------------------------------------------------------
  +
  +   // Inner classes --------------------------------------------------------------------------------
  +
  +}
  
  
  



More information about the jboss-cvs-commits mailing list