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.57 by jsr166, Mon Jul 17 21:01:30 2017 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines