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

Comparing jsr166/src/test/tck/ReentrantLockTest.java (file contents):
Revision 1.46 by jsr166, Fri May 13 21:48:59 2011 UTC vs.
Revision 1.49 by jsr166, Tue May 24 23:40:14 2011 UTC

# Line 78 | Line 78 | public class ReentrantLockTest extends J
78          long startTime = System.nanoTime();
79          while (!lock.hasQueuedThread(t)) {
80              if (millisElapsedSince(startTime) > LONG_DELAY_MS)
81 <                throw new AssertionError("timed out");
81 >                throw new AssertionFailedError("timed out");
82              Thread.yield();
83          }
84          assertTrue(t.isAlive());
# Line 136 | Line 136 | public class ReentrantLockTest extends J
136          lock.unlock();
137      }
138  
139 <    enum AwaitMethod { await, awaitNanos, awaitUntil };
139 >    enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil };
140  
141      /**
142       * Awaits condition using the specified AwaitMethod.
143       */
144      void await(Condition c, AwaitMethod awaitMethod)
145              throws InterruptedException {
146 +        long timeoutMillis = 2 * LONG_DELAY_MS;
147          switch (awaitMethod) {
148          case await:
149              c.await();
150              break;
151 +        case awaitTimed:
152 +            assertTrue(c.await(timeoutMillis, MILLISECONDS));
153 +            break;
154          case awaitNanos:
155 <            long nanosRemaining = c.awaitNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS));
155 >            long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
156 >            long nanosRemaining = c.awaitNanos(nanosTimeout);
157              assertTrue(nanosRemaining > 0);
158              break;
159          case awaitUntil:
160 <            java.util.Date d = new java.util.Date();
156 <            assertTrue(c.awaitUntil(new java.util.Date(d.getTime() + 2 * LONG_DELAY_MS)));
160 >            assertTrue(c.awaitUntil(delayedDate(timeoutMillis)));
161              break;
162          }
163      }
# Line 282 | Line 286 | public class ReentrantLockTest extends J
286      }
287  
288      /**
289 <     * hasQueuedThread reports whether a thread is queued.
289 >     * hasQueuedThread reports whether a thread is queued
290       */
291      public void testHasQueuedThread()      { testHasQueuedThread(false); }
292      public void testHasQueuedThread_fair() { testHasQueuedThread(true); }
# Line 343 | Line 347 | public class ReentrantLockTest extends J
347      }
348  
349      /**
350 <     * timed tryLock is interruptible.
350 >     * timed tryLock is interruptible
351       */
352      public void testTryLock_Interruptible()      { testTryLock_Interruptible(false); }
353      public void testTryLock_Interruptible_fair() { testTryLock_Interruptible(true); }
# Line 482 | Line 486 | public class ReentrantLockTest extends J
486      public void testAwait_IMSE(boolean fair) {
487          final ReentrantLock lock = new ReentrantLock(fair);
488          final Condition c = lock.newCondition();
489 <        long startTime = System.nanoTime();
490 <        try {
487 <            try {
488 <                c.await();
489 <                shouldThrow();
490 <            } catch (IllegalMonitorStateException success) {}
491 <            try {
492 <                c.await(LONG_DELAY_MS, MILLISECONDS);
493 <                shouldThrow();
494 <            } catch (IllegalMonitorStateException success) {}
495 <            try {
496 <                c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
497 <                shouldThrow();
498 <            } catch (IllegalMonitorStateException success) {}
489 >        for (AwaitMethod awaitMethod : AwaitMethod.values()) {
490 >            long startTime = System.nanoTime();
491              try {
492 <                c.awaitUninterruptibly();
492 >                await(c, awaitMethod);
493                  shouldThrow();
494 <            } catch (IllegalMonitorStateException success) {}
495 <        } catch (InterruptedException ie) {
496 <            threadUnexpectedException(ie);
494 >            } catch (IllegalMonitorStateException success) {
495 >            } catch (InterruptedException e) { threadUnexpectedException(e); }
496 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
497          }
506        assertTrue(millisElapsedSince(startTime) < MEDIUM_DELAY_MS);
498      }
499  
500      /**
# Line 922 | Line 913 | public class ReentrantLockTest extends J
913       */
914      public void testInterruptible_await()           { testInterruptible(false, AwaitMethod.await); }
915      public void testInterruptible_await_fair()      { testInterruptible(true,  AwaitMethod.await); }
916 +    public void testInterruptible_awaitTimed()      { testInterruptible(false, AwaitMethod.awaitTimed); }
917 +    public void testInterruptible_awaitTimed_fair() { testInterruptible(true,  AwaitMethod.awaitTimed); }
918      public void testInterruptible_awaitNanos()      { testInterruptible(false, AwaitMethod.awaitNanos); }
919      public void testInterruptible_awaitNanos_fair() { testInterruptible(true,  AwaitMethod.awaitNanos); }
920      public void testInterruptible_awaitUntil()      { testInterruptible(false, AwaitMethod.awaitUntil); }
# Line 959 | Line 952 | public class ReentrantLockTest extends J
952       */
953      public void testSignalAll_await()           { testSignalAll(false, AwaitMethod.await); }
954      public void testSignalAll_await_fair()      { testSignalAll(true,  AwaitMethod.await); }
955 +    public void testSignalAll_awaitTimed()      { testSignalAll(false, AwaitMethod.awaitTimed); }
956 +    public void testSignalAll_awaitTimed_fair() { testSignalAll(true,  AwaitMethod.awaitTimed); }
957      public void testSignalAll_awaitNanos()      { testSignalAll(false, AwaitMethod.awaitNanos); }
958      public void testSignalAll_awaitNanos_fair() { testSignalAll(true,  AwaitMethod.awaitNanos); }
959      public void testSignalAll_awaitUntil()      { testSignalAll(false, AwaitMethod.awaitUntil); }
# Line 990 | Line 985 | public class ReentrantLockTest extends J
985      }
986  
987      /**
988 <     * signal wakes up waiting threads in FIFO order.
988 >     * signal wakes up waiting threads in FIFO order
989       */
990      public void testSignalWakesFifo()      { testSignalWakesFifo(false); }
991      public void testSignalWakesFifo_fair() { testSignalWakesFifo(true); }
# Line 1115 | Line 1110 | public class ReentrantLockTest extends J
1110      public void testToString_fair() { testToString(true); }
1111      public void testToString(boolean fair) {
1112          ReentrantLock lock = new ReentrantLock(fair);
1113 <        String us = lock.toString();
1119 <        assertTrue(us.indexOf("Unlocked") >= 0);
1113 >        assertTrue(lock.toString().contains("Unlocked"));
1114          lock.lock();
1115 <        String ls = lock.toString();
1116 <        assertTrue(ls.indexOf("Locked") >= 0);
1115 >        assertTrue(lock.toString().contains("Locked"));
1116 >        lock.unlock();
1117 >        assertTrue(lock.toString().contains("Unlocked"));
1118      }
1119   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines