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.47 by jsr166, Sun May 15 17:30:21 2011 UTC vs.
Revision 1.48 by jsr166, Sat May 21 06:24:33 2011 UTC

# 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 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) {}
489 >        for (AwaitMethod awaitMethod : AwaitMethod.values()) {
490 >            long startTime = System.nanoTime();
491              try {
492 <                c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
492 >                await(c, awaitMethod);
493                  shouldThrow();
494 <            } catch (IllegalMonitorStateException success) {}
495 <            try {
496 <                c.awaitUninterruptibly();
501 <                shouldThrow();
502 <            } catch (IllegalMonitorStateException success) {}
503 <        } catch (InterruptedException ie) {
504 <            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); }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines