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.44 by jsr166, Thu Oct 8 03:08:37 2015 UTC vs.
Revision 1.47 by jsr166, Sun Jul 16 18:05:47 2017 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 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();
176 <        } catch (NullPointerException success) {}
177 <    }
178 <
179 <    /**
180 <     * submit(null callable) throws NPE
181 <     */
182 <    public void testSubmitNullCallable() {
183 <        ExecutorService e = new DirectExecutorService();
184 <        try {
185 <            e.submit((Callable) null);
186 <            shouldThrow();
187 <        } catch (NullPointerException success) {}
171 >    @SuppressWarnings("FutureReturnValueIgnored")
172 >    public void testNullTaskSubmission() throws Exception {
173 >        final ExecutorService e = new DirectExecutorService();
174 >        try (PoolCleaner cleaner = cleaner(e)) {
175 >            try {
176 >                e.execute((Runnable) null);
177 >                shouldThrow();
178 >            } catch (NullPointerException success) {}
179 >            try {
180 >                e.submit((Runnable) null);
181 >                shouldThrow();
182 >            } catch (NullPointerException success) {}
183 >            try {
184 >                e.submit((Callable) null);
185 >                shouldThrow();
186 >            } catch (NullPointerException success) {}
187 >        }
188      }
189  
190      /**
# Line 249 | Line 250 | public class AbstractExecutorServiceTest
250      }
251  
252      /**
253 <     * invokeAny(empty collection) throws IAE
253 >     * invokeAny(empty collection) throws IllegalArgumentException
254       */
255      public void testInvokeAny2() throws Exception {
256          final ExecutorService e = new DirectExecutorService();
257 +        final Collection<Callable<String>> emptyCollection
258 +            = Collections.emptyList();
259          try (PoolCleaner cleaner = cleaner(e)) {
260              try {
261 <                e.invokeAny(new ArrayList<Callable<String>>());
261 >                e.invokeAny(emptyCollection);
262                  shouldThrow();
263              } catch (IllegalArgumentException success) {}
264          }
# Line 267 | Line 270 | public class AbstractExecutorServiceTest
270      public void testInvokeAny3() throws Exception {
271          final ExecutorService e = new DirectExecutorService();
272          try (PoolCleaner cleaner = cleaner(e)) {
273 <            List<Callable<Long>> l = new ArrayList<Callable<Long>>();
273 >            List<Callable<Long>> l = new ArrayList<>();
274              l.add(new Callable<Long>() {
275                        public Long call() { throw new ArithmeticException(); }});
276              l.add(null);
# Line 284 | Line 287 | public class AbstractExecutorServiceTest
287      public void testInvokeAny4() throws InterruptedException {
288          final ExecutorService e = new DirectExecutorService();
289          try (PoolCleaner cleaner = cleaner(e)) {
290 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
290 >            List<Callable<String>> l = new ArrayList<>();
291              l.add(new NPETask());
292              try {
293                  e.invokeAny(l);
# Line 301 | Line 304 | public class AbstractExecutorServiceTest
304      public void testInvokeAny5() throws Exception {
305          final ExecutorService e = new DirectExecutorService();
306          try (PoolCleaner cleaner = cleaner(e)) {
307 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
307 >            List<Callable<String>> l = new ArrayList<>();
308              l.add(new StringTask());
309              l.add(new StringTask());
310              String result = e.invokeAny(l);
# Line 323 | Line 326 | public class AbstractExecutorServiceTest
326      }
327  
328      /**
329 <     * invokeAll(empty collection) returns empty collection
329 >     * invokeAll(empty collection) returns empty list
330       */
331      public void testInvokeAll2() throws InterruptedException {
332          final ExecutorService e = new DirectExecutorService();
333 +        final Collection<Callable<String>> emptyCollection
334 +            = Collections.emptyList();
335          try (PoolCleaner cleaner = cleaner(e)) {
336 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>());
336 >            List<Future<String>> r = e.invokeAll(emptyCollection);
337              assertTrue(r.isEmpty());
338          }
339      }
# Line 339 | Line 344 | public class AbstractExecutorServiceTest
344      public void testInvokeAll3() throws InterruptedException {
345          final ExecutorService e = new DirectExecutorService();
346          try (PoolCleaner cleaner = cleaner(e)) {
347 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
347 >            List<Callable<String>> l = new ArrayList<>();
348              l.add(new StringTask());
349              l.add(null);
350              try {
# Line 355 | Line 360 | public class AbstractExecutorServiceTest
360      public void testInvokeAll4() throws Exception {
361          final ExecutorService e = new DirectExecutorService();
362          try (PoolCleaner cleaner = cleaner(e)) {
363 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
363 >            List<Callable<String>> l = new ArrayList<>();
364              l.add(new NPETask());
365              List<Future<String>> futures = e.invokeAll(l);
366              assertEquals(1, futures.size());
# Line 374 | Line 379 | public class AbstractExecutorServiceTest
379      public void testInvokeAll5() throws Exception {
380          final ExecutorService e = new DirectExecutorService();
381          try (PoolCleaner cleaner = cleaner(e)) {
382 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
382 >            List<Callable<String>> l = new ArrayList<>();
383              l.add(new StringTask());
384              l.add(new StringTask());
385              List<Future<String>> futures = e.invokeAll(l);
# Line 391 | Line 396 | public class AbstractExecutorServiceTest
396          final ExecutorService e = new DirectExecutorService();
397          try (PoolCleaner cleaner = cleaner(e)) {
398              try {
399 <                e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS);
399 >                e.invokeAny(null, randomTimeout(), randomTimeUnit());
400                  shouldThrow();
401              } catch (NullPointerException success) {}
402          }
403      }
404  
405      /**
406 <     * timed invokeAny(null time unit) throws NPE
406 >     * timed invokeAny(null time unit) throws NullPointerException
407       */
408      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
409          final ExecutorService e = new DirectExecutorService();
410          try (PoolCleaner cleaner = cleaner(e)) {
411 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
411 >            List<Callable<String>> l = new ArrayList<>();
412              l.add(new StringTask());
413              try {
414 <                e.invokeAny(l, MEDIUM_DELAY_MS, null);
414 >                e.invokeAny(l, randomTimeout(), null);
415                  shouldThrow();
416              } catch (NullPointerException success) {}
417          }
418      }
419  
420      /**
421 <     * timed invokeAny(empty collection) throws IAE
421 >     * timed invokeAny(empty collection) throws IllegalArgumentException
422       */
423      public void testTimedInvokeAny2() throws Exception {
424          final ExecutorService e = new DirectExecutorService();
425 +        final Collection<Callable<String>> emptyCollection
426 +            = Collections.emptyList();
427          try (PoolCleaner cleaner = cleaner(e)) {
428              try {
429 <                e.invokeAny(new ArrayList<Callable<String>>(),
423 <                            MEDIUM_DELAY_MS, MILLISECONDS);
429 >                e.invokeAny(emptyCollection, randomTimeout(), randomTimeUnit());
430                  shouldThrow();
431              } catch (IllegalArgumentException success) {}
432          }
# Line 432 | Line 438 | public class AbstractExecutorServiceTest
438      public void testTimedInvokeAny3() throws Exception {
439          final ExecutorService e = new DirectExecutorService();
440          try (PoolCleaner cleaner = cleaner(e)) {
441 <            List<Callable<Long>> l = new ArrayList<Callable<Long>>();
441 >            List<Callable<Long>> l = new ArrayList<>();
442              l.add(new Callable<Long>() {
443                        public Long call() { throw new ArithmeticException(); }});
444              l.add(null);
445              try {
446 <                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
446 >                e.invokeAny(l, randomTimeout(), randomTimeUnit());
447                  shouldThrow();
448              } catch (NullPointerException success) {}
449          }
# Line 450 | Line 456 | public class AbstractExecutorServiceTest
456          final ExecutorService e = new DirectExecutorService();
457          try (PoolCleaner cleaner = cleaner(e)) {
458              long startTime = System.nanoTime();
459 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
459 >            List<Callable<String>> l = new ArrayList<>();
460              l.add(new NPETask());
461              try {
462                  e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
# Line 469 | Line 475 | public class AbstractExecutorServiceTest
475          final ExecutorService e = new DirectExecutorService();
476          try (PoolCleaner cleaner = cleaner(e)) {
477              long startTime = System.nanoTime();
478 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
478 >            List<Callable<String>> l = new ArrayList<>();
479              l.add(new StringTask());
480              l.add(new StringTask());
481              String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
# Line 479 | Line 485 | public class AbstractExecutorServiceTest
485      }
486  
487      /**
488 <     * timed invokeAll(null) throws NPE
488 >     * timed invokeAll(null) throws NullPointerException
489       */
490      public void testTimedInvokeAll1() throws InterruptedException {
491          final ExecutorService e = new DirectExecutorService();
492          try (PoolCleaner cleaner = cleaner(e)) {
493              try {
494 <                e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS);
494 >                e.invokeAll(null, randomTimeout(), randomTimeUnit());
495                  shouldThrow();
496              } catch (NullPointerException success) {}
497          }
# Line 497 | Line 503 | public class AbstractExecutorServiceTest
503      public void testTimedInvokeAllNullTimeUnit() throws InterruptedException {
504          final ExecutorService e = new DirectExecutorService();
505          try (PoolCleaner cleaner = cleaner(e)) {
506 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
506 >            List<Callable<String>> l = new ArrayList<>();
507              l.add(new StringTask());
508              try {
509 <                e.invokeAll(l, MEDIUM_DELAY_MS, null);
509 >                e.invokeAll(l, randomTimeout(), null);
510                  shouldThrow();
511              } catch (NullPointerException success) {}
512          }
513      }
514  
515      /**
516 <     * timed invokeAll(empty collection) returns empty collection
516 >     * timed invokeAll(empty collection) returns empty list
517       */
518      public void testTimedInvokeAll2() throws InterruptedException {
519          final ExecutorService e = new DirectExecutorService();
520 +        final Collection<Callable<String>> emptyCollection
521 +            = Collections.emptyList();
522          try (PoolCleaner cleaner = cleaner(e)) {
523 <            List<Future<String>> r = e.invokeAll(new ArrayList<Callable<String>>(), MEDIUM_DELAY_MS, MILLISECONDS);
523 >            List<Future<String>> r =
524 >                e.invokeAll(emptyCollection, randomTimeout(), randomTimeUnit());
525              assertTrue(r.isEmpty());
526          }
527      }
528  
529      /**
530 <     * timed invokeAll(c) throws NPE if c has null elements
530 >     * timed invokeAll(c) throws NullPointerException if c has null elements
531       */
532      public void testTimedInvokeAll3() throws InterruptedException {
533          final ExecutorService e = new DirectExecutorService();
534          try (PoolCleaner cleaner = cleaner(e)) {
535 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
535 >            List<Callable<String>> l = new ArrayList<>();
536              l.add(new StringTask());
537              l.add(null);
538              try {
539 <                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
539 >                e.invokeAll(l, randomTimeout(), randomTimeUnit());
540                  shouldThrow();
541              } catch (NullPointerException success) {}
542          }
# Line 539 | Line 548 | public class AbstractExecutorServiceTest
548      public void testTimedInvokeAll4() throws Exception {
549          final ExecutorService e = new DirectExecutorService();
550          try (PoolCleaner cleaner = cleaner(e)) {
551 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
551 >            List<Callable<String>> l = new ArrayList<>();
552              l.add(new NPETask());
553              List<Future<String>> futures =
554                  e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
# Line 559 | Line 568 | public class AbstractExecutorServiceTest
568      public void testTimedInvokeAll5() throws Exception {
569          final ExecutorService e = new DirectExecutorService();
570          try (PoolCleaner cleaner = cleaner(e)) {
571 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
571 >            List<Callable<String>> l = new ArrayList<>();
572              l.add(new StringTask());
573              l.add(new StringTask());
574              List<Future<String>> futures =

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines