You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by pe...@apache.org on 2011/09/21 16:48:02 UTC

svn commit: r1173687 - /river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/dos/IsolateTest.java

Author: peter_firmstone
Date: Wed Sep 21 14:48:01 2011
New Revision: 1173687

URL: http://svn.apache.org/viewvc?rev=1173687&view=rev
Log:
Reference Collection Utilities

Modified:
    river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/dos/IsolateTest.java

Modified: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/dos/IsolateTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/dos/IsolateTest.java?rev=1173687&r1=1173686&r2=1173687&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/dos/IsolateTest.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/dos/IsolateTest.java Wed Sep 21 14:48:01 2011
@@ -56,26 +56,70 @@ public class IsolateTest {
 
     @Before
     public void setUp() {
+        executor = new IsolatedExecutor();
+    }
+    
+    @After
+    public void tearDown() {
+        executor.shutdownNow();
+        executor = null;
     }
 
     /**
      * Test of process method, of class IsolatedExecutor.
+     * This test leaves stale threads consuming CPU.
      */
     @Test
-    public void timeout() throws Exception {
-        System.out.println("process");
-        Callable<Object> task = new EndlessLoopTask();
+    public void stackOverflow() {
+        System.out.println("Stack overflow");
+        Callable<Object> task = new StackOverflowTask();
         long timeout = 10L;
-        IsolatedExecutor instance = new IsolatedExecutor();
         Exception e = null;
+        Future result = executor.submit(task);
         try {
-            instance.process(task, timeout, TimeUnit.SECONDS);
-        } catch ( TimeoutException ex ){
-            e = ex;
-            System.out.println(ex);
-        }
-        assertTrue((e instanceof TimeoutException));
+            result.get();
+        } catch ( Exception ex ){
+            e = ex;            
+            ex.printStackTrace(System.out);
+        } 
+        assertTrue((e instanceof Exception));
         // TODO review the generated test code and remove the default call to fail.
     }
+    
+   /**
+     * Test of process method, of class IsolatedExecutor.
+     */
+    @Test
+    public void arrayListOverflow() {
+        System.out.println("ArrayList overflow");
+//         This leaves stale threads consuming CPU.
+        Callable<Object> task = new ArrayListOverflow();
+        long timeout = 120L;
+        Exception e = null;
+        try {
+            executor.process(task, timeout, TimeUnit.SECONDS);
+        } catch ( Exception ex ){
+            e = ex;            
+            ex.printStackTrace(System.out);
+            if (ex instanceof ExecutionException){
+                Throwable t = ((ExecutionException)ex).getCause();
+                if (t instanceof Error) executor = new IsolatedExecutor();
+            }
+        } 
+        assertTrue((e instanceof Exception));
+        Callable<Boolean> task2 = new PrintTask();
+        Boolean result = Boolean.FALSE;
+        try {
+            result = (Boolean) executor.process(task2, timeout, TimeUnit.MINUTES);
+        } catch (ExecutionException ex) {
+            
+        } catch (InterruptedException ex) {
+            
+        } catch (TimeoutException ex) {
+            
+        }
+        assertTrue(result);
+//        // TODO review the generated test code and remove the default call to fail.
+    }
 
 }
\ No newline at end of file