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 20:48:14 UTC

svn commit: r641517 - 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 12:47:56 2008
New Revision: 641517

URL: http://svn.apache.org/viewvc?rev=641517&view=rev
Log:
added basic tests to see if naming and classloader env. is propagated to the thread

Added:
    geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/RunnableWrapper.java   (with props)
Modified:
    geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/BasicTask.java
    geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ContextServiceServlet.java
    geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedThreadFactoryServlet.java
    geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ContextServiceTest.java
    geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedThreadFactoryTest.java

Modified: geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/BasicTask.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/BasicTask.java?rev=641517&r1=641516&r2=641517&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/BasicTask.java (original)
+++ geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/BasicTask.java Wed Mar 26 12:47:56 2008
@@ -33,6 +33,8 @@
     }
     
     public Object execute() throws Exception {
+        System.out.println("Task starting");
+        
         InitialContext ctx = new InitialContext();
         
         // lookup user env
@@ -47,6 +49,7 @@
         // check class loader
         testClassLoader();
         
+        System.out.println("Task stopping");
         return Boolean.TRUE;
     }
     

Modified: geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ContextServiceServlet.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ContextServiceServlet.java?rev=641517&r1=641516&r2=641517&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ContextServiceServlet.java (original)
+++ geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ContextServiceServlet.java Wed Mar 26 12:47:56 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 javax.annotation.Resource;
 import javax.servlet.http.HttpServlet;
@@ -43,21 +45,50 @@
         System.out.println(contextService);
         
         String testName = (String)request.getParameter("testName");
-        String id = (String)request.getParameter("id");
-        System.out.println(testName + " " + id);
+        System.out.println(testName);
         
-        try {
-            testContextService();
-        } 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 testContextService() throws Exception {
-        System.out.println(contextService);  
+    public void testBasicContextProperties() throws Exception {
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        BasicTaskRunnable runnable = new BasicTaskRunnable(classLoader);
+        
+        Runnable task = (Runnable)contextService.createContextObject(runnable, new Class [] {Runnable.class});
+        RunnableWrapper wrapper = new RunnableWrapper(task);        
+        Thread t = new Thread(wrapper);        
+        t.start();
+        t.join();
+        
+        Throwable throwable = wrapper.getThrowable();
+        if (throwable instanceof Exception) {
+            throw (Exception)throwable;
+        } else if (throwable instanceof Error) {
+            throw (Error)throwable;
+        }
+    }
+        
+    public void testContextService() throws Exception {
         
         TestRunnable testRunnable = new TestRunnable(2 * 1000);
         Runnable r = (Runnable)contextService.createContextObject(testRunnable, new Class [] {Runnable.class});

Modified: geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedThreadFactoryServlet.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedThreadFactoryServlet.java?rev=641517&r1=641516&r2=641517&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedThreadFactoryServlet.java (original)
+++ geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/ManagedThreadFactoryServlet.java Wed Mar 26 12:47:56 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 javax.annotation.Resource;
 import javax.servlet.http.HttpServlet;
@@ -43,35 +45,65 @@
         System.out.println(threadFactory);
         
         String testName = (String)request.getParameter("testName");
-        String id = (String)request.getParameter("id");
-        System.out.println(testName + " " + id);
+        System.out.println(testName);
+        
+        if (!testName.startsWith("test")) {
+            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Invalid test name");
+        }
         
         try {
-            testManagedThreadFactory(id);
-        } catch (Exception e) {
-            LOG.error("Test failed: " + e.getMessage(), e);
-            e.printStackTrace(response.getWriter());
+            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 testManagedThreadFactory(String id) throws Exception {                      
-        if ("1".equals(id)) {
-            Thread t1 = threadFactory.newThread(new TestRunnable(1000 * 30));
-            t1.start();
-        } else if ("2".equals(id)) {        
-            Thread t2 = threadFactory.newThread(new TestIdentifiableRunnable(1000 * 30));
-            t2.start();
-        } else if ("3".equals(id)) {        
-            Thread t3 = threadFactory.newThread(new TestRunnable("TestRunnable long", 1000 * 60 * 2));
-            t3.start();
-        } else if ("4".equals(id)) {
-            Thread t3 = threadFactory.newThread(new ThreadCreator());
-            t3.start();
-        } else {
-            System.out.println("Unknown test id: " + id);
+    public void testBasicContextProperties() throws Exception {
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        BasicTaskRunnable runnable = new BasicTaskRunnable(classLoader);
+        RunnableWrapper wrapper = new RunnableWrapper(runnable); 
+        Thread t = threadFactory.newThread(wrapper);
+        t.start();
+        t.join();
+        
+        Throwable throwable = wrapper.getThrowable();
+        if (throwable instanceof Exception) {
+            throw (Exception)throwable;
+        } else if (throwable instanceof Error) {
+            throw (Error)throwable;
         }
+    }
+    
+    public void testLongTask() throws Exception {
+        Thread t3 = threadFactory.newThread(new TestRunnable("TestRunnable long", 1000 * 60 * 2));
+        t3.start();
+    }
+    
+    public void testStartRunnable() throws Exception {
+        Thread t1 = threadFactory.newThread(new TestRunnable(1000 * 30));
+        t1.start();
+    }
+    
+    public void testStartIdentifiableRunnable() throws Exception {
+        Thread t2 = threadFactory.newThread(new TestIdentifiableRunnable(1000 * 30));
+        t2.start(); 
+    }
+    
+    public void testModuleShutdown() throws Exception {
+        Thread t3 = threadFactory.newThread(new ThreadCreator());
+        t3.start();
     }
     
     private class ThreadCreator implements Runnable {

Added: geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/RunnableWrapper.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/RunnableWrapper.java?rev=641517&view=auto
==============================================================================
--- geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/RunnableWrapper.java (added)
+++ geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/RunnableWrapper.java Wed Mar 26 12:47:56 2008
@@ -0,0 +1,42 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.geronimo.concurrent.test;
+
+public class RunnableWrapper implements Runnable {
+
+    private Runnable target;
+    private Throwable throwable;
+    
+    public RunnableWrapper(Runnable target) {
+        this.target = target;
+    }
+    
+    public void run() {
+        try {
+            this.target.run();
+        } catch (Throwable t) {
+            this.throwable = t;
+        }
+    }
+    
+    public Throwable getThrowable() {
+        return this.throwable;
+    }
+        
+}

Propchange: geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/main/java/org/apache/geronimo/concurrent/test/RunnableWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ContextServiceTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ContextServiceTest.java?rev=641517&r1=641516&r2=641517&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ContextServiceTest.java (original)
+++ geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ContextServiceTest.java Wed Mar 26 12:47:56 2008
@@ -28,8 +28,13 @@
     }
     
     @Test
+    public void testBasicContextProperties() throws Exception {
+        invokeTest("testBasicContextProperties"); 
+    }
+    
+    @Test
     public void test() throws Exception {                
-        invokeTest("testContext");  
+        invokeTest("testContextService");  
     }
           
 }

Modified: geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedThreadFactoryTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedThreadFactoryTest.java?rev=641517&r1=641516&r2=641517&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedThreadFactoryTest.java (original)
+++ geronimo/sandbox/concurrent/concurrent-tests/concurrent-war/src/test/java/org/apache/geronimo/concurrent/test/ManagedThreadFactoryTest.java Wed Mar 26 12:47:56 2008
@@ -56,10 +56,15 @@
     }
     
     @Test
+    public void testBasicContextProperties() throws Exception {
+        invokeTest("testBasicContextProperties"); 
+    }
+    
+    @Test
     public void testHungReleaseTaskNotification() throws Exception { 
         ObjectName threadFactory = getManagedThreadFactory();
                 
-        invokeTest("testManagedThreadFactory&id=3");
+        invokeTest("testLongTask");
                                 
         String expectedTaskName = "TestRunnable long";
         String expectedTaskDesc = expectedTaskName;
@@ -93,7 +98,7 @@
     public void testHungCancelReleaseTaskNotification() throws Exception {  
         ObjectName threadFactory = getManagedThreadFactory();
                 
-        invokeTest("testManagedThreadFactory&id=3");
+        invokeTest("testLongTask");
                                        
         String expectedTaskName = "TestRunnable long";
         String expectedTaskDesc = expectedTaskName;
@@ -189,7 +194,7 @@
     public void testHungTaskCancel() throws Exception { 
         ObjectName threadFactory = getManagedThreadFactory();
                 
-        invokeTest("testManagedThreadFactory&id=3");
+        invokeTest("testLongTask");
                 
         ObjectName hungTaskThread = findHungTaskThread(threadFactory, 
                                                        "TestRunnable long", 
@@ -260,7 +265,7 @@
         TestListener listener = new TestListener(filter);            
         mbServerConn.addNotificationListener(threadFactory, listener, null, null);
                    
-        invokeTest("testManagedThreadFactory&id=1");        
+        invokeTest("testStartRunnable");        
         testThreadNotification(threadFactory, 
                                listener, 
                                "TestRunnable", 
@@ -269,7 +274,7 @@
         
         listener.reset();
             
-        invokeTest("testManagedThreadFactory&id=2");        
+        invokeTest("testStartIdentifiableRunnable");        
         testThreadNotification(threadFactory, 
                                listener, 
                                "TestIdentifiableRunnable Name", 
@@ -322,13 +327,13 @@
     public void testAttributes() throws Exception {
         ObjectName threadFactory = getManagedThreadFactory();
 
-        invokeTest("testManagedThreadFactory&id=1");
+        invokeTest("testStartRunnable");
         checkThreadAttributes(threadFactory, 
                               "TestRunnable", 
                               "TestRunnable", 
                               "TestRunnable");
         
-        invokeTest("testManagedThreadFactory&id=2");        
+        invokeTest("testStartIdentifiableRunnable");        
         checkThreadAttributes(threadFactory, 
                               "TestIdentifiableRunnable Name", 
                               "TestIdentifiableRunnable Description",