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

Comparing jsr166/src/test/tck/ExecutorsTest.java (file contents):
Revision 1.23 by jsr166, Thu Nov 19 03:55:29 2009 UTC vs.
Revision 1.25 by jsr166, Sat Nov 21 02:07:26 2009 UTC

# Line 220 | Line 220 | public class ExecutorsTest extends JSR16
220       * a newSingleThreadScheduledExecutor successfully runs delayed task
221       */
222      public void testNewSingleThreadScheduledExecutor() throws Exception {
223 <        try {
224 <            TrackedCallable callable = new TrackedCallable();
225 <            ScheduledExecutorService p1 = Executors.newSingleThreadScheduledExecutor();
226 <            Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
227 <            assertFalse(callable.done);
228 <            Thread.sleep(MEDIUM_DELAY_MS);
229 <            assertTrue(callable.done);
230 <            assertEquals(Boolean.TRUE, f.get());
231 <            joinPool(p1);
232 <        } catch (RejectedExecutionException e) {}
223 >        TrackedCallable callable = new TrackedCallable();
224 >        ScheduledExecutorService p1 = Executors.newSingleThreadScheduledExecutor();
225 >        Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
226 >        assertFalse(callable.done);
227 >        Thread.sleep(MEDIUM_DELAY_MS);
228 >        assertTrue(callable.done);
229 >        assertEquals(Boolean.TRUE, f.get());
230 >        joinPool(p1);
231      }
232  
233      /**
234       * a newScheduledThreadPool successfully runs delayed task
235       */
236      public void testnewScheduledThreadPool() throws Exception {
237 <        try {
238 <            TrackedCallable callable = new TrackedCallable();
239 <            ScheduledExecutorService p1 = Executors.newScheduledThreadPool(2);
240 <            Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
241 <            assertFalse(callable.done);
242 <            Thread.sleep(MEDIUM_DELAY_MS);
243 <            assertTrue(callable.done);
244 <            assertEquals(Boolean.TRUE, f.get());
247 <            joinPool(p1);
248 <        } catch (RejectedExecutionException e) {}
237 >        TrackedCallable callable = new TrackedCallable();
238 >        ScheduledExecutorService p1 = Executors.newScheduledThreadPool(2);
239 >        Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
240 >        assertFalse(callable.done);
241 >        Thread.sleep(MEDIUM_DELAY_MS);
242 >        assertTrue(callable.done);
243 >        assertEquals(Boolean.TRUE, f.get());
244 >        joinPool(p1);
245      }
246  
247      /**
248 <     * an unconfigurable  newScheduledThreadPool successfully runs delayed task
248 >     * an unconfigurable newScheduledThreadPool successfully runs delayed task
249       */
250      public void testunconfigurableScheduledExecutorService() throws Exception {
251 <        try {
252 <            TrackedCallable callable = new TrackedCallable();
253 <            ScheduledExecutorService p1 = Executors.unconfigurableScheduledExecutorService(Executors.newScheduledThreadPool(2));
254 <            Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
255 <            assertFalse(callable.done);
256 <            Thread.sleep(MEDIUM_DELAY_MS);
257 <            assertTrue(callable.done);
258 <            assertEquals(Boolean.TRUE, f.get());
263 <            joinPool(p1);
264 <        } catch (RejectedExecutionException e) {}
251 >        TrackedCallable callable = new TrackedCallable();
252 >        ScheduledExecutorService p1 = Executors.unconfigurableScheduledExecutorService(Executors.newScheduledThreadPool(2));
253 >        Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
254 >        assertFalse(callable.done);
255 >        Thread.sleep(MEDIUM_DELAY_MS);
256 >        assertTrue(callable.done);
257 >        assertEquals(Boolean.TRUE, f.get());
258 >        joinPool(p1);
259      }
260  
261      /**
# Line 310 | Line 304 | public class ExecutorsTest extends JSR16
304          final ThreadGroup egroup = Thread.currentThread().getThreadGroup();
305          Runnable r = new Runnable() {
306                  public void run() {
307 <                    try {
308 <                        Thread current = Thread.currentThread();
309 <                        threadAssertTrue(!current.isDaemon());
310 <                        threadAssertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
311 <                        ThreadGroup g = current.getThreadGroup();
312 <                        SecurityManager s = System.getSecurityManager();
313 <                        if (s != null)
314 <                            threadAssertTrue(g == s.getThreadGroup());
315 <                        else
316 <                            threadAssertTrue(g == egroup);
317 <                        String name = current.getName();
318 <                        threadAssertTrue(name.endsWith("thread-1"));
319 <                    } catch (SecurityException ok) {
320 <                        // Also pass if not allowed to change setting
321 <                    }
307 >                    try {
308 >                        Thread current = Thread.currentThread();
309 >                        threadAssertTrue(!current.isDaemon());
310 >                        threadAssertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
311 >                        ThreadGroup g = current.getThreadGroup();
312 >                        SecurityManager s = System.getSecurityManager();
313 >                        if (s != null)
314 >                            threadAssertTrue(g == s.getThreadGroup());
315 >                        else
316 >                            threadAssertTrue(g == egroup);
317 >                        String name = current.getName();
318 >                        threadAssertTrue(name.endsWith("thread-1"));
319 >                    } catch (SecurityException ok) {
320 >                        // Also pass if not allowed to change setting
321 >                    }
322                  }
323              };
324          ExecutorService e = Executors.newSingleThreadExecutor(Executors.defaultThreadFactory());
# Line 363 | Line 357 | public class ExecutorsTest extends JSR16
357          final AccessControlContext thisacc = AccessController.getContext();
358          Runnable r = new Runnable() {
359                  public void run() {
360 <                    try {
361 <                        Thread current = Thread.currentThread();
362 <                        threadAssertTrue(!current.isDaemon());
363 <                        threadAssertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
364 <                        ThreadGroup g = current.getThreadGroup();
365 <                        SecurityManager s = System.getSecurityManager();
366 <                        if (s != null)
367 <                            threadAssertTrue(g == s.getThreadGroup());
368 <                        else
369 <                            threadAssertTrue(g == egroup);
370 <                        String name = current.getName();
371 <                        threadAssertTrue(name.endsWith("thread-1"));
372 <                        threadAssertTrue(thisccl == current.getContextClassLoader());
373 <                        threadAssertTrue(thisacc.equals(AccessController.getContext()));
374 <                    } catch (SecurityException ok) {
375 <                        // Also pass if not allowed to change settings
376 <                    }
360 >                    try {
361 >                        Thread current = Thread.currentThread();
362 >                        threadAssertTrue(!current.isDaemon());
363 >                        threadAssertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
364 >                        ThreadGroup g = current.getThreadGroup();
365 >                        SecurityManager s = System.getSecurityManager();
366 >                        if (s != null)
367 >                            threadAssertTrue(g == s.getThreadGroup());
368 >                        else
369 >                            threadAssertTrue(g == egroup);
370 >                        String name = current.getName();
371 >                        threadAssertTrue(name.endsWith("thread-1"));
372 >                        threadAssertTrue(thisccl == current.getContextClassLoader());
373 >                        threadAssertTrue(thisacc.equals(AccessController.getContext()));
374 >                    } catch (SecurityException ok) {
375 >                        // Also pass if not allowed to change settings
376 >                    }
377                  }
378              };
379          ExecutorService e = Executors.newSingleThreadExecutor(Executors.privilegedThreadFactory());
# Line 419 | Line 413 | public class ExecutorsTest extends JSR16
413       * privilegedCallableUsingCurrentClassLoader throws ACE
414       */
415      public void testCreatePrivilegedCallableUsingCCLWithNoPrivs() {
416 <        Policy savedPolicy = null;
416 >        Policy savedPolicy = null;
417          try {
418              savedPolicy = Policy.getPolicy();
419              AdjustablePolicy policy = new AdjustablePolicy();
# Line 451 | Line 445 | public class ExecutorsTest extends JSR16
445       * privilegedCallableUsingCurrentClassLoader does not throw ACE
446       */
447      public void testprivilegedCallableUsingCCLWithPrivs() throws Exception {
448 <        Policy savedPolicy = null;
448 >        Policy savedPolicy = null;
449          try {
450              savedPolicy = Policy.getPolicy();
451              AdjustablePolicy policy = new AdjustablePolicy();
# Line 512 | Line 506 | public class ExecutorsTest extends JSR16
506       * With permissions, calling privilegedCallable succeeds
507       */
508      public void testprivilegedCallableWithPrivs() throws Exception {
509 <        Policy savedPolicy = null;
509 >        Policy savedPolicy = null;
510          try {
511              savedPolicy = Policy.getPolicy();
512              AdjustablePolicy policy = new AdjustablePolicy();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines