21 |
|
|
22 |
|
public class AbstractQueuedLongSynchronizerTest extends JSR166TestCase { |
23 |
|
public static void main(String[] args) { |
24 |
< |
junit.textui.TestRunner.run(suite()); |
24 |
> |
main(suite(), args); |
25 |
|
} |
26 |
|
public static Test suite() { |
27 |
|
return new TestSuite(AbstractQueuedLongSynchronizerTest.class); |
94 |
|
} |
95 |
|
|
96 |
|
public boolean tryReleaseShared(long ignore) { |
97 |
< |
setState(1 << 62); |
97 |
> |
setState(1L << 62); |
98 |
|
return true; |
99 |
|
} |
100 |
|
} |
202 |
|
new HashSet<Thread>(Arrays.asList(threads))); |
203 |
|
} |
204 |
|
|
205 |
< |
enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil }; |
205 |
> |
enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil } |
206 |
|
|
207 |
|
/** |
208 |
|
* Awaits condition using the specified AwaitMethod. |
225 |
|
case awaitUntil: |
226 |
|
assertTrue(c.awaitUntil(delayedDate(timeoutMillis))); |
227 |
|
break; |
228 |
+ |
default: |
229 |
+ |
throw new AssertionError(); |
230 |
|
} |
231 |
|
} |
232 |
|
|
236 |
|
*/ |
237 |
|
void assertAwaitTimesOut(ConditionObject c, AwaitMethod awaitMethod) { |
238 |
|
long timeoutMillis = timeoutMillis(); |
239 |
< |
long startTime = System.nanoTime(); |
239 |
> |
long startTime; |
240 |
|
try { |
241 |
|
switch (awaitMethod) { |
242 |
|
case awaitTimed: |
243 |
+ |
startTime = System.nanoTime(); |
244 |
|
assertFalse(c.await(timeoutMillis, MILLISECONDS)); |
245 |
+ |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
246 |
|
break; |
247 |
|
case awaitNanos: |
248 |
+ |
startTime = System.nanoTime(); |
249 |
|
long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis); |
250 |
|
long nanosRemaining = c.awaitNanos(nanosTimeout); |
251 |
|
assertTrue(nanosRemaining <= 0); |
252 |
+ |
assertTrue(nanosRemaining > -MILLISECONDS.toNanos(LONG_DELAY_MS)); |
253 |
+ |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
254 |
|
break; |
255 |
|
case awaitUntil: |
256 |
+ |
// We shouldn't assume that nanoTime and currentTimeMillis |
257 |
+ |
// use the same time source, so don't use nanoTime here. |
258 |
+ |
java.util.Date delayedDate = delayedDate(timeoutMillis()); |
259 |
|
assertFalse(c.awaitUntil(delayedDate(timeoutMillis))); |
260 |
+ |
assertTrue(new java.util.Date().getTime() >= delayedDate.getTime()); |
261 |
|
break; |
262 |
|
default: |
263 |
|
throw new UnsupportedOperationException(); |
264 |
|
} |
265 |
|
} catch (InterruptedException ie) { threadUnexpectedException(ie); } |
255 |
– |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
266 |
|
} |
267 |
|
|
268 |
|
/** |
1205 |
|
public void testTryAcquireSharedNanos_Timeout() { |
1206 |
|
final BooleanLatch l = new BooleanLatch(); |
1207 |
|
final BooleanLatch observedQueued = new BooleanLatch(); |
1198 |
– |
final long timeoutMillis = timeoutMillis(); |
1208 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1209 |
|
public void realRun() throws InterruptedException { |
1210 |
|
assertFalse(l.isSignalled()); |