[jboss-remoting-commits] JBoss Remoting SVN: r5226 - in remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning: lease and 1 other directory.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Thu May 14 23:24:45 EDT 2009


Author: ron.sigal at jboss.com
Date: 2009-05-14 23:24:45 -0400 (Thu, 14 May 2009)
New Revision: 5226

Added:
   remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/
   remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestCase.java
   remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestClient.java
   remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestServer.java
Log:
JBREM-1133, JBREM-1134: New unit tests for versioning test suite.

Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestCase.java	                        (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestCase.java	2009-05-15 03:24:45 UTC (rev 5226)
@@ -0,0 +1,133 @@
+package org.jboss.test.remoting.versioning.lease;
+
+import org.apache.log4j.Level;
+import org.jboss.test.remoting.transport.InvokerTestDriver;
+
+/**
+ * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
+ */
+public class LeaseVersionTestCase extends InvokerTestDriver
+{
+   public void declareTestClasses()
+   {
+      addTestClasses("org.jboss.test.remoting.versioning.lease.LeaseVersionTestClient",
+                     1,
+                     "org.jboss.test.remoting.versioning.lease.LeaseVersionTestServer");
+   }
+   
+   /**
+    * Returns the classpath to be added to the classpath used to start the client tests.
+    * Default return is null, which means no extra classpath will be added.
+    *
+    * @return
+    */
+   protected String getExtendedServerClasspath()
+   {
+      return System.getProperty("server.path");
+   }
+
+   /**
+    * Returns the classpath to be added to the classpath used to start the client tests.
+    * Default return is null, which means no extra classpath will be added.
+    *
+    * @return
+    */
+   protected String getExtendedClientClasspath()
+   {
+      return System.getProperty("client.path");
+   }
+   
+   protected String getClientJVMArguments()
+   {
+      String prop = System.getProperty("client.pre_2_0_compatible");
+      String args = "";
+      if (prop != null && !"".equals(prop))
+      {
+         args = "-Djboss.remoting.pre_2_0_compatible=" + prop;
+      }
+      else
+      {
+         prop = System.getProperty("client.version");
+         if (prop != null && !"".equals(prop))
+            args = "-Djboss.remoting.version=" + prop;
+      }
+      prop = System.getProperty("client.check_connection");
+      if (prop != null && !"".equals(prop))
+      {
+         args += " -Dremoting.metadata=socket.check_connection=" + prop;
+      }
+      System.out.println("client arg: " + args);
+      return args;
+   }
+
+
+   protected String getServerJVMArguments()
+   {
+      String prop = System.getProperty("server.pre_2_0_compatible");
+      String args = "";
+      if (prop != null && !"".equals(prop))
+      {
+         args = "-Djboss.remoting.pre_2_0_compatible=" + prop;
+      }
+      else
+      {
+         prop = System.getProperty("server.version");
+         if (prop != null && !"".equals(prop))
+            args = "-Djboss.remoting.version=" + prop;
+      }
+      prop = System.getProperty("server.check_connection");
+      if (prop != null && !"".equals(prop))
+      {
+         args += " -Dremoting.metadata=socket.check_connection=" + prop;
+      }
+      System.out.println("server arg: " + args);
+      return args;
+   }
+   
+
+   protected Level getTestHarnessLogLevel()
+   {
+      return Level.INFO;
+   }
+
+   protected Level getTestLogLevel()
+   {
+      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.
+    *
+    * @return
+    */
+   protected long getResultsTimeout()
+   {
+      return 60000;
+   }
+
+   /**
+    * 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 60000;
+   }
+
+   /**
+    * 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 60000;
+   }
+
+
+}

Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestClient.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestClient.java	                        (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestClient.java	2009-05-15 03:24:45 UTC (rev 5226)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.versioning.lease;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+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.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ClientDisconnectedException;
+import org.jboss.remoting.InvokerLocator;
+
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 08, 2009
+ * </p>
+ */
+public class LeaseVersionTestClient extends TestCase
+{
+   private static Logger log = Logger.getLogger(LeaseVersionTestClient.class);
+   
+   protected static long LEASE_PERIOD = 2000;
+   protected static String LEASE_PERIOD_STRING = "2000";
+   
+   private static boolean firstTime = true;
+
+   
+   public void setUp() throws Exception
+   {
+      if (firstTime)
+      {
+         firstTime = false;
+         Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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()
+   {
+   }
+   
+   
+   public void testLease() throws Throwable
+   {
+      log.info("entering " + getName());
+      
+      // Create client.
+      InvokerLocator clientLocator = new InvokerLocator(createLocatorURI());
+      HashMap clientConfig = new HashMap();
+      clientConfig.put(Client.ENABLE_LEASE, "true");
+      addExtraClientConfig(clientConfig);
+      Client client = new Client(clientLocator, clientConfig);
+      client.connect();
+      log.info("client is connected");
+      
+      // Test connection.
+      assertEquals("abc", client.invoke("abc"));
+      log.info("connection is good");
+      
+      // Test lease behavior.
+      client.disconnect();
+      client.connect();
+      Map info = (Map) client.invoke(LeaseVersionTestServer.GET_LISTENER_INFO);
+      log.info("listener info: " + info);
+      assertEquals(1, ((Integer)info.get(LeaseVersionTestServer.LISTENER_COUNT)).intValue());
+      assertTrue(info.get(LeaseVersionTestServer.THROWABLE) instanceof ClientDisconnectedException);
+      client.disconnect();
+      
+      log.info(getName() + " PASSES");
+   }
+   
+   
+   protected String getTransport()
+   {
+      return "socket";
+   }
+   
+   
+   protected void addExtraClientConfig(Map config) {}
+   
+   
+   protected String createLocatorURI() throws UnknownHostException
+   {
+      String locatorURI = getTransport() + "://" + InetAddress.getLocalHost().getHostAddress() + ":" + LeaseVersionTestServer.PORT;
+      String metadata = System.getProperty("remoting.metadata");
+      if (metadata != null)
+      {
+         locatorURI += "/?" + metadata;
+      }
+      return locatorURI;
+   }
+}
\ No newline at end of file

Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestServer.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestServer.java	                        (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestServer.java	2009-05-15 03:24:45 UTC (rev 5226)
@@ -0,0 +1,190 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.versioning.lease;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.jrunit.extensions.ServerTestCase;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+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;
+
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 08, 2009
+ * </p>
+ */
+public class LeaseVersionTestServer extends ServerTestCase
+{
+   public static final String REMOTING_METADATA = "remoting.metadata";
+   public static final String JVM_MAX_HEAP_SIZE = "jvm.mx";
+   public static final String GET_LISTENER_INFO = "getListenerCount";
+   public static final String LISTENER_COUNT = "listenerCount";
+   public static final String THROWABLE = "throwable";
+   public static final String PORT = "9091";
+   
+   private static Logger log = Logger.getLogger(LeaseVersionTestServer.class);
+   
+   protected static long LEASE_PERIOD = 2000;
+   protected static String LEASE_PERIOD_STRING = "2000";
+   
+   protected Connector connector;
+   protected TestConnectionListener listener;
+   
+   
+   public static void main(String[] args)
+   {
+      try
+      {
+         LeaseVersionTestServer p = new LeaseVersionTestServer();
+         p.setUp();
+         Thread.sleep(3000000);
+         p.tearDown();
+      }
+      catch (Exception e)
+      {
+         log.error("Error", e);
+      }
+   }
+   
+   
+   public void setUp() throws Exception
+   {
+      Logger.getLogger("org.jboss.remoting").setLevel(XLevel.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);  
+      setupServer();
+   }
+   
+   
+   public void tearDown()
+   {
+      if(connector != null)
+      {
+         connector.stop();
+         connector.destroy();
+      }
+   }
+   
+   
+   protected String getTransport()
+   {
+      return "socket";
+   }
+   
+   
+   protected void addExtraServerConfig(Map config) {}
+   
+   
+   protected void setupServer() throws Exception
+   {
+      String locatorURI = createLocatorURI();
+      String metadata = System.getProperty("remoting.metadata");
+      if (metadata != null)
+      {
+         locatorURI += "/?" + metadata;
+      }
+      InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+      log.info("Starting remoting server with locator uri of: " + locatorURI);
+      HashMap config = new HashMap();
+      config.put("leasePeriod", LEASE_PERIOD_STRING);
+      addExtraServerConfig(config);
+      connector = new Connector(serverLocator, config);
+      connector.create();
+      ServerInvocationHandler invocationHandler = new TestInvocationHandler();
+      connector.addInvocationHandler("test", invocationHandler);
+      connector.start();
+      listener = new TestConnectionListener();
+      connector.addConnectionListener(listener);
+   }
+   
+   
+   protected String createLocatorURI() throws UnknownHostException
+   {
+      String locatorURI = getTransport() + "://" + InetAddress.getLocalHost().getHostAddress() + ":" + PORT;
+      String metadata = System.getProperty("remoting.metadata");
+      if (metadata != null)
+      {
+         locatorURI += "/?" + metadata;
+      }
+      return locatorURI;
+   }
+   
+   
+   class TestInvocationHandler implements ServerInvocationHandler
+   {
+      public void addListener(InvokerCallbackHandler callbackHandler) {}
+      public Object invoke(final InvocationRequest invocation) throws Throwable
+      {
+         Object o = invocation.getParameter();
+         if (GET_LISTENER_INFO.equals(o))
+         {
+            HashMap map = new HashMap();
+            map.put(LISTENER_COUNT, new Integer(listener.counter));
+            map.put(THROWABLE, listener.throwable);
+            listener.counter = 0;
+            listener.throwable = null;
+            return map;
+         }
+         return o;
+      }
+      public void removeListener(InvokerCallbackHandler callbackHandler) {}
+      public void setMBeanServer(MBeanServer server) {}
+      public void setInvoker(ServerInvoker invoker) {}
+   }
+   
+
+   static class TestConnectionListener implements ConnectionListener
+   {
+      public int counter;
+      public Throwable throwable;
+      
+      public void handleConnectionException(Throwable throwable, Client client)
+      {
+         counter++;
+         this.throwable = throwable;
+         log.info("called: throwable = " + throwable);
+      }  
+   }
+}
\ No newline at end of file




More information about the jboss-remoting-commits mailing list