geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r638554 - in /geronimo/sandbox/concurrent/geronimo-concurrent-core/src: main/java/org/apache/geronimo/concurrent/thread/ test/java/org/apache/geronimo/concurrent/ test/java/org/apache/geronimo/concurrent/executor/
Date Tue, 18 Mar 2008 20:25:54 GMT
Author: gawor
Date: Tue Mar 18 13:25:46 2008
New Revision: 638554

URL: http://svn.apache.org/viewvc?rev=638554&view=rev
Log:
added a new test when a task throws an exception

Modified:
    geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/ManagedThreadFactoryUtils.java
    geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/TestCallable.java
    geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/TestRunnable.java
    geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/BasicManagedExecutorServiceTest.java

Modified: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/ManagedThreadFactoryUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/ManagedThreadFactoryUtils.java?rev=638554&r1=638553&r2=638554&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/ManagedThreadFactoryUtils.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent-core/src/main/java/org/apache/geronimo/concurrent/thread/ManagedThreadFactoryUtils.java
Tue Mar 18 13:25:46 2008
@@ -54,7 +54,7 @@
         }
         
         public Thread newThread(Runnable runnable) {                
-            runnable = new ManagedRunnable(runnable, this.managedContext, associateTask);
+            runnable = new ManagedRunnable(runnable, this.managedContext, this.associateTask);
             return this.factory.newThread(runnable);
         }
                

Modified: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/TestCallable.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/TestCallable.java?rev=638554&r1=638553&r2=638554&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/TestCallable.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/TestCallable.java
Tue Mar 18 13:25:46 2008
@@ -23,13 +23,19 @@
 public class TestCallable implements Callable<Object> {
     private List list = new ArrayList();
     private long delay;
+    private boolean fail;
     
     public TestCallable() {
-        this(0);
+        this(0, false);
     }
     
     public TestCallable(long delay) {
+        this(delay, false);
+    }
+    
+    public TestCallable(long delay, boolean fail) {
         this.delay = delay;
+        this.fail = fail;
     }
     
     public List getList() {
@@ -42,6 +48,9 @@
             Thread.sleep(this.delay);
         }
         list.add(TestContextHandler.getCurrentObject());
+        if (this.fail) {
+            throw new IllegalStateException("Abort");
+        }
         return this;
     } 
 } 

Modified: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/TestRunnable.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/TestRunnable.java?rev=638554&r1=638553&r2=638554&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/TestRunnable.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/TestRunnable.java
Tue Mar 18 13:25:46 2008
@@ -21,8 +21,17 @@
 
 public class TestRunnable implements Runnable { 
     
-    private List list = new ArrayList();     
+    private List list = new ArrayList();
+    private boolean fail;     
         
+    public TestRunnable() {
+        this(false);
+    }
+    
+    public TestRunnable(boolean fail) {
+        this.fail = fail;
+    }
+    
     public List getList() {
         return this.list;
     }
@@ -30,6 +39,9 @@
     public void run() {
         System.out.println(Thread.currentThread());
         list.add(TestContextHandler.getCurrentObject());
+        if (this.fail) {
+            throw new IllegalStateException("Abort");
+        }
     }    
     
 }

Modified: geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/BasicManagedExecutorServiceTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/BasicManagedExecutorServiceTest.java?rev=638554&r1=638553&r2=638554&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/BasicManagedExecutorServiceTest.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent-core/src/test/java/org/apache/geronimo/concurrent/executor/BasicManagedExecutorServiceTest.java
Tue Mar 18 13:25:46 2008
@@ -21,6 +21,7 @@
 import java.util.List;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CancellationException;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -123,6 +124,62 @@
         assertEquals(Arrays.asList(expected), task3.getList());  
         List<TestManagedTaskListener.CallbackInfo> callbacks3 = createCallbackInfo(f3);
         compareCallbacks(callbacks3, listener3.getCallbacks(f3));
+    }
+    
+    public void testFailSubmitWithListener() throws Exception {
+        // test1
+        TestRunnable task1 = new TestRunnable(true);
+        TestManagedTaskListener listener1 = new TestManagedTaskListener();
+
+        Future f1 = service.submit(task1, listener1);
+        
+        try {
+            f1.get(5, TimeUnit.SECONDS);
+            fail("Did not throw exception");
+        } catch (ExecutionException e) {
+            assertTrue("Unexpected exception " + e.getMessage(), 
+                       e.getCause() instanceof IllegalStateException);
+        }
+        
+        assertEquals(Arrays.asList(expected), task1.getList());
+        List<TestManagedTaskListener.CallbackInfo> callbacks1 = createCallbackInfo(f1);
+        compareCallbacks(callbacks1, listener1.getCallbacks(f1));
+                
+        // test2
+        TestRunnable task2 = new TestRunnable(true);
+        TestManagedTaskListener listener2 = new TestManagedTaskListener();
+        Integer value = new Integer(5);
+        
+        Future f2 = service.submit(task2, value, listener2);
+        
+        try {
+            f2.get(5, TimeUnit.SECONDS);
+            fail("Did not throw exception");
+        } catch (ExecutionException e) {
+            assertTrue("Unexpected exception " + e.getMessage(), 
+                       e.getCause() instanceof IllegalStateException);
+        }
+        
+        assertEquals(Arrays.asList(expected), task2.getList());  
+        List<TestManagedTaskListener.CallbackInfo> callbacks2 = createCallbackInfo(f2);
+        compareCallbacks(callbacks2, listener2.getCallbacks(f2));
+        
+        // test3        
+        TestCallable task3 = new TestCallable(0, true);
+        TestManagedTaskListener listener3 = new TestManagedTaskListener();
+        
+        Future f3 = service.submit(task3, listener3);
+        
+        try {
+            f3.get(5, TimeUnit.SECONDS);
+        } catch (ExecutionException e) {
+            assertTrue("Unexpected exception " + e.getMessage(), 
+                       e.getCause() instanceof IllegalStateException);
+        }
+        
+        assertEquals(Arrays.asList(expected), task3.getList());  
+        List<TestManagedTaskListener.CallbackInfo> callbacks3 = createCallbackInfo(f3);
+        compareCallbacks(callbacks3, listener3.getCallbacks(f3));        
     }
     
     public void testInvokeAll() throws Exception {



Mime
View raw message