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.63 by jsr166, Sat May 21 06:24:33 2011 UTC vs.
Revision 1.65 by jsr166, Tue May 31 16:16:24 2011 UTC

# Line 8 | Line 8
8  
9   import junit.framework.*;
10   import java.util.concurrent.atomic.AtomicBoolean;
11 < import java.util.concurrent.locks.*;
12 < import java.util.concurrent.*;
11 > import java.util.concurrent.locks.Condition;
12 > import java.util.concurrent.locks.Lock;
13 > import java.util.concurrent.locks.ReentrantReadWriteLock;
14 > import java.util.concurrent.CountDownLatch;
15   import static java.util.concurrent.TimeUnit.MILLISECONDS;
14 import java.io.*;
16   import java.util.*;
17  
18   public class ReentrantReadWriteLockTest extends JSR166TestCase {
# Line 507 | Line 508 | public class ReentrantReadWriteLockTest
508  
509      /**
510       * A thread that tries to acquire a fair read lock (non-reentrantly)
511 <     * will block if there is a waiting writer thread.
511 >     * will block if there is a waiting writer thread
512       */
513      public void testReaderWriterReaderFairFifo() {
514          final PublicReentrantReadWriteLock lock =
# Line 584 | Line 585 | public class ReentrantReadWriteLockTest
585      }
586  
587      /**
588 <     * Read trylock succeeds (barging) even in the presence of waiting readers and/or writers.
588 >     * Read trylock succeeds (barging) even in the presence of waiting
589 >     * readers and/or writers
590       */
591      public void testReadTryLockBarging()      { testReadTryLockBarging(false); }
592      public void testReadTryLockBarging_fair() { testReadTryLockBarging(true); }
# Line 1111 | Line 1113 | public class ReentrantReadWriteLockTest
1113      }
1114  
1115      /**
1116 <     * signal wakes up waiting threads in FIFO order.
1116 >     * signal wakes up waiting threads in FIFO order
1117       */
1118      public void testSignalWakesFifo()      { testSignalWakesFifo(false); }
1119      public void testSignalWakesFifo_fair() { testSignalWakesFifo(true); }
# Line 1272 | Line 1274 | public class ReentrantReadWriteLockTest
1274      }
1275  
1276      /**
1277 <     * hasQueuedThread reports whether a thread is queued.
1277 >     * hasQueuedThread reports whether a thread is queued
1278       */
1279      public void testHasQueuedThread()      { testHasQueuedThread(false); }
1280      public void testHasQueuedThread_fair() { testHasQueuedThread(true); }
# Line 1613 | Line 1615 | public class ReentrantReadWriteLockTest
1615      public void testToString_fair() { testToString(true); }
1616      public void testToString(boolean fair) {
1617          ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1618 <        String us = lock.toString();
1619 <        assertTrue(us.indexOf("Write locks = 0") >= 0);
1620 <        assertTrue(us.indexOf("Read locks = 0") >= 0);
1621 <        lock.writeLock().lock();
1622 <        String ws = lock.toString();
1621 <        assertTrue(ws.indexOf("Write locks = 1") >= 0);
1622 <        assertTrue(ws.indexOf("Read locks = 0") >= 0);
1618 >        assertTrue(lock.toString().contains("Write locks = 0"));
1619 >        assertTrue(lock.toString().contains("Read locks = 0"));
1620 >        lock.writeLock().lock();
1621 >        assertTrue(lock.toString().contains("Write locks = 1"));
1622 >        assertTrue(lock.toString().contains("Read locks = 0"));
1623          lock.writeLock().unlock();
1624          lock.readLock().lock();
1625          lock.readLock().lock();
1626 <        String rs = lock.toString();
1627 <        assertTrue(rs.indexOf("Write locks = 0") >= 0);
1628 <        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1626 >        assertTrue(lock.toString().contains("Write locks = 0"));
1627 >        assertTrue(lock.toString().contains("Read locks = 2"));
1628      }
1629  
1630      /**
# Line 1635 | Line 1634 | public class ReentrantReadWriteLockTest
1634      public void testReadLockToString_fair() { testReadLockToString(true); }
1635      public void testReadLockToString(boolean fair) {
1636          ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1637 <        String us = lock.readLock().toString();
1639 <        assertTrue(us.indexOf("Read locks = 0") >= 0);
1637 >        assertTrue(lock.readLock().toString().contains("Read locks = 0"));
1638          lock.readLock().lock();
1639          lock.readLock().lock();
1640 <        String rs = lock.readLock().toString();
1643 <        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1640 >        assertTrue(lock.readLock().toString().contains("Read locks = 2"));
1641      }
1642  
1643      /**
# Line 1650 | Line 1647 | public class ReentrantReadWriteLockTest
1647      public void testWriteLockToString_fair() { testWriteLockToString(true); }
1648      public void testWriteLockToString(boolean fair) {
1649          ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1650 <        String us = lock.writeLock().toString();
1654 <        assertTrue(us.indexOf("Unlocked") >= 0);
1650 >        assertTrue(lock.writeLock().toString().contains("Unlocked"));
1651          lock.writeLock().lock();
1652 <        String ls = lock.writeLock().toString();
1653 <        assertTrue(ls.indexOf("Locked") >= 0);
1652 >        assertTrue(lock.writeLock().toString().contains("Locked"));
1653 >        lock.writeLock().unlock();
1654 >        assertTrue(lock.writeLock().toString().contains("Unlocked"));
1655      }
1656  
1657   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines