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

Comparing jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java (file contents):
Revision 1.51 by jsr166, Fri Jul 3 01:56:38 2015 UTC vs.
Revision 1.56 by jsr166, Sun May 14 02:24:10 2017 UTC

# Line 238 | Line 238 | public class AbstractQueuedSynchronizerT
238       * default timeout duration).
239       */
240      void assertAwaitTimesOut(ConditionObject c, AwaitMethod awaitMethod) {
241 <        long timeoutMillis = timeoutMillis();
242 <        long startTime = System.nanoTime();
241 >        final long timeoutMillis = timeoutMillis();
242 >        final long startTime;
243          try {
244              switch (awaitMethod) {
245              case awaitTimed:
246 +                startTime = System.nanoTime();
247                  assertFalse(c.await(timeoutMillis, MILLISECONDS));
248 +                assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
249                  break;
250              case awaitNanos:
251 +                startTime = System.nanoTime();
252                  long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
253                  long nanosRemaining = c.awaitNanos(nanosTimeout);
254                  assertTrue(nanosRemaining <= 0);
255                  assertTrue(nanosRemaining > -MILLISECONDS.toNanos(LONG_DELAY_MS));
256 +                assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
257                  break;
258              case awaitUntil:
259 +                // We shouldn't assume that nanoTime and currentTimeMillis
260 +                // use the same time source, so don't use nanoTime here.
261 +                java.util.Date delayedDate = delayedDate(timeoutMillis);
262                  assertFalse(c.awaitUntil(delayedDate(timeoutMillis)));
263 +                assertTrue(new java.util.Date().getTime() >= delayedDate.getTime());
264                  break;
265              default:
266                  throw new UnsupportedOperationException();
267              }
268          } catch (InterruptedException ie) { threadUnexpectedException(ie); }
261        assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
269      }
270  
271      /**
# Line 961 | Line 968 | public class AbstractQueuedSynchronizerT
968       */
969      public void testAwaitUninterruptibly() {
970          final Mutex sync = new Mutex();
971 <        final ConditionObject c = sync.newCondition();
971 >        final ConditionObject condition = sync.newCondition();
972          final BooleanLatch pleaseInterrupt = new BooleanLatch();
973          Thread t = newStartedThread(new CheckedRunnable() {
974              public void realRun() {
975                  sync.acquire();
976                  assertTrue(pleaseInterrupt.releaseShared(0));
977 <                c.awaitUninterruptibly();
977 >                condition.awaitUninterruptibly();
978                  assertTrue(Thread.interrupted());
979 <                assertHasWaitersLocked(sync, c, NO_THREADS);
979 >                assertHasWaitersLocked(sync, condition, NO_THREADS);
980                  sync.release();
981              }});
982  
983          pleaseInterrupt.acquireShared(0);
984          sync.acquire();
985 <        assertHasWaitersLocked(sync, c, t);
985 >        assertHasWaitersLocked(sync, condition, t);
986          sync.release();
987          t.interrupt();
988 <        assertHasWaitersUnlocked(sync, c, t);
989 <        assertThreadStaysAlive(t);
988 >        assertHasWaitersUnlocked(sync, condition, t);
989 >        assertThreadBlocks(t, Thread.State.WAITING);
990          sync.acquire();
991 <        assertHasWaitersLocked(sync, c, t);
991 >        assertHasWaitersLocked(sync, condition, t);
992          assertHasExclusiveQueuedThreads(sync, NO_THREADS);
993 <        c.signal();
994 <        assertHasWaitersLocked(sync, c, NO_THREADS);
993 >        condition.signal();
994 >        assertHasWaitersLocked(sync, condition, NO_THREADS);
995          assertHasExclusiveQueuedThreads(sync, t);
996          sync.release();
997          awaitTermination(t);
# Line 1127 | Line 1134 | public class AbstractQueuedSynchronizerT
1134  
1135          waitForQueuedThread(l, t);
1136          assertFalse(l.isSignalled());
1137 <        assertThreadStaysAlive(t);
1137 >        assertThreadBlocks(t, Thread.State.WAITING);
1138          assertHasSharedQueuedThreads(l, t);
1139          assertTrue(l.releaseShared(0));
1140          assertTrue(l.isSignalled());
# Line 1152 | Line 1159 | public class AbstractQueuedSynchronizerT
1159  
1160          waitForQueuedThread(l, t);
1161          assertFalse(l.isSignalled());
1162 <        assertThreadStaysAlive(t);
1162 >        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
1163          assertTrue(l.releaseShared(0));
1164          assertTrue(l.isSignalled());
1165          awaitTermination(t);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines