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

Comparing jsr166/src/test/tck/ForkJoinPool9Test.java (file contents):
Revision 1.6 by jsr166, Fri Dec 14 02:48:21 2018 UTC vs.
Revision 1.9 by jsr166, Tue Aug 13 23:06:39 2019 UTC

# Line 11 | Line 11 | import java.util.concurrent.CountDownLat
11   import java.util.concurrent.ForkJoinPool;
12   import java.util.concurrent.ForkJoinTask;
13   import java.util.concurrent.Future;
14 + import java.util.stream.Stream;
15  
16   import junit.framework.Test;
17   import junit.framework.TestSuite;
# Line 40 | Line 41 | public class ForkJoinPool9Test extends J
41              .findVarHandle(Thread.class, "contextClassLoader", ClassLoader.class);
42          ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
43          boolean haveSecurityManager = (System.getSecurityManager() != null);
44 <        CountDownLatch taskStarted = new CountDownLatch(1);
44 >        CountDownLatch runInCommonPoolStarted = new CountDownLatch(1);
45          ClassLoader classLoaderDistinctFromSystemClassLoader
46              = ClassLoader.getPlatformClassLoader();
47          assertNotSame(classLoaderDistinctFromSystemClassLoader,
48                        systemClassLoader);
49          Runnable runInCommonPool = () -> {
50 <            taskStarted.countDown();
50 >            runInCommonPoolStarted.countDown();
51              assertTrue(ForkJoinTask.inForkJoinPool());
52 <            assertSame(ForkJoinPool.commonPool(),
53 <                       ForkJoinTask.getPool());
54 <            assertSame(systemClassLoader,
55 <                       Thread.currentThread().getContextClassLoader());
56 <            assertSame(systemClassLoader,
57 <                       CCL.get(Thread.currentThread()));
52 >            assertSame(ForkJoinPool.commonPool(), ForkJoinTask.getPool());
53 >            Thread currentThread = Thread.currentThread();
54 >
55 >            Stream.of(systemClassLoader, null).forEach(cl -> {
56 >                if (randomBoolean())
57 >                    // should always be permitted, without effect
58 >                    currentThread.setContextClassLoader(cl);
59 >                });
60 >
61 >            Stream.of(currentThread.getContextClassLoader(),
62 >                      (ClassLoader) CCL.get(currentThread))
63 >            .forEach(cl -> assertTrue(cl == systemClassLoader || cl == null));
64 >
65              if (haveSecurityManager)
66                  assertThrows(
67                      SecurityException.class,
68                      () -> System.getProperty("foo"),
69 <                    () -> Thread.currentThread().setContextClassLoader(
69 >                    () -> currentThread.setContextClassLoader(
70                          classLoaderDistinctFromSystemClassLoader));
71              // TODO ?
72   //          if (haveSecurityManager
# Line 69 | Line 77 | public class ForkJoinPool9Test extends J
77          Future<?> f = ForkJoinPool.commonPool().submit(runInCommonPool);
78          // Ensure runInCommonPool is truly running in the common pool,
79          // by giving this thread no opportunity to "help" on get().
80 <        await(taskStarted);
80 >        await(runInCommonPoolStarted);
81          assertNull(f.get());
82      }
83  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines