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

Comparing jsr166/src/test/tck/AbstractExecutorServiceTest.java (file contents):
Revision 1.45 by jsr166, Wed Jan 4 06:09:58 2017 UTC vs.
Revision 1.49 by dl, Tue Jan 26 13:33:05 2021 UTC

# Line 11 | Line 11 | import static java.util.concurrent.TimeU
11   import java.security.PrivilegedAction;
12   import java.security.PrivilegedExceptionAction;
13   import java.util.ArrayList;
14 + import java.util.Collection;
15   import java.util.Collections;
16   import java.util.List;
17   import java.util.concurrent.AbstractExecutorService;
# Line 46 | Line 47 | public class AbstractExecutorServiceTest
47          public void shutdown() { shutdown = true; }
48          public List<Runnable> shutdownNow() {
49              shutdown = true;
50 <            return Collections.EMPTY_LIST;
50 >            return Collections.emptyList();
51          }
52          public boolean isShutdown() { return shutdown; }
53          public boolean isTerminated() { return isShutdown(); }
# Line 110 | Line 111 | public class AbstractExecutorServiceTest
111          Runnable r = new CheckedRunnable() {
112              public void realRun() throws Exception {
113                  ExecutorService e = new DirectExecutorService();
114 <                Future future = e.submit(Executors.callable(new PrivilegedAction() {
114 >                Future<?> future = e.submit(Executors.callable(new PrivilegedAction<Object>() {
115                      public Object run() {
116                          return TEST_STRING;
117                      }}));
# Line 131 | Line 132 | public class AbstractExecutorServiceTest
132          Runnable r = new CheckedRunnable() {
133              public void realRun() throws Exception {
134                  ExecutorService e = new DirectExecutorService();
135 <                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
135 >                Future<?> future = e.submit(Executors.callable(new PrivilegedExceptionAction<Object>() {
136                      public Object run() {
137                          return TEST_STRING;
138                      }}));
# Line 149 | Line 150 | public class AbstractExecutorServiceTest
150          Runnable r = new CheckedRunnable() {
151              public void realRun() throws Exception {
152                  ExecutorService e = new DirectExecutorService();
153 <                Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() {
153 >                Future<?> future = e.submit(Executors.callable(new PrivilegedExceptionAction<Object>() {
154                      public Object run() throws Exception {
155                          throw new IndexOutOfBoundsException();
156                      }}));
# Line 165 | Line 166 | public class AbstractExecutorServiceTest
166      }
167  
168      /**
169 <     * execute(null runnable) throws NPE
169 >     * Submitting null tasks throws NullPointerException
170       */
171 <    public void testExecuteNullRunnable() {
172 <        ExecutorService e = new DirectExecutorService();
173 <        try {
174 <            e.submit((Runnable) null);
175 <            shouldThrow();
175 <        } catch (NullPointerException success) {}
176 <    }
177 <
178 <    /**
179 <     * submit(null callable) throws NPE
180 <     */
181 <    public void testSubmitNullCallable() {
182 <        ExecutorService e = new DirectExecutorService();
183 <        try {
184 <            e.submit((Callable) null);
185 <            shouldThrow();
186 <        } catch (NullPointerException success) {}
171 >    public void testNullTaskSubmission() {
172 >        final ExecutorService e = new DirectExecutorService();
173 >        try (PoolCleaner cleaner = cleaner(e)) {
174 >            assertNullTaskSubmissionThrowsNullPointerException(e);
175 >        }
176      }
177  
178      /**
# Line 224 | Line 213 | public class AbstractExecutorServiceTest
213                                     60, TimeUnit.SECONDS,
214                                     new ArrayBlockingQueue<Runnable>(10));
215          try (PoolCleaner cleaner = cleaner(p)) {
216 <            Callable c = new Callable() {
216 >            Callable<Object> c = new Callable<Object>() {
217                  public Object call() { throw new ArithmeticException(); }};
218              try {
219                  p.submit(c).get();
# Line 249 | Line 238 | public class AbstractExecutorServiceTest
238      }
239  
240      /**
241 <     * invokeAny(empty collection) throws IAE
241 >     * invokeAny(empty collection) throws IllegalArgumentException
242       */
243      public void testInvokeAny2() throws Exception {
244          final ExecutorService e = new DirectExecutorService();
245 +        final Collection<Callable<String>> emptyCollection
246 +            = Collections.emptyList();
247          try (PoolCleaner cleaner = cleaner(e)) {
248              try {
249 <                e.invokeAny(new ArrayList<Callable<String>>());
249 >                e.invokeAny(emptyCollection);
250                  shouldThrow();
251              } catch (IllegalArgumentException success) {}
252          }
# Line 323 | Line 314 | public class AbstractExecutorServiceTest
314      }
315  
316      /**
317 <     * invokeAll(empty collection) returns empty collection
317 >     * invokeAll(empty collection) returns empty list
318       */
319      public void testInvokeAll2() throws InterruptedException {
320          final ExecutorService e = new DirectExecutorService();
321 +        final Collection<Callable<String>> emptyCollection
322 +            = Collections.emptyList();
323          try (PoolCleaner cleaner = cleaner(e)) {
324 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
324 >            List<Future<String>> r = e.invokeAll(emptyCollection);
325              assertTrue(r.isEmpty());
326          }
327      }
# Line 391 | Line 384 | public class AbstractExecutorServiceTest
384          final ExecutorService e = new DirectExecutorService();
385          try (PoolCleaner cleaner = cleaner(e)) {
386              try {
387 <                e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
387 >                e.invokeAny(null, randomTimeout(), randomTimeUnit());
388                  shouldThrow();
389              } catch (NullPointerException success) {}
390          }
391      }
392  
393      /**
394 <     * timed invokeAny(null time unit) throws NPE
394 >     * timed invokeAny(null time unit) throws NullPointerException
395       */
396      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
397          final ExecutorService e = new DirectExecutorService();
# Line 406 | Line 399 | public class AbstractExecutorServiceTest
399              List<Callable<String>> l = new ArrayList<>();
400              l.add(new StringTask());
401              try {
402 <                e.invokeAny(l, MEDIUM_DELAY_MS, null);
402 >                e.invokeAny(l, randomTimeout(), null);
403                  shouldThrow();
404              } catch (NullPointerException success) {}
405          }
406      }
407  
408      /**
409 <     * timed invokeAny(empty collection) throws IAE
409 >     * timed invokeAny(empty collection) throws IllegalArgumentException
410       */
411      public void testTimedInvokeAny2() throws Exception {
412          final ExecutorService e = new DirectExecutorService();
413 +        final Collection<Callable<String>> emptyCollection
414 +            = Collections.emptyList();
415          try (PoolCleaner cleaner = cleaner(e)) {
416              try {
417 <                e.invokeAny(new ArrayList<Callable<String>>(),
423 <                            MEDIUM_DELAY_MS, MILLISECONDS);
417 >                e.invokeAny(emptyCollection, randomTimeout(), randomTimeUnit());
418                  shouldThrow();
419              } catch (IllegalArgumentException success) {}
420          }
# Line 437 | Line 431 | public class AbstractExecutorServiceTest
431                        public Long call() { throw new ArithmeticException(); }});
432              l.add(null);
433              try {
434 <                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
434 >                e.invokeAny(l, randomTimeout(), randomTimeUnit());
435                  shouldThrow();
436              } catch (NullPointerException success) {}
437          }
# Line 479 | Line 473 | public class AbstractExecutorServiceTest
473      }
474  
475      /**
476 <     * timed invokeAll(null) throws NPE
476 >     * timed invokeAll(null) throws NullPointerException
477       */
478      public void testTimedInvokeAll1() throws InterruptedException {
479          final ExecutorService e = new DirectExecutorService();
480          try (PoolCleaner cleaner = cleaner(e)) {
481              try {
482 <                e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
482 >                e.invokeAll(null, randomTimeout(), randomTimeUnit());
483                  shouldThrow();
484              } catch (NullPointerException success) {}
485          }
# Line 500 | Line 494 | public class AbstractExecutorServiceTest
494              List<Callable<String>> l = new ArrayList<>();
495              l.add(new StringTask());
496              try {
497 <                e.invokeAll(l, MEDIUM_DELAY_MS, null);
497 >                e.invokeAll(l, randomTimeout(), null);
498                  shouldThrow();
499              } catch (NullPointerException success) {}
500          }
501      }
502  
503      /**
504 <     * timed invokeAll(empty collection) returns empty collection
504 >     * timed invokeAll(empty collection) returns empty list
505       */
506      public void testTimedInvokeAll2() throws InterruptedException {
507          final ExecutorService e = new DirectExecutorService();
508 +        final Collection<Callable<String>> emptyCollection
509 +            = Collections.emptyList();
510          try (PoolCleaner cleaner = cleaner(e)) {
511 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
511 >            List<Future<String>> r =
512 >                e.invokeAll(emptyCollection, randomTimeout(), randomTimeUnit());
513              assertTrue(r.isEmpty());
514          }
515      }
516  
517      /**
518 <     * timed invokeAll(c) throws NPE if c has null elements
518 >     * timed invokeAll(c) throws NullPointerException if c has null elements
519       */
520      public void testTimedInvokeAll3() throws InterruptedException {
521          final ExecutorService e = new DirectExecutorService();
# Line 527 | Line 524 | public class AbstractExecutorServiceTest
524              l.add(new StringTask());
525              l.add(null);
526              try {
527 <                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
527 >                e.invokeAll(l, randomTimeout(), randomTimeUnit());
528                  shouldThrow();
529              } catch (NullPointerException success) {}
530          }
# Line 587 | Line 584 | public class AbstractExecutorServiceTest
584                      e.invokeAll(tasks, timeout, MILLISECONDS);
585                  assertEquals(tasks.size(), futures.size());
586                  assertTrue(millisElapsedSince(startTime) >= timeout);
587 <                for (Future future : futures)
587 >                for (Future<?> future : futures)
588                      assertTrue(future.isDone());
589                  try {
590                      assertEquals("0", futures.get(0).get());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines