ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/JSR166TestCase.java
(Generate patch)

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.218 by jsr166, Sun Jan 29 20:19:00 2017 UTC vs.
Revision 1.219 by jsr166, Sat Feb 18 16:37:49 2017 UTC

# Line 1299 | Line 1299 | public class JSR166TestCase extends Test
1299                  startTime = System.nanoTime();
1300              else if (millisElapsedSince(startTime) > timeoutMillis) {
1301                  threadAssertTrue(thread.isAlive());
1302 <                return;
1302 >                fail("timed out waiting for thread to enter wait state");
1303              }
1304              Thread.yield();
1305          }
1306      }
1307  
1308      /**
1309 <     * Waits up to LONG_DELAY_MS for the given thread to enter a wait
1310 <     * state: BLOCKED, WAITING, or TIMED_WAITING.
1309 >     * Spin-waits up to the specified number of milliseconds for the given
1310 >     * thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING,
1311 >     * and additionally satisfy the given condition.
1312 >     */
1313 >    void waitForThreadToEnterWaitState(
1314 >        Thread thread, long timeoutMillis, Callable<Boolean> waitingForGodot) {
1315 >        long startTime = 0L;
1316 >        for (;;) {
1317 >            Thread.State s = thread.getState();
1318 >            if (s == Thread.State.BLOCKED ||
1319 >                s == Thread.State.WAITING ||
1320 >                s == Thread.State.TIMED_WAITING) {
1321 >                try {
1322 >                    if (waitingForGodot.call())
1323 >                        return;
1324 >                } catch (Throwable fail) { threadUnexpectedException(fail); }
1325 >            }
1326 >            else if (s == Thread.State.TERMINATED)
1327 >                fail("Unexpected thread termination");
1328 >            else if (startTime == 0L)
1329 >                startTime = System.nanoTime();
1330 >            else if (millisElapsedSince(startTime) > timeoutMillis) {
1331 >                threadAssertTrue(thread.isAlive());
1332 >                fail("timed out waiting for thread to enter wait state");
1333 >            }
1334 >            Thread.yield();
1335 >        }
1336 >    }
1337 >
1338 >    /**
1339 >     * Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to
1340 >     * enter a wait state: BLOCKED, WAITING, or TIMED_WAITING.
1341       */
1342      void waitForThreadToEnterWaitState(Thread thread) {
1343          waitForThreadToEnterWaitState(thread, LONG_DELAY_MS);
1344      }
1345  
1346      /**
1347 +     * Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to
1348 +     * enter a wait state: BLOCKED, WAITING, or TIMED_WAITING,
1349 +     * and additionally satisfy the given condition.
1350 +     */
1351 +    void waitForThreadToEnterWaitState(
1352 +        Thread thread, Callable<Boolean> waitingForGodot) {
1353 +        waitForThreadToEnterWaitState(thread, LONG_DELAY_MS, waitingForGodot);
1354 +    }
1355 +
1356 +    /**
1357       * Returns the number of milliseconds since time given by
1358       * startNanoTime, which must have been previously returned from a
1359       * call to {@link System#nanoTime()}.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines