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.71 by jsr166, Fri Feb 27 21:43:18 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) {
834 <            threadUnexpectedException(t);
833 >        } catch (InterruptedException ie) {
834 >            threadUnexpectedException(ie);
835          }
836          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
837              public void realRun() throws InterruptedException {
# Line 801 | Line 840 | public class ReentrantReadWriteLockTest
840  
841          waitForQueuedThread(lock, t);
842          t.interrupt();
843 +        assertTrue(lock.writeLock().isHeldByCurrentThread());
844          awaitTermination(t);
845          releaseWriteLock(lock);
846      }
# Line 817 | Line 857 | public class ReentrantReadWriteLockTest
857              lock.readLock().lockInterruptibly();
858              lock.readLock().unlock();
859              lock.writeLock().lockInterruptibly();
860 <        } catch (Throwable t) {
861 <            threadUnexpectedException(t);
860 >        } catch (InterruptedException ie) {
861 >            threadUnexpectedException(ie);
862          }
863          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
864              public void realRun() throws InterruptedException {
# Line 839 | Line 879 | public class ReentrantReadWriteLockTest
879      public void testAwait_IMSE(boolean fair) {
880          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
881          final Condition c = lock.writeLock().newCondition();
882 <        long startTime = System.nanoTime();
883 <        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) {}
882 >        for (AwaitMethod awaitMethod : AwaitMethod.values()) {
883 >            long startTime = System.nanoTime();
884              try {
885 <                c.awaitUninterruptibly();
885 >                await(c, awaitMethod);
886                  shouldThrow();
887 <            } catch (IllegalMonitorStateException success) {}
888 <        } catch (Throwable t) {
889 <            threadUnexpectedException(t);
887 >            } catch (IllegalMonitorStateException success) {
888 >            } catch (InterruptedException e) { threadUnexpectedException(e); }
889 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
890          }
863        assertTrue(millisElapsedSince(startTime) < MEDIUM_DELAY_MS);
891      }
892  
893      /**
# Line 930 | Line 957 | public class ReentrantReadWriteLockTest
957              assertFalse(c.await(timeoutMillis, MILLISECONDS));
958              assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
959              lock.writeLock().unlock();
960 <        } catch (InterruptedException e) {
934 <            threadUnexpectedException(e);
935 <        }
960 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
961      }
962  
963      /**
# Line 952 | Line 977 | public class ReentrantReadWriteLockTest
977              assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + timeoutMillis)));
978              assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
979              lock.writeLock().unlock();
980 <        } catch (InterruptedException e) {
956 <            threadUnexpectedException(e);
957 <        }
980 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
981      }
982  
983      /**
# Line 986 | Line 1009 | public class ReentrantReadWriteLockTest
1009      }
1010  
1011      /**
1012 <     * awaitUninterruptibly doesn't abort on interrupt
1012 >     * awaitUninterruptibly is uninterruptible
1013       */
1014      public void testAwaitUninterruptibly()      { testAwaitUninterruptibly(false); }
1015      public void testAwaitUninterruptibly_fair() { testAwaitUninterruptibly(true); }
1016      public void testAwaitUninterruptibly(boolean fair) {
1017          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1018          final Condition c = lock.writeLock().newCondition();
1019 <        final CountDownLatch locked = new CountDownLatch(1);
1020 <        Thread t = newStartedThread(new CheckedRunnable() {
1019 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(2);
1020 >
1021 >        Thread t1 = newStartedThread(new CheckedRunnable() {
1022              public void realRun() {
1023 +                // Interrupt before awaitUninterruptibly
1024                  lock.writeLock().lock();
1025 <                locked.countDown();
1025 >                pleaseInterrupt.countDown();
1026 >                Thread.currentThread().interrupt();
1027                  c.awaitUninterruptibly();
1028                  assertTrue(Thread.interrupted());
1029                  lock.writeLock().unlock();
1030              }});
1031  
1032 <        await(locked);
1032 >        Thread t2 = newStartedThread(new CheckedRunnable() {
1033 >            public void realRun() {
1034 >                // Interrupt during awaitUninterruptibly
1035 >                lock.writeLock().lock();
1036 >                pleaseInterrupt.countDown();
1037 >                c.awaitUninterruptibly();
1038 >                assertTrue(Thread.interrupted());
1039 >                lock.writeLock().unlock();
1040 >            }});
1041 >
1042 >        await(pleaseInterrupt);
1043          lock.writeLock().lock();
1044          lock.writeLock().unlock();
1045 <        t.interrupt();
1046 <        long timeoutMillis = 10;
1047 <        assertThreadJoinTimesOut(t, timeoutMillis);
1045 >        t2.interrupt();
1046 >
1047 >        assertThreadStaysAlive(t1);
1048 >        assertTrue(t2.isAlive());
1049 >
1050          lock.writeLock().lock();
1051 <        c.signal();
1051 >        c.signalAll();
1052          lock.writeLock().unlock();
1053 <        awaitTermination(t);
1053 >
1054 >        awaitTermination(t1);
1055 >        awaitTermination(t2);
1056      }
1057  
1058      /**
# Line 1020 | Line 1060 | public class ReentrantReadWriteLockTest
1060       */
1061      public void testInterruptible_await()           { testInterruptible(false, AwaitMethod.await); }
1062      public void testInterruptible_await_fair()      { testInterruptible(true,  AwaitMethod.await); }
1063 +    public void testInterruptible_awaitTimed()      { testInterruptible(false, AwaitMethod.awaitTimed); }
1064 +    public void testInterruptible_awaitTimed_fair() { testInterruptible(true,  AwaitMethod.awaitTimed); }
1065      public void testInterruptible_awaitNanos()      { testInterruptible(false, AwaitMethod.awaitNanos); }
1066      public void testInterruptible_awaitNanos_fair() { testInterruptible(true,  AwaitMethod.awaitNanos); }
1067      public void testInterruptible_awaitUntil()      { testInterruptible(false, AwaitMethod.awaitUntil); }
# Line 1032 | Line 1074 | public class ReentrantReadWriteLockTest
1074          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
1075              public void realRun() throws InterruptedException {
1076                  lock.writeLock().lock();
1077 <                assertWriteLockedBy(lock, Thread.currentThread());
1077 >                assertWriteLockedByMoi(lock);
1078                  assertHasNoWaiters(lock, c);
1079                  locked.countDown();
1080                  try {
1081                      await(c, awaitMethod);
1082                  } finally {
1083 <                    assertWriteLockedBy(lock, Thread.currentThread());
1083 >                    assertWriteLockedByMoi(lock);
1084                      assertHasNoWaiters(lock, c);
1085                      lock.writeLock().unlock();
1086                      assertFalse(Thread.interrupted());
# Line 1057 | Line 1099 | public class ReentrantReadWriteLockTest
1099       */
1100      public void testSignalAll_await()           { testSignalAll(false, AwaitMethod.await); }
1101      public void testSignalAll_await_fair()      { testSignalAll(true,  AwaitMethod.await); }
1102 +    public void testSignalAll_awaitTimed()      { testSignalAll(false, AwaitMethod.awaitTimed); }
1103 +    public void testSignalAll_awaitTimed_fair() { testSignalAll(true,  AwaitMethod.awaitTimed); }
1104      public void testSignalAll_awaitNanos()      { testSignalAll(false, AwaitMethod.awaitNanos); }
1105      public void testSignalAll_awaitNanos_fair() { testSignalAll(true,  AwaitMethod.awaitNanos); }
1106      public void testSignalAll_awaitUntil()      { testSignalAll(false, AwaitMethod.awaitUntil); }
# Line 1090 | Line 1134 | public class ReentrantReadWriteLockTest
1134      }
1135  
1136      /**
1137 <     * signal wakes up waiting threads in FIFO order.
1137 >     * signal wakes up waiting threads in FIFO order
1138       */
1139      public void testSignalWakesFifo()      { testSignalWakesFifo(false); }
1140      public void testSignalWakesFifo_fair() { testSignalWakesFifo(true); }
# Line 1150 | Line 1194 | public class ReentrantReadWriteLockTest
1194          Thread t1 = newStartedThread(new CheckedRunnable() {
1195              public void realRun() throws InterruptedException {
1196                  lock.writeLock().lock();
1197 <                assertWriteLockedBy(lock, Thread.currentThread());
1197 >                assertWriteLockedByMoi(lock);
1198                  assertEquals(1, lock.writeLock().getHoldCount());
1199                  locked.countDown();
1200                  c.await();
1201 <                assertWriteLockedBy(lock, Thread.currentThread());
1201 >                assertWriteLockedByMoi(lock);
1202                  assertEquals(1, lock.writeLock().getHoldCount());
1203                  lock.writeLock().unlock();
1204              }});
# Line 1163 | Line 1207 | public class ReentrantReadWriteLockTest
1207              public void realRun() throws InterruptedException {
1208                  lock.writeLock().lock();
1209                  lock.writeLock().lock();
1210 <                assertWriteLockedBy(lock, Thread.currentThread());
1210 >                assertWriteLockedByMoi(lock);
1211                  assertEquals(2, lock.writeLock().getHoldCount());
1212                  locked.countDown();
1213                  c.await();
1214 <                assertWriteLockedBy(lock, Thread.currentThread());
1214 >                assertWriteLockedByMoi(lock);
1215                  assertEquals(2, lock.writeLock().getHoldCount());
1216                  lock.writeLock().unlock();
1217                  lock.writeLock().unlock();
# Line 1205 | Line 1249 | public class ReentrantReadWriteLockTest
1249          assertEquals(1, clone.getReadLockCount());
1250          clone.readLock().unlock();
1251          clone.writeLock().unlock();
1252 +        assertFalse(clone.isWriteLocked());
1253 +        assertEquals(1, lock.getReadLockCount());
1254 +        assertEquals(0, clone.getReadLockCount());
1255      }
1256  
1257      /**
# Line 1248 | Line 1295 | public class ReentrantReadWriteLockTest
1295      }
1296  
1297      /**
1298 <     * hasQueuedThread reports whether a thread is queued.
1298 >     * hasQueuedThread reports whether a thread is queued
1299       */
1300      public void testHasQueuedThread()      { testHasQueuedThread(false); }
1301      public void testHasQueuedThread_fair() { testHasQueuedThread(true); }
# Line 1589 | Line 1636 | public class ReentrantReadWriteLockTest
1636      public void testToString_fair() { testToString(true); }
1637      public void testToString(boolean fair) {
1638          ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1639 <        String us = lock.toString();
1640 <        assertTrue(us.indexOf("Write locks = 0") >= 0);
1641 <        assertTrue(us.indexOf("Read locks = 0") >= 0);
1642 <        lock.writeLock().lock();
1643 <        String ws = lock.toString();
1597 <        assertTrue(ws.indexOf("Write locks = 1") >= 0);
1598 <        assertTrue(ws.indexOf("Read locks = 0") >= 0);
1639 >        assertTrue(lock.toString().contains("Write locks = 0"));
1640 >        assertTrue(lock.toString().contains("Read locks = 0"));
1641 >        lock.writeLock().lock();
1642 >        assertTrue(lock.toString().contains("Write locks = 1"));
1643 >        assertTrue(lock.toString().contains("Read locks = 0"));
1644          lock.writeLock().unlock();
1645          lock.readLock().lock();
1646          lock.readLock().lock();
1647 <        String rs = lock.toString();
1648 <        assertTrue(rs.indexOf("Write locks = 0") >= 0);
1604 <        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1647 >        assertTrue(lock.toString().contains("Write locks = 0"));
1648 >        assertTrue(lock.toString().contains("Read locks = 2"));
1649      }
1650  
1651      /**
# Line 1611 | Line 1655 | public class ReentrantReadWriteLockTest
1655      public void testReadLockToString_fair() { testReadLockToString(true); }
1656      public void testReadLockToString(boolean fair) {
1657          ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1658 <        String us = lock.readLock().toString();
1615 <        assertTrue(us.indexOf("Read locks = 0") >= 0);
1658 >        assertTrue(lock.readLock().toString().contains("Read locks = 0"));
1659          lock.readLock().lock();
1660          lock.readLock().lock();
1661 <        String rs = lock.readLock().toString();
1619 <        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1661 >        assertTrue(lock.readLock().toString().contains("Read locks = 2"));
1662      }
1663  
1664      /**
# Line 1626 | Line 1668 | public class ReentrantReadWriteLockTest
1668      public void testWriteLockToString_fair() { testWriteLockToString(true); }
1669      public void testWriteLockToString(boolean fair) {
1670          ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1671 <        String us = lock.writeLock().toString();
1630 <        assertTrue(us.indexOf("Unlocked") >= 0);
1671 >        assertTrue(lock.writeLock().toString().contains("Unlocked"));
1672          lock.writeLock().lock();
1673 <        String ls = lock.writeLock().toString();
1674 <        assertTrue(ls.indexOf("Locked") >= 0);
1673 >        assertTrue(lock.writeLock().toString().contains("Locked"));
1674 >        lock.writeLock().unlock();
1675 >        assertTrue(lock.writeLock().toString().contains("Unlocked"));
1676      }
1677  
1678   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines