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.4 by jsr166, Sat Mar 25 21:41:10 2017 UTC vs.
Revision 1.7 by jsr166, Sat Feb 9 19:20:54 2019 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines