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.46 by jsr166, Sun Oct 4 16:14:48 2015 UTC vs.
Revision 1.52 by dl, Sat Feb 1 16:45:50 2020 UTC

# Line 63 | Line 63 | public class ExecutorsTest extends JSR16
63       */
64      public void testNewCachedThreadPool3() {
65          try {
66 <            ExecutorService e = Executors.newCachedThreadPool(null);
66 >            ExecutorService unused = Executors.newCachedThreadPool(null);
67              shouldThrow();
68          } catch (NullPointerException success) {}
69      }
# Line 97 | Line 97 | public class ExecutorsTest extends JSR16
97       */
98      public void testNewSingleThreadExecutor3() {
99          try {
100 <            ExecutorService e = Executors.newSingleThreadExecutor(null);
100 >            ExecutorService unused = Executors.newSingleThreadExecutor(null);
101              shouldThrow();
102          } catch (NullPointerException success) {}
103      }
# Line 140 | Line 140 | public class ExecutorsTest extends JSR16
140      }
141  
142      /**
143 <     * A new newFixedThreadPool with null ThreadFactory throws NPE
143 >     * A new newFixedThreadPool with null ThreadFactory throws
144 >     * NullPointerException
145       */
146      public void testNewFixedThreadPool3() {
147          try {
148 <            ExecutorService e = Executors.newFixedThreadPool(2, null);
148 >            ExecutorService unused = Executors.newFixedThreadPool(2, null);
149              shouldThrow();
150          } catch (NullPointerException success) {}
151      }
152  
153      /**
154 <     * A new newFixedThreadPool with 0 threads throws IAE
154 >     * A new newFixedThreadPool with 0 threads throws IllegalArgumentException
155       */
156      public void testNewFixedThreadPool4() {
157          try {
158 <            ExecutorService e = Executors.newFixedThreadPool(0);
158 >            ExecutorService unused = Executors.newFixedThreadPool(0);
159              shouldThrow();
160          } catch (IllegalArgumentException success) {}
161      }
# Line 176 | Line 177 | public class ExecutorsTest extends JSR16
177       */
178      public void testUnconfigurableExecutorServiceNPE() {
179          try {
180 <            ExecutorService e = Executors.unconfigurableExecutorService(null);
180 >            ExecutorService unused =
181 >                Executors.unconfigurableExecutorService(null);
182              shouldThrow();
183          } catch (NullPointerException success) {}
184      }
# Line 186 | Line 188 | public class ExecutorsTest extends JSR16
188       */
189      public void testUnconfigurableScheduledExecutorServiceNPE() {
190          try {
191 <            ExecutorService e = Executors.unconfigurableScheduledExecutorService(null);
191 >            ExecutorService unused =
192 >                Executors.unconfigurableScheduledExecutorService(null);
193              shouldThrow();
194          } catch (NullPointerException success) {}
195      }
# Line 276 | Line 279 | public class ExecutorsTest extends JSR16
279              Executors.newScheduledThreadPool(2),
280          };
281  
282 <        final Runnable sleeper = new CheckedInterruptedRunnable() {
282 >        final Runnable sleeper = new CheckedRunnable() {
283              public void realRun() throws InterruptedException {
284 <                delay(LONG_DELAY_MS);
284 >                try {
285 >                    delay(LONG_DELAY_MS);
286 >                } catch(InterruptedException OK) {
287 >                }
288              }};
289  
290 <        List<Thread> threads = new ArrayList<Thread>();
290 >        List<Thread> threads = new ArrayList<>();
291          for (final ExecutorService executor : executors) {
292              threads.add(newStartedThread(new CheckedRunnable() {
293                  public void realRun() {
# Line 292 | Line 298 | public class ExecutorsTest extends JSR16
298          for (Thread thread : threads)
299              awaitTermination(thread);
300          for (ExecutorService executor : executors)
301 +            executor.shutdownNow(); // assumes shutdownNow interrupts threads
302 +        for (ExecutorService executor : executors)
303              joinPool(executor);
304      }
305  
# Line 306 | Line 314 | public class ExecutorsTest extends JSR16
314              public void realRun() {
315                  try {
316                      Thread current = Thread.currentThread();
317 <                    assertTrue(!current.isDaemon());
317 >                    assertFalse(current.isDaemon());
318                      assertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
311                    ThreadGroup g = current.getThreadGroup();
319                      SecurityManager s = System.getSecurityManager();
320 <                    if (s != null)
321 <                        assertTrue(g == s.getThreadGroup());
322 <                    else
316 <                        assertTrue(g == egroup);
317 <                    String name = current.getName();
318 <                    assertTrue(name.endsWith("thread-1"));
320 >                    assertSame(current.getThreadGroup(),
321 >                               (s == null) ? egroup : s.getThreadGroup());
322 >                    assertTrue(current.getName().endsWith("thread-1"));
323                  } catch (SecurityException ok) {
324                      // Also pass if not allowed to change setting
325                  }
# Line 343 | Line 347 | public class ExecutorsTest extends JSR16
347                  Runnable r = new CheckedRunnable() {
348                      public void realRun() {
349                          Thread current = Thread.currentThread();
350 <                        assertTrue(!current.isDaemon());
350 >                        assertFalse(current.isDaemon());
351                          assertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
348                        ThreadGroup g = current.getThreadGroup();
352                          SecurityManager s = System.getSecurityManager();
353 <                        if (s != null)
354 <                            assertTrue(g == s.getThreadGroup());
355 <                        else
353 <                            assertTrue(g == egroup);
354 <                        String name = current.getName();
355 <                        assertTrue(name.endsWith("thread-1"));
353 >                        assertSame(current.getThreadGroup(),
354 >                                   (s == null) ? egroup : s.getThreadGroup());
355 >                        assertTrue(current.getName().endsWith("thread-1"));
356                          assertSame(thisccl, current.getContextClassLoader());
357                          assertEquals(thisacc, AccessController.getContext());
358                          done.countDown();
# Line 558 | Line 558 | public class ExecutorsTest extends JSR16
558       */
559      public void testCallableNPE1() {
560          try {
561 <            Callable c = Executors.callable((Runnable) null);
561 >            Callable unused = Executors.callable((Runnable) null);
562              shouldThrow();
563          } catch (NullPointerException success) {}
564      }
# Line 568 | Line 568 | public class ExecutorsTest extends JSR16
568       */
569      public void testCallableNPE2() {
570          try {
571 <            Callable c = Executors.callable((Runnable) null, one);
571 >            Callable unused = Executors.callable((Runnable) null, one);
572              shouldThrow();
573          } catch (NullPointerException success) {}
574      }
# Line 578 | Line 578 | public class ExecutorsTest extends JSR16
578       */
579      public void testCallableNPE3() {
580          try {
581 <            Callable c = Executors.callable((PrivilegedAction) null);
581 >            Callable unused = Executors.callable((PrivilegedAction) null);
582              shouldThrow();
583          } catch (NullPointerException success) {}
584      }
# Line 588 | Line 588 | public class ExecutorsTest extends JSR16
588       */
589      public void testCallableNPE4() {
590          try {
591 <            Callable c = Executors.callable((PrivilegedExceptionAction) null);
591 >            Callable unused = Executors.callable((PrivilegedExceptionAction) null);
592              shouldThrow();
593          } catch (NullPointerException success) {}
594      }
595  
596 +    /**
597 +     * callable(runnable, x).toString() contains toString of wrapped task
598 +     */
599 +    public void testCallable_withResult_toString() {
600 +        if (testImplementationDetails) {
601 +            Runnable r = () -> {};
602 +            Callable<String> c = Executors.callable(r, "");
603 +            assertEquals(
604 +                identityString(c) + "[Wrapped task = " + r.toString() + "]",
605 +                c.toString());
606 +        }
607 +    }
608 +
609 +    /**
610 +     * callable(runnable).toString() contains toString of wrapped task
611 +     */
612 +    public void testCallable_toString() {
613 +        if (testImplementationDetails) {
614 +            Runnable r = () -> {};
615 +            Callable<Object> c = Executors.callable(r);
616 +            assertEquals(
617 +                identityString(c) + "[Wrapped task = " + r.toString() + "]",
618 +                c.toString());
619 +        }
620 +    }
621 +
622 +    /**
623 +     * privilegedCallable(callable).toString() contains toString of wrapped task
624 +     */
625 +    public void testPrivilegedCallable_toString() {
626 +        if (testImplementationDetails) {
627 +            Callable<String> c = () -> "";
628 +            Callable<String> priv = Executors.privilegedCallable(c);
629 +            assertEquals(
630 +                identityString(priv) + "[Wrapped task = " + c.toString() + "]",
631 +                priv.toString());
632 +        }
633 +    }
634 +
635 +    /**
636 +     * privilegedCallableUsingCurrentClassLoader(callable).toString()
637 +     * contains toString of wrapped task
638 +     */
639 +    public void testPrivilegedCallableUsingCurrentClassLoader_toString() {
640 +        if (testImplementationDetails) {
641 +            Callable<String> c = () -> "";
642 +            Callable<String> priv = Executors.privilegedCallableUsingCurrentClassLoader(c);
643 +            assertEquals(
644 +                identityString(priv) + "[Wrapped task = " + c.toString() + "]",
645 +                priv.toString());
646 +        }
647 +    }
648   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines