[cvs] / jsr166 / src / test / tck / FutureTaskTest.java Repository:
ViewVC logotype

Diff of /jsr166/src/test/tck/FutureTaskTest.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.38, Wed Jun 19 05:54:45 2013 UTC revision 1.42, Sat Feb 28 18:18:56 2015 UTC
# Line 6  Line 6 
6   * Pat Fisher, Mike Judd.   * Pat Fisher, Mike Judd.
7   */   */
8    
9  import junit.framework.*;  import static java.util.concurrent.TimeUnit.MILLISECONDS;
10    import static java.util.concurrent.TimeUnit.NANOSECONDS;
11    import static java.util.concurrent.TimeUnit.SECONDS;
12    
13    import java.util.ArrayList;
14    import java.util.List;
15    import java.util.NoSuchElementException;
16  import java.util.concurrent.Callable;  import java.util.concurrent.Callable;
17  import java.util.concurrent.CancellationException;  import java.util.concurrent.CancellationException;
18  import java.util.concurrent.CountDownLatch;  import java.util.concurrent.CountDownLatch;
19  import java.util.concurrent.ExecutionException;  import java.util.concurrent.ExecutionException;
20    import java.util.concurrent.Executors;
21    import java.util.concurrent.ExecutorService;
22  import java.util.concurrent.Future;  import java.util.concurrent.Future;
23  import java.util.concurrent.FutureTask;  import java.util.concurrent.FutureTask;
24  import java.util.concurrent.TimeoutException;  import java.util.concurrent.TimeoutException;
25  import java.util.concurrent.atomic.AtomicInteger;  import java.util.concurrent.atomic.AtomicInteger;
26  import static java.util.concurrent.TimeUnit.MILLISECONDS;  
27  import static java.util.concurrent.TimeUnit.SECONDS;  import junit.framework.Test;
28  import java.util.*;  import junit.framework.TestSuite;
29    
30  public class FutureTaskTest extends JSR166TestCase {  public class FutureTaskTest extends JSR166TestCase {
31    
# Line 127  Line 135 
135          pf.set(new Object());          pf.set(new Object());
136          pf.setException(new Error());          pf.setException(new Error());
137          for (boolean mayInterruptIfRunning : new boolean[] { true, false }) {          for (boolean mayInterruptIfRunning : new boolean[] { true, false }) {
138              pf.cancel(true);              pf.cancel(mayInterruptIfRunning);
139          }          }
140      }      }
141    
# Line 478  Line 486 
486          final PublicFutureTask task =          final PublicFutureTask task =
487              new PublicFutureTask(new Runnable() {              new PublicFutureTask(new Runnable() {
488                  public void run() {                  public void run() {
                     try {  
489                          pleaseCancel.countDown();                          pleaseCancel.countDown();
490                        try {
491                          delay(LONG_DELAY_MS);                          delay(LONG_DELAY_MS);
492                          threadShouldThrow();                          threadShouldThrow();
493                      } catch (InterruptedException success) {                      } catch (InterruptedException success) {
# Line 801  Line 809 
809          }          }
810      }      }
811    
812        /**
813         * timed get with most negative timeout works correctly (i.e. no
814         * underflow bug)
815         */
816        public void testGet_NegativeInfinityTimeout() throws Exception {
817            final ExecutorService pool = Executors.newFixedThreadPool(10);
818            final Runnable nop = new Runnable() { public void run() {}};
819            final FutureTask<Void> task = new FutureTask<>(nop, null);
820            final List<Future<?>> futures = new ArrayList<>();
821            Runnable r = new Runnable() { public void run() {
822                for (long timeout : new long[] { 0L, -1L, Long.MIN_VALUE }) {
823                    try {
824                        task.get(timeout, NANOSECONDS);
825                        shouldThrow();
826                    } catch (TimeoutException success) {
827                    } catch (Throwable fail) {threadUnexpectedException(fail);}}}};
828            for (int i = 0; i < 10; i++)
829                futures.add(pool.submit(r));
830            try {
831                joinPool(pool);
832                for (Future<?> future : futures)
833                    checkCompletedNormally(future, null);
834            } finally {
835                task.run();         // last resort to help terminate
836            }
837        }
838    
839  }  }

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.42

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8