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.26 by jsr166, Sat Nov 21 02:33:20 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines