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.24 by jsr166, Fri Nov 20 22:58:48 2009 UTC vs.
Revision 1.27 by jsr166, Tue Dec 1 09:56:28 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 222 | Line 223 | public class ExecutorsTest extends JSR16
223      public void testNewSingleThreadScheduledExecutor() throws Exception {
224          TrackedCallable callable = new TrackedCallable();
225          ScheduledExecutorService p1 = Executors.newSingleThreadScheduledExecutor();
226 <        Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
226 >        Future f = p1.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
227          assertFalse(callable.done);
228          Thread.sleep(MEDIUM_DELAY_MS);
229          assertTrue(callable.done);
# Line 236 | Line 237 | public class ExecutorsTest extends JSR16
237      public void testnewScheduledThreadPool() throws Exception {
238          TrackedCallable callable = new TrackedCallable();
239          ScheduledExecutorService p1 = Executors.newScheduledThreadPool(2);
240 <        Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
240 >        Future f = p1.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
241          assertFalse(callable.done);
242          Thread.sleep(MEDIUM_DELAY_MS);
243          assertTrue(callable.done);
# Line 250 | Line 251 | public class ExecutorsTest extends JSR16
251      public void testunconfigurableScheduledExecutorService() throws Exception {
252          TrackedCallable callable = new TrackedCallable();
253          ScheduledExecutorService p1 = Executors.unconfigurableScheduledExecutorService(Executors.newScheduledThreadPool(2));
254 <        Future f = p1.schedule(callable, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
254 >        Future f = p1.schedule(callable, SHORT_DELAY_MS, MILLISECONDS);
255          assertFalse(callable.done);
256          Thread.sleep(MEDIUM_DELAY_MS);
257          assertTrue(callable.done);
# Line 304 | 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 357 | 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 389 | Line 390 | public class ExecutorsTest extends JSR16
390          } finally {
391              joinPool(e);
392          }
392
393      }
394  
395      void checkCCL() {
# Line 413 | 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 445 | 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 506 | 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();
# Line 538 | Line 538 | public class ExecutorsTest extends JSR16
538       */
539      public void testCallable2() throws Exception {
540          Callable c = Executors.callable(new NoOpRunnable(), one);
541 <        assertEquals(one, c.call());
541 >        assertSame(one, c.call());
542      }
543  
544      /**
# Line 547 | Line 547 | public class ExecutorsTest extends JSR16
547      public void testCallable3() throws Exception {
548          Callable c = Executors.callable(new PrivilegedAction() {
549                  public Object run() { return one; }});
550 <        assertEquals(one, c.call());
550 >        assertSame(one, c.call());
551      }
552  
553      /**
# Line 556 | Line 556 | public class ExecutorsTest extends JSR16
556      public void testCallable4() throws Exception {
557          Callable c = Executors.callable(new PrivilegedExceptionAction() {
558                  public Object run() { return one; }});
559 <        assertEquals(one, c.call());
559 >        assertSame(one, c.call());
560      }
561  
562  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines