You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2008/03/26 16:36:32 UTC
svn commit: r641351 - in
/geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src:
main/java/org/apache/geronimo/concurrent/test/
test/java/org/apache/geronimo/concurrent/test/
Author: gawor
Date: Wed Mar 26 08:36:30 2008
New Revision: 641351
URL: http://svn.apache.org/viewvc?rev=641351&view=rev
Log:
test for right exceptions raised by server-managed executor services
Modified:
geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedExecutorServiceServlet.java
geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedScheduledExecutorServiceServlet.java
geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedExecutorServiceTest.java
geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedScheduledExecutorServiceTest.java
Modified: geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedExecutorServiceServlet.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedExecutorServiceServlet.java?rev=641351&r1=641350&r2=641351&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedExecutorServiceServlet.java (original)
+++ geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedExecutorServiceServlet.java Wed Mar 26 08:36:30 2008
@@ -19,7 +19,10 @@
package org.apache.geronimo.concurrent.test;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import javax.servlet.http.HttpServlet;
@@ -29,6 +32,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.testng.Assert;
public class ManagedExecutorServiceServlet extends HttpServlet {
@@ -44,25 +48,43 @@
System.out.println(executorService);
String testName = (String)request.getParameter("testName");
- String id = (String)request.getParameter("id");
- System.out.println(testName + " " + id);
+ System.out.println(testName);
- try {
- testManagedExecutorService(id);
- } catch (Exception e) {
- LOG.error("Test failed: " + e.getMessage(), e);
- e.printStackTrace(response.getWriter());
+ if (!testName.startsWith("test")) {
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Invalid test name");
+ }
+
+ try {
+ Method method = getClass().getMethod(testName, new Class [] {});
+ method.invoke(this, new Object [] {});
+ } catch (NoSuchMethodException e) {
+ LOG.error("No such test: " + testName);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No such test");
+ } catch (IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ Throwable ex = e.getTargetException();
+ LOG.error("Test " + testName + " failed", ex);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Test failed");
- }
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
- private void testManagedExecutorService(String id) throws Exception {
- if ("1".equals(id)) {
- Future t1 = executorService.submit(new TestRunnable(1000 * 30));
- Future t2 = executorService.submit(new TestIdentifiableRunnable(1000 * 60));
- } else {
- System.out.println("Unknown test id: " + id);
- }
+ public void testBasic() throws Exception {
+ Future t1 = executorService.submit(new TestRunnable(1000 * 30));
+ Future t2 = executorService.submit(new TestIdentifiableRunnable(1000 * 60));
+ }
+
+ /*
+ * Tests if lifecycle methods throws IllegalStateException on
+ * server-managed executor service.
+ */
+ public void testServerManagedLifecycleMethods() throws Exception {
+ ManagedExecutorServiceTest test = new ManagedExecutorServiceTest(executorService);
+ test.testServerManagedLifecycleMethods();
}
}
Modified: geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedScheduledExecutorServiceServlet.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedScheduledExecutorServiceServlet.java?rev=641351&r1=641350&r2=641351&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedScheduledExecutorServiceServlet.java (original)
+++ geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedScheduledExecutorServiceServlet.java Wed Mar 26 08:36:30 2008
@@ -19,6 +19,8 @@
package org.apache.geronimo.concurrent.test;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -45,26 +47,43 @@
System.out.println(scheduledExecutorService);
String testName = (String)request.getParameter("testName");
- String id = (String)request.getParameter("id");
- System.out.println(testName + " " + id);
+ System.out.println(testName);
- try {
- testManagedScheduledExecutorService(id);
- } catch (Exception e) {
- LOG.error("Test failed: " + e.getMessage(), e);
- e.printStackTrace(response.getWriter());
- response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Test failed");
+ if (!testName.startsWith("test")) {
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Invalid test name");
}
+ try {
+ Method method = getClass().getMethod(testName, new Class [] {});
+ method.invoke(this, new Object [] {});
+ } catch (NoSuchMethodException e) {
+ LOG.error("No such test: " + testName);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No such test");
+ } catch (IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ Throwable ex = e.getTargetException();
+ LOG.error("Test " + testName + " failed", ex);
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Test failed");
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
- private void testManagedScheduledExecutorService(String id) throws Exception {
- if ("1".equals(id)) {
- Future t1 = scheduledExecutorService.scheduleWithFixedDelay(new TestRunnable(1000 * 10), 5, 5, TimeUnit.SECONDS);
- Thread.sleep(5 * 1000);
- } else {
- System.out.println("Unknown test id: " + id);
- }
+ public void testBasic() throws Exception {
+ Future t1 = scheduledExecutorService.scheduleWithFixedDelay(new TestRunnable(1000 * 10), 5, 5, TimeUnit.SECONDS);
+ Thread.sleep(5 * 1000);
}
+
+ /*
+ * Tests if lifecycle methods throws IllegalStateException on
+ * server-managed executor service.
+ */
+ public void testServerManagedLifecycleMethods() throws Exception {
+ ManagedExecutorServiceTest test = new ManagedExecutorServiceTest(scheduledExecutorService);
+ test.testServerManagedLifecycleMethods();
+ }
}
Modified: geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedExecutorServiceTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedExecutorServiceTest.java?rev=641351&r1=641350&r2=641351&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedExecutorServiceTest.java (original)
+++ geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedExecutorServiceTest.java Wed Mar 26 08:36:30 2008
@@ -33,6 +33,11 @@
}
@Test
+ public void testLifecycleMethods() throws Exception {
+ invokeTest("testServerManagedLifecycleMethods");
+ }
+
+ @Test
public void testThreadsField() throws Exception {
MBeanServerConnection mbServerConn = this.jmxConnector.getMBeanServerConnection();
@@ -44,7 +49,7 @@
ObjectName executorService = objectNameSet.iterator().next();
- invokeTest("testManagedExecutorService&id=1");
+ invokeTest("testBasic");
ObjectName task1Thread = null;
ObjectName task2Thread = null;
Modified: geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedScheduledExecutorServiceTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedScheduledExecutorServiceTest.java?rev=641351&r1=641350&r2=641351&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedScheduledExecutorServiceTest.java (original)
+++ geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedScheduledExecutorServiceTest.java Wed Mar 26 08:36:30 2008
@@ -33,6 +33,11 @@
}
@Test
+ public void testLifecycleMethods() throws Exception {
+ invokeTest("testServerManagedLifecycleMethods");
+ }
+
+ @Test
public void testThreadsField() throws Exception {
MBeanServerConnection mbServerConn = this.jmxConnector.getMBeanServerConnection();
@@ -44,8 +49,7 @@
ObjectName executorService = objectNameSet.iterator().next();
- invokeTest("testManagedScheduledExecutorService&id=1");
-
+ invokeTest("testBasic");
}
}