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.60 by jsr166, Mon May 9 20:00:19 2011 UTC vs.
Revision 1.72 by jsr166, Fri Feb 27 22:06:24 2015 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 import junit.framework.*;
10 import java.util.concurrent.atomic.AtomicBoolean;
11 import java.util.concurrent.locks.*;
12 import java.util.concurrent.*;
9   import static java.util.concurrent.TimeUnit.MILLISECONDS;
10 < import java.io.*;
11 < import java.util.*;
10 >
11 > import java.util.Arrays;
12 > import java.util.Collection;
13 > import java.util.HashSet;
14 > import java.util.concurrent.CountDownLatch;
15 > import java.util.concurrent.atomic.AtomicBoolean;
16 > import java.util.concurrent.locks.Condition;
17 > import java.util.concurrent.locks.Lock;
18 > import java.util.concurrent.locks.ReentrantReadWriteLock;
19 >
20 > import junit.framework.AssertionFailedError;
21 > import junit.framework.Test;
22 > import junit.framework.TestSuite;
23  
24   public class ReentrantReadWriteLockTest extends JSR166TestCase {
25      public static void main(String[] args) {
# Line 67 | Line 74 | public class ReentrantReadWriteLockTest
74       */
75      void releaseWriteLock(PublicReentrantReadWriteLock lock) {
76          ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();
77 <        assertWriteLockedBy(lock, Thread.currentThread());
77 >        assertWriteLockedByMoi(lock);
78          assertEquals(1, lock.getWriteHoldCount());
79          writeLock.unlock();
80          assertNotWriteLocked(lock);
# Line 80 | Line 87 | public class ReentrantReadWriteLockTest
87          long startTime = System.nanoTime();
88          while (!lock.hasQueuedThread(t)) {
89              if (millisElapsedSince(startTime) > LONG_DELAY_MS)
90 <                throw new AssertionError("timed out");
90 >                throw new AssertionFailedError("timed out");
91              Thread.yield();
92          }
93          assertTrue(t.isAlive());
94 <        assertTrue(lock.getOwner() != t);
94 >        assertNotSame(t, lock.getOwner());
95      }
96  
97      /**
# Line 94 | Line 101 | public class ReentrantReadWriteLockTest
101          assertFalse(lock.isWriteLocked());
102          assertFalse(lock.isWriteLockedByCurrentThread());
103          assertFalse(lock.writeLock().isHeldByCurrentThread());
97        assertNull(lock.getOwner());
104          assertEquals(0, lock.getWriteHoldCount());
105 +        assertEquals(0, lock.writeLock().getHoldCount());
106 +        assertNull(lock.getOwner());
107      }
108  
109      /**
# Line 110 | Line 118 | public class ReentrantReadWriteLockTest
118                       lock.writeLock().isHeldByCurrentThread());
119          assertEquals(t == Thread.currentThread(),
120                       lock.getWriteHoldCount() > 0);
121 +        assertEquals(t == Thread.currentThread(),
122 +                     lock.writeLock().getHoldCount() > 0);
123          assertEquals(0, lock.getReadLockCount());
124      }
125  
126      /**
127 +     * Checks that lock is write-locked by the current thread.
128 +     */
129 +    void assertWriteLockedByMoi(PublicReentrantReadWriteLock lock) {
130 +        assertWriteLockedBy(lock, Thread.currentThread());
131 +    }
132 +
133 +    /**
134       * Checks that condition c has no waiters.
135       */
136      void assertHasNoWaiters(PublicReentrantReadWriteLock lock, Condition c) {
# Line 135 | Line 152 | public class ReentrantReadWriteLockTest
152          lock.writeLock().unlock();
153      }
154  
155 <    enum AwaitMethod { await, awaitNanos, awaitUntil };
155 >    enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil }
156  
157      /**
158 <     * Awaits condition using the specified AwaitMethod
158 >     * Awaits condition using the specified AwaitMethod.
159       */
160      void await(Condition c, AwaitMethod awaitMethod)
161              throws InterruptedException {
# Line 146 | Line 163 | public class ReentrantReadWriteLockTest
163          case await:
164              c.await();
165              break;
166 +        case awaitTimed:
167 +            assertTrue(c.await(2 * LONG_DELAY_MS, MILLISECONDS));
168 +            break;
169          case awaitNanos:
170              long nanosRemaining = c.awaitNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS));
171              assertTrue(nanosRemaining > 0);
# Line 154 | Line 174 | public class ReentrantReadWriteLockTest
174              java.util.Date d = new java.util.Date();
175              assertTrue(c.awaitUntil(new java.util.Date(d.getTime() + 2 * LONG_DELAY_MS)));
176              break;
177 +        default:
178 +            throw new AssertionError();
179          }
180      }
181  
# Line 189 | Line 211 | public class ReentrantReadWriteLockTest
211              new PublicReentrantReadWriteLock(fair);
212          assertNotWriteLocked(lock);
213          lock.writeLock().lock();
214 <        assertWriteLockedBy(lock, Thread.currentThread());
214 >        assertWriteLockedByMoi(lock);
215          lock.writeLock().unlock();
216          assertNotWriteLocked(lock);
217          assertEquals(0, lock.getReadLockCount());
# Line 359 | Line 381 | public class ReentrantReadWriteLockTest
381      }
382  
383      /**
384 +     * write-tryLock on an unlocked lock succeeds
385 +     */
386 +    public void testWriteTryLock()      { testWriteTryLock(false); }
387 +    public void testWriteTryLock_fair() { testWriteTryLock(true); }
388 +    public void testWriteTryLock(boolean fair) {
389 +        final PublicReentrantReadWriteLock lock =
390 +            new PublicReentrantReadWriteLock(fair);
391 +        assertTrue(lock.writeLock().tryLock());
392 +        assertWriteLockedByMoi(lock);
393 +        assertTrue(lock.writeLock().tryLock());
394 +        assertWriteLockedByMoi(lock);
395 +        lock.writeLock().unlock();
396 +        releaseWriteLock(lock);
397 +    }
398 +
399 +    /**
400       * write-tryLock fails if locked
401       */
402      public void testWriteTryLockWhenLocked()      { testWriteTryLockWhenLocked(false); }
# Line 478 | Line 516 | public class ReentrantReadWriteLockTest
516  
517      /**
518       * A thread that tries to acquire a fair read lock (non-reentrantly)
519 <     * will block if there is a waiting writer thread.
519 >     * will block if there is a waiting writer thread
520       */
521      public void testReaderWriterReaderFairFifo() {
522          final PublicReentrantReadWriteLock lock =
# Line 555 | Line 593 | public class ReentrantReadWriteLockTest
593      }
594  
595      /**
596 <     * Read trylock succeeds (barging) even in the presence of waiting readers and/or writers.
596 >     * Read trylock succeeds (barging) even in the presence of waiting
597 >     * readers and/or writers
598       */
599      public void testReadTryLockBarging()      { testReadTryLockBarging(false); }
600      public void testReadTryLockBarging_fair() { testReadTryLockBarging(true); }
# Line 622 | Line 661 | public class ReentrantReadWriteLockTest
661  
662          waitForQueuedThread(lock, t1);
663          waitForQueuedThread(lock, t2);
664 <        assertWriteLockedBy(lock, Thread.currentThread());
664 >        assertWriteLockedByMoi(lock);
665          lock.readLock().lock();
666          lock.readLock().unlock();
667          releaseWriteLock(lock);
# Line 656 | Line 695 | public class ReentrantReadWriteLockTest
695  
696          waitForQueuedThread(lock, t1);
697          waitForQueuedThread(lock, t2);
698 <        assertWriteLockedBy(lock, Thread.currentThread());
698 >        assertWriteLockedByMoi(lock);
699          lock.readLock().lock();
700          lock.readLock().unlock();
701 <        assertWriteLockedBy(lock, Thread.currentThread());
701 >        assertWriteLockedByMoi(lock);
702          lock.writeLock().unlock();
703          awaitTermination(t1);
704          awaitTermination(t2);
# Line 691 | Line 730 | public class ReentrantReadWriteLockTest
730  
731          waitForQueuedThread(lock, t1);
732          waitForQueuedThread(lock, t2);
733 <        assertWriteLockedBy(lock, Thread.currentThread());
733 >        assertWriteLockedByMoi(lock);
734          assertEquals(1, lock.getWriteHoldCount());
735          lock.writeLock().lock();
736 <        assertWriteLockedBy(lock, Thread.currentThread());
736 >        assertWriteLockedByMoi(lock);
737          assertEquals(2, lock.getWriteHoldCount());
738          lock.writeLock().unlock();
739 <        assertWriteLockedBy(lock, Thread.currentThread());
739 >        assertWriteLockedByMoi(lock);
740          assertEquals(1, lock.getWriteHoldCount());
741          lock.writeLock().unlock();
742          awaitTermination(t1);
# Line 745 | Line 784 | public class ReentrantReadWriteLockTest
784      public void testWriteTryLock_Timeout()      { testWriteTryLock_Timeout(false); }
785      public void testWriteTryLock_Timeout_fair() { testWriteTryLock_Timeout(true); }
786      public void testWriteTryLock_Timeout(boolean fair) {
787 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
787 >        final PublicReentrantReadWriteLock lock =
788 >            new PublicReentrantReadWriteLock(fair);
789          lock.writeLock().lock();
790          Thread t = newStartedThread(new CheckedRunnable() {
791              public void realRun() throws InterruptedException {
# Line 756 | Line 796 | public class ReentrantReadWriteLockTest
796              }});
797  
798          awaitTermination(t);
799 <        assertTrue(lock.writeLock().isHeldByCurrentThread());
760 <        lock.writeLock().unlock();
799 >        releaseWriteLock(lock);
800      }
801  
802      /**
# Line 782 | Line 821 | public class ReentrantReadWriteLockTest
821      }
822  
823      /**
824 <     * write lockInterruptibly succeeds if lock free else is interruptible
824 >     * write lockInterruptibly succeeds if unlocked, else is interruptible
825       */
826      public void testWriteLockInterruptibly()      { testWriteLockInterruptibly(false); }
827      public void testWriteLockInterruptibly_fair() { testWriteLockInterruptibly(true); }
# Line 791 | Line 830 | public class ReentrantReadWriteLockTest
830              new PublicReentrantReadWriteLock(fair);
831          try {
832              lock.writeLock().lockInterruptibly();
833 <        } catch (Throwable t) {
795 <            threadUnexpectedException(t);
796 <        }
833 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
834          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
835              public void realRun() throws InterruptedException {
836                  lock.writeLock().lockInterruptibly();
# Line 801 | Line 838 | public class ReentrantReadWriteLockTest
838  
839          waitForQueuedThread(lock, t);
840          t.interrupt();
841 +        assertTrue(lock.writeLock().isHeldByCurrentThread());
842          awaitTermination(t);
843          releaseWriteLock(lock);
844      }
# Line 817 | Line 855 | public class ReentrantReadWriteLockTest
855              lock.readLock().lockInterruptibly();
856              lock.readLock().unlock();
857              lock.writeLock().lockInterruptibly();
858 <        } catch (Throwable t) {
821 <            threadUnexpectedException(t);
822 <        }
858 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
859          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
860              public void realRun() throws InterruptedException {
861                  lock.readLock().lockInterruptibly();
# Line 839 | Line 875 | public class ReentrantReadWriteLockTest
875      public void testAwait_IMSE(boolean fair) {
876          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
877          final Condition c = lock.writeLock().newCondition();
878 <        long startTime = System.nanoTime();
879 <        try {
844 <            try {
845 <                c.await();
846 <                shouldThrow();
847 <            } catch (IllegalMonitorStateException success) {}
848 <            try {
849 <                c.await(LONG_DELAY_MS, MILLISECONDS);
850 <                shouldThrow();
851 <            } catch (IllegalMonitorStateException success) {}
852 <            try {
853 <                c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
854 <                shouldThrow();
855 <            } catch (IllegalMonitorStateException success) {}
878 >        for (AwaitMethod awaitMethod : AwaitMethod.values()) {
879 >            long startTime = System.nanoTime();
880              try {
881 <                c.awaitUninterruptibly();
881 >                await(c, awaitMethod);
882                  shouldThrow();
883 <            } catch (IllegalMonitorStateException success) {}
884 <        } catch (Throwable t) {
885 <            threadUnexpectedException(t);
883 >            } catch (IllegalMonitorStateException success) {
884 >            } catch (InterruptedException fail) {
885 >                threadUnexpectedException(fail);
886 >            }
887 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
888          }
863        assertTrue(millisElapsedSince(startTime) < MEDIUM_DELAY_MS);
889      }
890  
891      /**
# Line 909 | Line 934 | public class ReentrantReadWriteLockTest
934              assertTrue(nanosRemaining <= 0);
935              assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
936              lock.writeLock().unlock();
937 <        } catch (InterruptedException e) {
913 <            threadUnexpectedException(e);
914 <        }
937 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
938      }
939  
940      /**
# Line 930 | Line 953 | public class ReentrantReadWriteLockTest
953              assertFalse(c.await(timeoutMillis, MILLISECONDS));
954              assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
955              lock.writeLock().unlock();
956 <        } catch (InterruptedException e) {
934 <            threadUnexpectedException(e);
935 <        }
956 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
957      }
958  
959      /**
# Line 952 | Line 973 | public class ReentrantReadWriteLockTest
973              assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + timeoutMillis)));
974              assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
975              lock.writeLock().unlock();
976 <        } catch (InterruptedException e) {
956 <            threadUnexpectedException(e);
957 <        }
976 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
977      }
978  
979      /**
# Line 986 | Line 1005 | public class ReentrantReadWriteLockTest
1005      }
1006  
1007      /**
1008 <     * awaitUninterruptibly doesn't abort on interrupt
1008 >     * awaitUninterruptibly is uninterruptible
1009       */
1010      public void testAwaitUninterruptibly()      { testAwaitUninterruptibly(false); }
1011      public void testAwaitUninterruptibly_fair() { testAwaitUninterruptibly(true); }
1012      public void testAwaitUninterruptibly(boolean fair) {
1013          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1014          final Condition c = lock.writeLock().newCondition();
1015 <        final CountDownLatch locked = new CountDownLatch(1);
1016 <        Thread t = newStartedThread(new CheckedRunnable() {
1015 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(2);
1016 >
1017 >        Thread t1 = newStartedThread(new CheckedRunnable() {
1018              public void realRun() {
1019 +                // Interrupt before awaitUninterruptibly
1020                  lock.writeLock().lock();
1021 <                locked.countDown();
1021 >                pleaseInterrupt.countDown();
1022 >                Thread.currentThread().interrupt();
1023                  c.awaitUninterruptibly();
1024                  assertTrue(Thread.interrupted());
1025                  lock.writeLock().unlock();
1026              }});
1027  
1028 <        await(locked);
1028 >        Thread t2 = newStartedThread(new CheckedRunnable() {
1029 >            public void realRun() {
1030 >                // Interrupt during awaitUninterruptibly
1031 >                lock.writeLock().lock();
1032 >                pleaseInterrupt.countDown();
1033 >                c.awaitUninterruptibly();
1034 >                assertTrue(Thread.interrupted());
1035 >                lock.writeLock().unlock();
1036 >            }});
1037 >
1038 >        await(pleaseInterrupt);
1039          lock.writeLock().lock();
1040          lock.writeLock().unlock();
1041 <        t.interrupt();
1042 <        long timeoutMillis = 10;
1043 <        assertThreadJoinTimesOut(t, timeoutMillis);
1041 >        t2.interrupt();
1042 >
1043 >        assertThreadStaysAlive(t1);
1044 >        assertTrue(t2.isAlive());
1045 >
1046          lock.writeLock().lock();
1047 <        c.signal();
1047 >        c.signalAll();
1048          lock.writeLock().unlock();
1049 <        awaitTermination(t);
1049 >
1050 >        awaitTermination(t1);
1051 >        awaitTermination(t2);
1052      }
1053  
1054      /**
# Line 1020 | Line 1056 | public class ReentrantReadWriteLockTest
1056       */
1057      public void testInterruptible_await()           { testInterruptible(false, AwaitMethod.await); }
1058      public void testInterruptible_await_fair()      { testInterruptible(true,  AwaitMethod.await); }
1059 +    public void testInterruptible_awaitTimed()      { testInterruptible(false, AwaitMethod.awaitTimed); }
1060 +    public void testInterruptible_awaitTimed_fair() { testInterruptible(true,  AwaitMethod.awaitTimed); }
1061      public void testInterruptible_awaitNanos()      { testInterruptible(false, AwaitMethod.awaitNanos); }
1062      public void testInterruptible_awaitNanos_fair() { testInterruptible(true,  AwaitMethod.awaitNanos); }
1063      public void testInterruptible_awaitUntil()      { testInterruptible(false, AwaitMethod.awaitUntil); }
# Line 1032 | Line 1070 | public class ReentrantReadWriteLockTest
1070          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
1071              public void realRun() throws InterruptedException {
1072                  lock.writeLock().lock();
1073 <                assertWriteLockedBy(lock, Thread.currentThread());
1073 >                assertWriteLockedByMoi(lock);
1074                  assertHasNoWaiters(lock, c);
1075                  locked.countDown();
1076                  try {
1077                      await(c, awaitMethod);
1078                  } finally {
1079 <                    assertWriteLockedBy(lock, Thread.currentThread());
1079 >                    assertWriteLockedByMoi(lock);
1080                      assertHasNoWaiters(lock, c);
1081                      lock.writeLock().unlock();
1082                      assertFalse(Thread.interrupted());
# Line 1057 | Line 1095 | public class ReentrantReadWriteLockTest
1095       */
1096      public void testSignalAll_await()           { testSignalAll(false, AwaitMethod.await); }
1097      public void testSignalAll_await_fair()      { testSignalAll(true,  AwaitMethod.await); }
1098 +    public void testSignalAll_awaitTimed()      { testSignalAll(false, AwaitMethod.awaitTimed); }
1099 +    public void testSignalAll_awaitTimed_fair() { testSignalAll(true,  AwaitMethod.awaitTimed); }
1100      public void testSignalAll_awaitNanos()      { testSignalAll(false, AwaitMethod.awaitNanos); }
1101      public void testSignalAll_awaitNanos_fair() { testSignalAll(true,  AwaitMethod.awaitNanos); }
1102      public void testSignalAll_awaitUntil()      { testSignalAll(false, AwaitMethod.awaitUntil); }
# Line 1090 | Line 1130 | public class ReentrantReadWriteLockTest
1130      }
1131  
1132      /**
1133 <     * signal wakes up waiting threads in FIFO order.
1133 >     * signal wakes up waiting threads in FIFO order
1134       */
1135      public void testSignalWakesFifo()      { testSignalWakesFifo(false); }
1136      public void testSignalWakesFifo_fair() { testSignalWakesFifo(true); }
# Line 1150 | Line 1190 | public class ReentrantReadWriteLockTest
1190          Thread t1 = newStartedThread(new CheckedRunnable() {
1191              public void realRun() throws InterruptedException {
1192                  lock.writeLock().lock();
1193 <                assertWriteLockedBy(lock, Thread.currentThread());
1193 >                assertWriteLockedByMoi(lock);
1194                  assertEquals(1, lock.writeLock().getHoldCount());
1195                  locked.countDown();
1196                  c.await();
1197 <                assertWriteLockedBy(lock, Thread.currentThread());
1197 >                assertWriteLockedByMoi(lock);
1198                  assertEquals(1, lock.writeLock().getHoldCount());
1199                  lock.writeLock().unlock();
1200              }});
# Line 1163 | Line 1203 | public class ReentrantReadWriteLockTest
1203              public void realRun() throws InterruptedException {
1204                  lock.writeLock().lock();
1205                  lock.writeLock().lock();
1206 <                assertWriteLockedBy(lock, Thread.currentThread());
1206 >                assertWriteLockedByMoi(lock);
1207                  assertEquals(2, lock.writeLock().getHoldCount());
1208                  locked.countDown();
1209                  c.await();
1210 <                assertWriteLockedBy(lock, Thread.currentThread());
1210 >                assertWriteLockedByMoi(lock);
1211                  assertEquals(2, lock.writeLock().getHoldCount());
1212                  lock.writeLock().unlock();
1213                  lock.writeLock().unlock();
# Line 1205 | Line 1245 | public class ReentrantReadWriteLockTest
1245          assertEquals(1, clone.getReadLockCount());
1246          clone.readLock().unlock();
1247          clone.writeLock().unlock();
1248 +        assertFalse(clone.isWriteLocked());
1249 +        assertEquals(1, lock.getReadLockCount());
1250 +        assertEquals(0, clone.getReadLockCount());
1251      }
1252  
1253      /**
# Line 1248 | Line 1291 | public class ReentrantReadWriteLockTest
1291      }
1292  
1293      /**
1294 <     * hasQueuedThread reports whether a thread is queued.
1294 >     * hasQueuedThread reports whether a thread is queued
1295       */
1296      public void testHasQueuedThread()      { testHasQueuedThread(false); }
1297      public void testHasQueuedThread_fair() { testHasQueuedThread(true); }
# Line 1589 | Line 1632 | public class ReentrantReadWriteLockTest
1632      public void testToString_fair() { testToString(true); }
1633      public void testToString(boolean fair) {
1634          ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1635 <        String us = lock.toString();
1636 <        assertTrue(us.indexOf("Write locks = 0") >= 0);
1637 <        assertTrue(us.indexOf("Read locks = 0") >= 0);
1638 <        lock.writeLock().lock();
1639 <        String ws = lock.toString();
1597 <        assertTrue(ws.indexOf("Write locks = 1") >= 0);
1598 <        assertTrue(ws.indexOf("Read locks = 0") >= 0);
1635 >        assertTrue(lock.toString().contains("Write locks = 0"));
1636 >        assertTrue(lock.toString().contains("Read locks = 0"));
1637 >        lock.writeLock().lock();
1638 >        assertTrue(lock.toString().contains("Write locks = 1"));
1639 >        assertTrue(lock.toString().contains("Read locks = 0"));
1640          lock.writeLock().unlock();
1641          lock.readLock().lock();
1642          lock.readLock().lock();
1643 <        String rs = lock.toString();
1644 <        assertTrue(rs.indexOf("Write locks = 0") >= 0);
1604 <        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1643 >        assertTrue(lock.toString().contains("Write locks = 0"));
1644 >        assertTrue(lock.toString().contains("Read locks = 2"));
1645      }
1646  
1647      /**
# Line 1611 | Line 1651 | public class ReentrantReadWriteLockTest
1651      public void testReadLockToString_fair() { testReadLockToString(true); }
1652      public void testReadLockToString(boolean fair) {
1653          ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1654 <        String us = lock.readLock().toString();
1615 <        assertTrue(us.indexOf("Read locks = 0") >= 0);
1654 >        assertTrue(lock.readLock().toString().contains("Read locks = 0"));
1655          lock.readLock().lock();
1656          lock.readLock().lock();
1657 <        String rs = lock.readLock().toString();
1619 <        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1657 >        assertTrue(lock.readLock().toString().contains("Read locks = 2"));
1658      }
1659  
1660      /**
# Line 1626 | Line 1664 | public class ReentrantReadWriteLockTest
1664      public void testWriteLockToString_fair() { testWriteLockToString(true); }
1665      public void testWriteLockToString(boolean fair) {
1666          ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1667 <        String us = lock.writeLock().toString();
1630 <        assertTrue(us.indexOf("Unlocked") >= 0);
1667 >        assertTrue(lock.writeLock().toString().contains("Unlocked"));
1668          lock.writeLock().lock();
1669 <        String ls = lock.writeLock().toString();
1670 <        assertTrue(ls.indexOf("Locked") >= 0);
1669 >        assertTrue(lock.writeLock().toString().contains("Locked"));
1670 >        lock.writeLock().unlock();
1671 >        assertTrue(lock.writeLock().toString().contains("Unlocked"));
1672      }
1673  
1674   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines