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

Comparing jsr166/src/test/tck/ReentrantReadWriteLockTest.java (file contents):
Revision 1.62 by jsr166, Sun May 15 17:30:21 2011 UTC vs.
Revision 1.64 by jsr166, Tue May 24 23:40:14 2011 UTC

# Line 145 | Line 145 | public class ReentrantReadWriteLockTest
145          lock.writeLock().unlock();
146      }
147  
148 <    enum AwaitMethod { await, awaitNanos, awaitUntil };
148 >    enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil };
149  
150      /**
151       * Awaits condition using the specified AwaitMethod.
# Line 156 | Line 156 | public class ReentrantReadWriteLockTest
156          case await:
157              c.await();
158              break;
159 +        case awaitTimed:
160 +            assertTrue(c.await(2 * LONG_DELAY_MS, MILLISECONDS));
161 +            break;
162          case awaitNanos:
163              long nanosRemaining = c.awaitNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS));
164              assertTrue(nanosRemaining > 0);
# Line 504 | Line 507 | public class ReentrantReadWriteLockTest
507  
508      /**
509       * A thread that tries to acquire a fair read lock (non-reentrantly)
510 <     * will block if there is a waiting writer thread.
510 >     * will block if there is a waiting writer thread
511       */
512      public void testReaderWriterReaderFairFifo() {
513          final PublicReentrantReadWriteLock lock =
# Line 581 | Line 584 | public class ReentrantReadWriteLockTest
584      }
585  
586      /**
587 <     * Read trylock succeeds (barging) even in the presence of waiting readers and/or writers.
587 >     * Read trylock succeeds (barging) even in the presence of waiting
588 >     * readers and/or writers
589       */
590      public void testReadTryLockBarging()      { testReadTryLockBarging(false); }
591      public void testReadTryLockBarging_fair() { testReadTryLockBarging(true); }
# Line 866 | Line 870 | public class ReentrantReadWriteLockTest
870      public void testAwait_IMSE(boolean fair) {
871          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
872          final Condition c = lock.writeLock().newCondition();
873 <        long startTime = System.nanoTime();
874 <        try {
871 <            try {
872 <                c.await();
873 <                shouldThrow();
874 <            } catch (IllegalMonitorStateException success) {}
875 <            try {
876 <                c.await(LONG_DELAY_MS, MILLISECONDS);
877 <                shouldThrow();
878 <            } catch (IllegalMonitorStateException success) {}
879 <            try {
880 <                c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
881 <                shouldThrow();
882 <            } catch (IllegalMonitorStateException success) {}
873 >        for (AwaitMethod awaitMethod : AwaitMethod.values()) {
874 >            long startTime = System.nanoTime();
875              try {
876 <                c.awaitUninterruptibly();
876 >                await(c, awaitMethod);
877                  shouldThrow();
878 <            } catch (IllegalMonitorStateException success) {}
879 <        } catch (InterruptedException ie) {
880 <            threadUnexpectedException(ie);
878 >            } catch (IllegalMonitorStateException success) {
879 >            } catch (InterruptedException e) { threadUnexpectedException(e); }
880 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
881          }
890        assertTrue(millisElapsedSince(startTime) < MEDIUM_DELAY_MS);
882      }
883  
884      /**
# Line 1047 | Line 1038 | public class ReentrantReadWriteLockTest
1038       */
1039      public void testInterruptible_await()           { testInterruptible(false, AwaitMethod.await); }
1040      public void testInterruptible_await_fair()      { testInterruptible(true,  AwaitMethod.await); }
1041 +    public void testInterruptible_awaitTimed()      { testInterruptible(false, AwaitMethod.awaitTimed); }
1042 +    public void testInterruptible_awaitTimed_fair() { testInterruptible(true,  AwaitMethod.awaitTimed); }
1043      public void testInterruptible_awaitNanos()      { testInterruptible(false, AwaitMethod.awaitNanos); }
1044      public void testInterruptible_awaitNanos_fair() { testInterruptible(true,  AwaitMethod.awaitNanos); }
1045      public void testInterruptible_awaitUntil()      { testInterruptible(false, AwaitMethod.awaitUntil); }
# Line 1084 | Line 1077 | public class ReentrantReadWriteLockTest
1077       */
1078      public void testSignalAll_await()           { testSignalAll(false, AwaitMethod.await); }
1079      public void testSignalAll_await_fair()      { testSignalAll(true,  AwaitMethod.await); }
1080 +    public void testSignalAll_awaitTimed()      { testSignalAll(false, AwaitMethod.awaitTimed); }
1081 +    public void testSignalAll_awaitTimed_fair() { testSignalAll(true,  AwaitMethod.awaitTimed); }
1082      public void testSignalAll_awaitNanos()      { testSignalAll(false, AwaitMethod.awaitNanos); }
1083      public void testSignalAll_awaitNanos_fair() { testSignalAll(true,  AwaitMethod.awaitNanos); }
1084      public void testSignalAll_awaitUntil()      { testSignalAll(false, AwaitMethod.awaitUntil); }
# Line 1117 | Line 1112 | public class ReentrantReadWriteLockTest
1112      }
1113  
1114      /**
1115 <     * signal wakes up waiting threads in FIFO order.
1115 >     * signal wakes up waiting threads in FIFO order
1116       */
1117      public void testSignalWakesFifo()      { testSignalWakesFifo(false); }
1118      public void testSignalWakesFifo_fair() { testSignalWakesFifo(true); }
# Line 1278 | Line 1273 | public class ReentrantReadWriteLockTest
1273      }
1274  
1275      /**
1276 <     * hasQueuedThread reports whether a thread is queued.
1276 >     * hasQueuedThread reports whether a thread is queued
1277       */
1278      public void testHasQueuedThread()      { testHasQueuedThread(false); }
1279      public void testHasQueuedThread_fair() { testHasQueuedThread(true); }
# Line 1619 | Line 1614 | public class ReentrantReadWriteLockTest
1614      public void testToString_fair() { testToString(true); }
1615      public void testToString(boolean fair) {
1616          ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1617 <        String us = lock.toString();
1618 <        assertTrue(us.indexOf("Write locks = 0") >= 0);
1619 <        assertTrue(us.indexOf("Read locks = 0") >= 0);
1620 <        lock.writeLock().lock();
1621 <        String ws = lock.toString();
1627 <        assertTrue(ws.indexOf("Write locks = 1") >= 0);
1628 <        assertTrue(ws.indexOf("Read locks = 0") >= 0);
1617 >        assertTrue(lock.toString().contains("Write locks = 0"));
1618 >        assertTrue(lock.toString().contains("Read locks = 0"));
1619 >        lock.writeLock().lock();
1620 >        assertTrue(lock.toString().contains("Write locks = 1"));
1621 >        assertTrue(lock.toString().contains("Read locks = 0"));
1622          lock.writeLock().unlock();
1623          lock.readLock().lock();
1624          lock.readLock().lock();
1625 <        String rs = lock.toString();
1626 <        assertTrue(rs.indexOf("Write locks = 0") >= 0);
1634 <        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1625 >        assertTrue(lock.toString().contains("Write locks = 0"));
1626 >        assertTrue(lock.toString().contains("Read locks = 2"));
1627      }
1628  
1629      /**
# Line 1641 | Line 1633 | public class ReentrantReadWriteLockTest
1633      public void testReadLockToString_fair() { testReadLockToString(true); }
1634      public void testReadLockToString(boolean fair) {
1635          ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1636 <        String us = lock.readLock().toString();
1645 <        assertTrue(us.indexOf("Read locks = 0") >= 0);
1636 >        assertTrue(lock.readLock().toString().contains("Read locks = 0"));
1637          lock.readLock().lock();
1638          lock.readLock().lock();
1639 <        String rs = lock.readLock().toString();
1649 <        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1639 >        assertTrue(lock.readLock().toString().contains("Read locks = 2"));
1640      }
1641  
1642      /**
# Line 1656 | Line 1646 | public class ReentrantReadWriteLockTest
1646      public void testWriteLockToString_fair() { testWriteLockToString(true); }
1647      public void testWriteLockToString(boolean fair) {
1648          ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1649 <        String us = lock.writeLock().toString();
1660 <        assertTrue(us.indexOf("Unlocked") >= 0);
1649 >        assertTrue(lock.writeLock().toString().contains("Unlocked"));
1650          lock.writeLock().lock();
1651 <        String ls = lock.writeLock().toString();
1652 <        assertTrue(ls.indexOf("Locked") >= 0);
1651 >        assertTrue(lock.writeLock().toString().contains("Locked"));
1652 >        lock.writeLock().unlock();
1653 >        assertTrue(lock.writeLock().toString().contains("Unlocked"));
1654      }
1655  
1656   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines