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

Tom Elrod tom.elrod at jboss.com
Fri Nov 3 10:56:32 EST 2006


  User: telrod  
  Date: 06/11/03 10:56:32

  Added:       src/tests/org/jboss/test/remoting/transport/socket/timeout/idle   
                        Tag: remoting_2_x IdleTimeoutTestCase.java
                        IdleTimeoutTestServer.java
                        IdleTimeoutClientTest.java
  Log:
  JBREM-607 - adding idle timeout for server threads
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +48 -0     JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle/Attic/IdleTimeoutTestCase.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: IdleTimeoutTestCase.java
  ===================================================================
  RCS file: IdleTimeoutTestCase.java
  diff -N IdleTimeoutTestCase.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ IdleTimeoutTestCase.java	3 Nov 2006 15:56:31 -0000	1.1.2.1
  @@ -0,0 +1,48 @@
  +package org.jboss.test.remoting.transport.socket.timeout.idle;
  +
  +import org.jboss.jrunit.harness.TestDriver;
  +
  +public class IdleTimeoutTestCase extends TestDriver
  +{
  +   public void declareTestClasses()
  +   {
  +      addTestClasses(IdleTimeoutClientTest.class.getName(),
  +                     2,
  +                     IdleTimeoutTestServer.class.getName());
  +   }
  +
  +   /**
  +    * 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 360000;
  +   }
  +
  +   /**
  +    * 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 360000;
  +   }
  +
  +   /**
  +    * 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 360000;
  +   }
  +
  +}
  \ No newline at end of file
  
  
  
  1.1.2.1   +56 -0     JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle/Attic/IdleTimeoutTestServer.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: IdleTimeoutTestServer.java
  ===================================================================
  RCS file: IdleTimeoutTestServer.java
  diff -N IdleTimeoutTestServer.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ IdleTimeoutTestServer.java	3 Nov 2006 15:56:31 -0000	1.1.2.1
  @@ -0,0 +1,56 @@
  +package org.jboss.test.remoting.transport.socket.timeout.idle;
  +
  +import org.jboss.jrunit.extensions.ServerTestCase;
  +import org.jboss.remoting.transport.Connector;
  +import org.jboss.remoting.InvokerLocator;
  +import org.jboss.remoting.Client;
  +import org.apache.log4j.Logger;
  +import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
  +
  +/**
  + * @author <a href="mailto:telrod at e2technologies.net">Tom Elrod</a>
  + */
  +public class IdleTimeoutTestServer extends ServerTestCase
  +{
  +   private Connector connector;
  +
  +   private Logger logger = Logger.getRootLogger();
  +
  +   public static void main(String[] args) throws Throwable
  +   {
  +      IdleTimeoutTestServer rt = new IdleTimeoutTestServer();
  +      rt.startServer();
  +   }
  +
  +   public void setUp() throws Exception
  +   {
  +      startServer();
  +   }
  +
  +   public void tearDown() throws Exception
  +   {
  +      if(connector != null)
  +      {
  +         connector.stop();
  +         connector.destroy();
  +      }
  +   }
  +
  +   public void startServer() throws Exception
  +   {
  +//      String locatorURI = "socket://localhost:54000/?maxPoolSize=2&timeout=60000&backlog=0";
  +      String locatorURI = "socket://localhost:54000/?maxPoolSize=2&backlog=0&timeout=60000&idleTimeout=5";
  +      InvokerLocator locator = new InvokerLocator(locatorURI);
  +
  +      connector = new Connector();
  +
  +      connector.setInvokerLocator(locator.getLocatorURI());
  +      connector.create();
  +
  +      SampleInvocationHandler invocationHandler = new SampleInvocationHandler();
  +      connector.addInvocationHandler("sample", invocationHandler);
  +      connector.start();
  +   }
  +
  +}
  +
  
  
  
  1.1.2.1   +84 -0     JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle/Attic/IdleTimeoutClientTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: IdleTimeoutClientTest.java
  ===================================================================
  RCS file: IdleTimeoutClientTest.java
  diff -N IdleTimeoutClientTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ IdleTimeoutClientTest.java	3 Nov 2006 15:56:31 -0000	1.1.2.1
  @@ -0,0 +1,84 @@
  +package org.jboss.test.remoting.transport.socket.timeout.idle;
  +
  +import junit.framework.TestCase;
  +import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
  +import org.jboss.remoting.transport.Connector;
  +import org.jboss.remoting.InvokerLocator;
  +import org.jboss.remoting.Client;
  +import org.apache.log4j.Logger;
  +
  +/**
  + * @author <a href="mailto:telrod at e2technologies.net">Tom Elrod</a>
  + */
  +public class IdleTimeoutClientTest extends TestCase
  +{
  +
  +//   private static int numOfRunnerThreads = 10;
  +   private static int numOfRunnerThreads = 2;
  +   private static SynchronizedInt responseCount = new SynchronizedInt(0);
  +
  +   private Logger logger = Logger.getRootLogger();
  +
  +   public static void main(String[] args) throws Throwable
  +   {
  +      IdleTimeoutClientTest rt = new IdleTimeoutClientTest();
  +//      rt.runMultipleClients(Integer.parseInt(args[1]));
  +      rt.runMultipleClients(numOfRunnerThreads);
  +   }
  +
  +   public void testRunClients() throws Throwable
  +   {
  +      String locatorURI = "socket://localhost:54000/?clientMaxPoolSize=50&timeout=10000";
  +      InvokerLocator locator = new InvokerLocator(locatorURI);
  +      Client client = new Client(locator);
  +      client.connect();
  +      Object resp = client.invoke(Boolean.TRUE);
  +      Boolean isFirst = (Boolean)resp;
  +      System.out.println("client is first = " + isFirst);
  +
  +      Thread.currentThread().sleep(10000);
  +
  +      if(isFirst.booleanValue())
  +      {
  +          Thread.currentThread().sleep(10000);
  +      }
  +
  +      runMultipleClients(numOfRunnerThreads);
  +      Thread.currentThread().sleep(30000);
  +      System.out.println("done with first timeout.");
  +      runMultipleClients(numOfRunnerThreads);
  +      Thread.currentThread().sleep(12000);
  +
  +      System.out.println("response count = " + responseCount.get());
  +      assertEquals(4, responseCount.get());
  +   }
  +
  +   public void runClient(String clientId) throws Throwable
  +   {
  +      String locatorURI = "socket://localhost:54000/?clientMaxPoolSize=50&timeout=10000";
  +      InvokerLocator locator = new InvokerLocator(locatorURI);
  +      Client client = new Client(locator);
  +      client.connect();
  +      String req = clientId;
  +      Object resp = client.invoke(req);
  +      responseCount.increment();
  +      System.out.println("Received response of: " + resp + ".  Response count = " + responseCount);
  +   }
  +
  +      public void runMultipleClients(int cnt) throws Throwable {
  +      for (int i = 0; i < cnt; i++) {
  +         Thread t = new Thread(new Runnable() {
  +            public void run() {
  +               try {
  +                  Thread.sleep(1000);
  +                  runClient(Thread.currentThread().getName());
  +               } catch (Throwable e) {
  +                  logger.error(e);
  +                  e.printStackTrace();
  +               }
  +            }
  +         }, Integer.toString(i));
  +         t.start();
  +      }
  +   }
  +}
  
  
  



More information about the jboss-cvs-commits mailing list