ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ThreadPoolExecutorTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ThreadPoolExecutorTest.java (file contents):
Revision 1.17 by dl, Tue Jan 20 20:20:56 2004 UTC vs.
Revision 1.19 by dl, Sat Apr 10 14:27:17 2004 UTC

# Line 36 | Line 36 | public class ThreadPoolExecutorTest exte
36          }
37      }
38  
39 +    static class FailingThreadFactory implements ThreadFactory{
40 +        int calls = 0;
41 +        public Thread newThread(Runnable r){
42 +            if (++calls > 1) throw new NullPointerException();
43 +            return new Thread(r);
44 +        }  
45 +    }
46 +    
47 +
48      /**
49       *  execute successfully executes a runnable
50       */
# Line 769 | Line 778 | public class ThreadPoolExecutorTest exte
778              for(int i = 1; i < 5; ++i) {
779                  assertTrue(tasks[i].done);
780              }
781 +            try { p.shutdownNow(); } catch(SecurityException ok) { return; }
782          } catch(RejectedExecutionException ex){
783              unexpectedException();
784          } finally {
# Line 795 | Line 805 | public class ThreadPoolExecutorTest exte
805              for(int i = 0; i < 5; ++i){
806                  assertFalse(tasks[i].done);
807              }
808 +            try { p.shutdownNow(); } catch(SecurityException ok) { return; }
809          } catch(RejectedExecutionException ex){
810              unexpectedException();
811          } finally {
# Line 817 | Line 828 | public class ThreadPoolExecutorTest exte
828              p.execute(r3);
829              assertFalse(p.getQueue().contains(r2));
830              assertTrue(p.getQueue().contains(r3));
831 +            try { p.shutdownNow(); } catch(SecurityException ok) { return; }
832          } catch(RejectedExecutionException ex){
833              unexpectedException();
834          } finally {
# Line 1495 | Line 1507 | public class ThreadPoolExecutorTest exte
1507          }
1508      }
1509  
1510 <
1510 >    /**
1511 >     * Execution continues if there is at least one thread even if
1512 >     * thread factory fails to create more
1513 >     */
1514 >    public void testFailingThreadFactory() {
1515 >        ExecutorService e = new ThreadPoolExecutor(100, 100, LONG_DELAY_MS, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1516 >        try {
1517 >            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1518 >            for (int k = 0; k < 100; ++k) {
1519 >                e.execute(new NoOpRunnable());
1520 >            }
1521 >            Thread.sleep(LONG_DELAY_MS);
1522 >        } catch(Exception ex) {
1523 >            unexpectedException();
1524 >        } finally {
1525 >            joinPool(e);
1526 >        }
1527 >    }
1528   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines