[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle ...
Tom Elrod
tom.elrod at jboss.com
Fri Nov 3 14:04:40 EST 2006
User: telrod
Date: 06/11/03 14:04:40
Added: src/tests/org/jboss/test/remoting/transport/socket/timeout/idle
InactiveIdleTimeoutTestCase.java
InactiveIdleTimeoutClientTest.java
InactiveIdleTimeoutTestServer.java
Log:
JBREM-607 - adding idle server thread cleanup for thread pool on server side.
Revision Changes Path
1.2 +48 -0 JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle/InactiveIdleTimeoutTestCase.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: InactiveIdleTimeoutTestCase.java
===================================================================
RCS file: InactiveIdleTimeoutTestCase.java
diff -N InactiveIdleTimeoutTestCase.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ InactiveIdleTimeoutTestCase.java 3 Nov 2006 19:04:40 -0000 1.2
@@ -0,0 +1,48 @@
+package org.jboss.test.remoting.transport.socket.timeout.idle;
+
+import org.jboss.jrunit.harness.TestDriver;
+
+public class InactiveIdleTimeoutTestCase extends TestDriver
+{
+ public void declareTestClasses()
+ {
+ addTestClasses(InactiveIdleTimeoutClientTest.class.getName(),
+ 1,
+ InactiveIdleTimeoutTestServer.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;
+ }
+
+}
1.2 +62 -0 JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle/InactiveIdleTimeoutClientTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: InactiveIdleTimeoutClientTest.java
===================================================================
RCS file: InactiveIdleTimeoutClientTest.java
diff -N InactiveIdleTimeoutClientTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ InactiveIdleTimeoutClientTest.java 3 Nov 2006 19:04:40 -0000 1.2
@@ -0,0 +1,62 @@
+package org.jboss.test.remoting.transport.socket.timeout.idle;
+
+import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
+import junit.framework.TestCase;
+import org.apache.log4j.Logger;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+
+/**
+ * @author <a href="mailto:telrod at e2technologies.net">Tom Elrod</a>
+ */
+public class InactiveIdleTimeoutClientTest 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
+ {
+ InactiveIdleTimeoutClientTest rt = new InactiveIdleTimeoutClientTest();
+// rt.runMultipleClients(Integer.parseInt(args[1]));
+ rt.runMultipleClients(numOfRunnerThreads);
+ }
+
+ public void testRunClients() throws Throwable
+ {
+ runMultipleClients(numOfRunnerThreads);
+ Thread.currentThread().sleep(60000);
+ }
+
+ 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();
+ }
+ }
+}
1.2 +82 -0 JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle/InactiveIdleTimeoutTestServer.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: InactiveIdleTimeoutTestServer.java
===================================================================
RCS file: InactiveIdleTimeoutTestServer.java
diff -N InactiveIdleTimeoutTestServer.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ InactiveIdleTimeoutTestServer.java 3 Nov 2006 19:04:40 -0000 1.2
@@ -0,0 +1,82 @@
+package org.jboss.test.remoting.transport.socket.timeout.idle;
+
+import org.apache.log4j.Logger;
+import org.jboss.jrunit.extensions.ServerTestCase;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+
+/**
+ * This is just like IdleTimeoutTestServer except instead of
+ * looking for server threads that are still in read mode waiting for
+ * data from client, want to test for idle server threads that finished with
+ * client/server connection and are just sitting in the thread pool waiting to
+ * be re-used.
+ *
+ * @author <a href="mailto:telrod at e2technologies.net">Tom Elrod</a>
+ */
+public class InactiveIdleTimeoutTestServer extends ServerTestCase
+{
+ private Connector connector;
+
+ private Logger logger = Logger.getRootLogger();
+
+ public static void main(String[] args) throws Throwable
+ {
+ InactiveIdleTimeoutTestServer rt = new InactiveIdleTimeoutTestServer();
+ rt.setUp();
+ Thread.currentThread().sleep(45000);
+ rt.tearDown();
+
+ }
+
+ public void setUp() throws Exception
+ {
+ startServer();
+ }
+
+ public void tearDown() throws Exception
+ {
+ if(connector != null)
+ {
+ try
+ {
+ // check for empty thread pool
+ SocketServerInvoker svrInvoker = (SocketServerInvoker)connector.getServerInvoker();
+ int threadPoolSize = svrInvoker.getCurrentThreadPoolSize();
+ if(threadPoolSize > 0)
+ {
+ System.out.println("Error - thread pool should be size of 0, but is " + threadPoolSize);
+ throw new RuntimeException("Thread pool was not size of 0, but " + threadPoolSize);
+ }
+ else
+ {
+ System.out.println("Pass - thread pool size is 0");
+ }
+
+ }
+ finally
+ {
+ 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=10000&idleTimeout=15";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+
+ connector = new Connector();
+
+ connector.setInvokerLocator(locator.getLocatorURI());
+ connector.create();
+
+ SampleInvocationHandler invocationHandler = new SampleInvocationHandler();
+ connector.addInvocationHandler("sample", invocationHandler);
+ connector.start();
+ }
+
+}
More information about the jboss-cvs-commits
mailing list