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.40 by jsr166, Sun Oct 4 18:18:48 2015 UTC vs.
Revision 1.45 by jsr166, Wed Jan 4 06:09:58 2017 UTC

# Line 194 | Line 194 | public class AbstractExecutorServiceTest
194          final CountDownLatch quittingTime = new CountDownLatch(1);
195          final Callable<Void> awaiter = new CheckedCallable<Void>() {
196              public Void realCall() throws InterruptedException {
197 <                quittingTime.await();
197 >                assertTrue(quittingTime.await(2*LONG_DELAY_MS, MILLISECONDS));
198                  return null;
199              }};
200          final ExecutorService p
201              = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS,
202                                       new ArrayBlockingQueue<Runnable>(10));
203 <        try (PoolCleaner cleaner = cleaner(p)) {
204 <            Thread t = new Thread(new CheckedInterruptedRunnable() {
203 >        try (PoolCleaner cleaner = cleaner(p, quittingTime)) {
204 >            Thread t = newStartedThread(new CheckedInterruptedRunnable() {
205                  public void realRun() throws Exception {
206                      Future<Void> future = p.submit(awaiter);
207                      submitted.countDown();
208                      future.get();
209                  }});
210 <            t.start();
211 <            submitted.await();
210 >
211 >            await(submitted);
212              t.interrupt();
213 <            t.join();
214 <            quittingTime.countDown();
213 >            awaitTermination(t);
214          }
215      }
216  
# Line 268 | Line 267 | public class AbstractExecutorServiceTest
267      public void testInvokeAny3() throws Exception {
268          final ExecutorService e = new DirectExecutorService();
269          try (PoolCleaner cleaner = cleaner(e)) {
270 <            List<Callable<Long>> l = new ArrayList<Callable<Long>>();
270 >            List<Callable<Long>> l = new ArrayList<>();
271              l.add(new Callable<Long>() {
272                        public Long call() { throw new ArithmeticException(); }});
273              l.add(null);
# Line 285 | Line 284 | public class AbstractExecutorServiceTest
284      public void testInvokeAny4() throws InterruptedException {
285          final ExecutorService e = new DirectExecutorService();
286          try (PoolCleaner cleaner = cleaner(e)) {
287 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
287 >            List<Callable<String>> l = new ArrayList<>();
288              l.add(new NPETask());
289              try {
290                  e.invokeAny(l);
# Line 302 | Line 301 | public class AbstractExecutorServiceTest
301      public void testInvokeAny5() throws Exception {
302          final ExecutorService e = new DirectExecutorService();
303          try (PoolCleaner cleaner = cleaner(e)) {
304 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
304 >            List<Callable<String>> l = new ArrayList<>();
305              l.add(new StringTask());
306              l.add(new StringTask());
307              String result = e.invokeAny(l);
# Line 340 | Line 339 | public class AbstractExecutorServiceTest
339      public void testInvokeAll3() throws InterruptedException {
340          final ExecutorService e = new DirectExecutorService();
341          try (PoolCleaner cleaner = cleaner(e)) {
342 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
342 >            List<Callable<String>> l = new ArrayList<>();
343              l.add(new StringTask());
344              l.add(null);
345              try {
# Line 356 | Line 355 | public class AbstractExecutorServiceTest
355      public void testInvokeAll4() throws Exception {
356          final ExecutorService e = new DirectExecutorService();
357          try (PoolCleaner cleaner = cleaner(e)) {
358 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
358 >            List<Callable<String>> l = new ArrayList<>();
359              l.add(new NPETask());
360              List<Future<String>> futures = e.invokeAll(l);
361              assertEquals(1, futures.size());
# Line 375 | Line 374 | public class AbstractExecutorServiceTest
374      public void testInvokeAll5() throws Exception {
375          final ExecutorService e = new DirectExecutorService();
376          try (PoolCleaner cleaner = cleaner(e)) {
377 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
377 >            List<Callable<String>> l = new ArrayList<>();
378              l.add(new StringTask());
379              l.add(new StringTask());
380              List<Future<String>> futures = e.invokeAll(l);
# Line 404 | Line 403 | public class AbstractExecutorServiceTest
403      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
404          final ExecutorService e = new DirectExecutorService();
405          try (PoolCleaner cleaner = cleaner(e)) {
406 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
406 >            List<Callable<String>> l = new ArrayList<>();
407              l.add(new StringTask());
408              try {
409                  e.invokeAny(l, MEDIUM_DELAY_MS, null);
# Line 433 | Line 432 | public class AbstractExecutorServiceTest
432      public void testTimedInvokeAny3() throws Exception {
433          final ExecutorService e = new DirectExecutorService();
434          try (PoolCleaner cleaner = cleaner(e)) {
435 <            List<Callable<Long>> l = new ArrayList<Callable<Long>>();
435 >            List<Callable<Long>> l = new ArrayList<>();
436              l.add(new Callable<Long>() {
437                        public Long call() { throw new ArithmeticException(); }});
438              l.add(null);
# Line 450 | Line 449 | public class AbstractExecutorServiceTest
449      public void testTimedInvokeAny4() throws Exception {
450          final ExecutorService e = new DirectExecutorService();
451          try (PoolCleaner cleaner = cleaner(e)) {
452 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
452 >            long startTime = System.nanoTime();
453 >            List<Callable<String>> l = new ArrayList<>();
454              l.add(new NPETask());
455              try {
456 <                e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
456 >                e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
457                  shouldThrow();
458              } catch (ExecutionException success) {
459                  assertTrue(success.getCause() instanceof NullPointerException);
460              }
461 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
462          }
463      }
464  
# Line 467 | Line 468 | public class AbstractExecutorServiceTest
468      public void testTimedInvokeAny5() throws Exception {
469          final ExecutorService e = new DirectExecutorService();
470          try (PoolCleaner cleaner = cleaner(e)) {
471 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
471 >            long startTime = System.nanoTime();
472 >            List<Callable<String>> l = new ArrayList<>();
473              l.add(new StringTask());
474              l.add(new StringTask());
475 <            String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
475 >            String result = e.invokeAny(l, LONG_DELAY_MS, MILLISECONDS);
476              assertSame(TEST_STRING, result);
477 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
478          }
479      }
480  
# Line 494 | Line 497 | public class AbstractExecutorServiceTest
497      public void testTimedInvokeAllNullTimeUnit() throws InterruptedException {
498          final ExecutorService e = new DirectExecutorService();
499          try (PoolCleaner cleaner = cleaner(e)) {
500 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
500 >            List<Callable<String>> l = new ArrayList<>();
501              l.add(new StringTask());
502              try {
503                  e.invokeAll(l, MEDIUM_DELAY_MS, null);
# Line 520 | Line 523 | public class AbstractExecutorServiceTest
523      public void testTimedInvokeAll3() throws InterruptedException {
524          final ExecutorService e = new DirectExecutorService();
525          try (PoolCleaner cleaner = cleaner(e)) {
526 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
526 >            List<Callable<String>> l = new ArrayList<>();
527              l.add(new StringTask());
528              l.add(null);
529              try {
# Line 536 | Line 539 | public class AbstractExecutorServiceTest
539      public void testTimedInvokeAll4() throws Exception {
540          final ExecutorService e = new DirectExecutorService();
541          try (PoolCleaner cleaner = cleaner(e)) {
542 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
542 >            List<Callable<String>> l = new ArrayList<>();
543              l.add(new NPETask());
544              List<Future<String>> futures =
545 <                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
545 >                e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
546              assertEquals(1, futures.size());
547              try {
548                  futures.get(0).get();
# Line 556 | Line 559 | public class AbstractExecutorServiceTest
559      public void testTimedInvokeAll5() throws Exception {
560          final ExecutorService e = new DirectExecutorService();
561          try (PoolCleaner cleaner = cleaner(e)) {
562 <            List<Callable<String>> l = new ArrayList<Callable<String>>();
562 >            List<Callable<String>> l = new ArrayList<>();
563              l.add(new StringTask());
564              l.add(new StringTask());
565              List<Future<String>> futures =

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines