31 * http://creativecommons.org/publicdomain/zero/1.0/ |
31 * http://creativecommons.org/publicdomain/zero/1.0/ |
32 */ |
32 */ |
33 |
33 |
34 /* |
34 /* |
35 * @test |
35 * @test |
|
36 * @library /test/lib |
36 * @run main DoneTimedGetLoops 300 |
37 * @run main DoneTimedGetLoops 300 |
37 * @summary isDone returning true guarantees that subsequent timed get |
38 * @summary isDone returning true guarantees that subsequent timed get |
38 * will never throw TimeoutException. |
39 * will never throw TimeoutException. |
39 */ |
40 */ |
40 |
41 |
41 import java.util.concurrent.ExecutionException; |
42 import java.util.concurrent.ExecutionException; |
42 import java.util.concurrent.FutureTask; |
43 import java.util.concurrent.FutureTask; |
43 import java.util.concurrent.TimeUnit; |
44 import java.util.concurrent.TimeUnit; |
44 import java.util.concurrent.atomic.AtomicReference; |
45 import java.util.concurrent.atomic.AtomicReference; |
|
46 import jdk.test.lib.Utils; |
45 |
47 |
46 @SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) |
48 @SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) |
47 public class DoneTimedGetLoops { |
49 public class DoneTimedGetLoops { |
48 final long testDurationMillisDefault = 10L * 1000L; |
50 static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000); |
|
51 final long testDurationMillisDefault = 10_000L; |
49 final long testDurationMillis; |
52 final long testDurationMillis; |
50 |
53 |
51 static class PublicFutureTask extends FutureTask<Boolean> { |
54 static class PublicFutureTask extends FutureTask<Boolean> { |
52 static final Runnable noop = new Runnable() { public void run() {} }; |
55 static final Runnable noop = new Runnable() { public void run() {} }; |
53 PublicFutureTask() { super(noop, null); } |
56 PublicFutureTask() { super(noop, null); } |
61 } |
64 } |
62 |
65 |
63 void test(String[] args) throws Throwable { |
66 void test(String[] args) throws Throwable { |
64 final long testDurationNanos = testDurationMillis * 1000L * 1000L; |
67 final long testDurationNanos = testDurationMillis * 1000L * 1000L; |
65 final long quittingTimeNanos = System.nanoTime() + testDurationNanos; |
68 final long quittingTimeNanos = System.nanoTime() + testDurationNanos; |
66 final long timeoutMillis = 10L * 1000L; |
|
67 |
69 |
68 final AtomicReference<PublicFutureTask> normalRef |
70 final AtomicReference<PublicFutureTask> normalRef |
69 = new AtomicReference<>(); |
71 = new AtomicReference<>(); |
70 final AtomicReference<PublicFutureTask> abnormalRef |
72 final AtomicReference<PublicFutureTask> abnormalRef |
71 = new AtomicReference<>(); |
73 = new AtomicReference<>(); |
134 for (Thread thread : new Thread[] { |
136 for (Thread thread : new Thread[] { |
135 setter, |
137 setter, |
136 setterException, |
138 setterException, |
137 doneTimedGetNormal, |
139 doneTimedGetNormal, |
138 doneTimedGetAbnormal }) { |
140 doneTimedGetAbnormal }) { |
139 thread.join(timeoutMillis + testDurationMillis); |
141 thread.join(LONG_DELAY_MS + testDurationMillis); |
140 if (thread.isAlive()) { |
142 if (thread.isAlive()) { |
141 System.err.printf("Hung thread: %s%n", thread.getName()); |
143 System.err.printf("Hung thread: %s%n", thread.getName()); |
142 failed++; |
144 failed++; |
143 for (StackTraceElement e : thread.getStackTrace()) |
145 for (StackTraceElement e : thread.getStackTrace()) |
144 System.err.println(e); |
146 System.err.println(e); |
145 thread.join(timeoutMillis); |
147 thread.join(LONG_DELAY_MS); |
146 } |
148 } |
147 } |
149 } |
148 } |
150 } |
149 |
151 |
150 //--------------------- Infrastructure --------------------------- |
152 //--------------------- Infrastructure --------------------------- |