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.46 by jsr166, Fri May 13 21:48:59 2011 UTC vs.
Revision 1.66 by jsr166, Mon Jul 17 21:01:30 2017 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 import junit.framework.*;
10 import java.util.concurrent.locks.*;
11 import java.util.concurrent.*;
9   import static java.util.concurrent.TimeUnit.MILLISECONDS;
13 import java.util.*;
14 import java.io.*;
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.CyclicBarrier;
16 + import java.util.concurrent.locks.Condition;
17 + import java.util.concurrent.locks.ReentrantLock;
18 +
19 + import junit.framework.AssertionFailedError;
20 + import junit.framework.Test;
21 + import junit.framework.TestSuite;
22 +
23 + @SuppressWarnings("WaitNotInLoop") // we implement spurious-wakeup freedom
24   public class ReentrantLockTest extends JSR166TestCase {
25      public static void main(String[] args) {
26 <        junit.textui.TestRunner.run(suite());
26 >        main(suite(), args);
27      }
28      public static Test suite() {
29          return new TestSuite(ReentrantLockTest.class);
30      }
31  
32      /**
33 <     * A runnable calling lockInterruptibly
33 >     * A checked runnable calling lockInterruptibly
34       */
35      class InterruptibleLockRunnable extends CheckedRunnable {
36          final ReentrantLock lock;
37 <        InterruptibleLockRunnable(ReentrantLock l) { lock = l; }
37 >        InterruptibleLockRunnable(ReentrantLock lock) { this.lock = lock; }
38          public void realRun() throws InterruptedException {
39              lock.lockInterruptibly();
40          }
41      }
42  
43      /**
44 <     * A runnable calling lockInterruptibly that expects to be
44 >     * A checked runnable calling lockInterruptibly that expects to be
45       * interrupted
46       */
47      class InterruptedLockRunnable extends CheckedInterruptedRunnable {
48          final ReentrantLock lock;
49 <        InterruptedLockRunnable(ReentrantLock l) { lock = l; }
49 >        InterruptedLockRunnable(ReentrantLock lock) { this.lock = lock; }
50          public void realRun() throws InterruptedException {
51              lock.lockInterruptibly();
52          }
# Line 78 | Line 86 | public class ReentrantLockTest extends J
86          long startTime = System.nanoTime();
87          while (!lock.hasQueuedThread(t)) {
88              if (millisElapsedSince(startTime) > LONG_DELAY_MS)
89 <                throw new AssertionError("timed out");
89 >                throw new AssertionFailedError("timed out");
90              Thread.yield();
91          }
92          assertTrue(t.isAlive());
93 <        assertTrue(lock.getOwner() != t);
93 >        assertNotSame(t, lock.getOwner());
94      }
95  
96      /**
# Line 136 | Line 144 | public class ReentrantLockTest extends J
144          lock.unlock();
145      }
146  
147 <    enum AwaitMethod { await, awaitNanos, awaitUntil };
147 >    enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil }
148  
149      /**
150 <     * Awaits condition using the specified AwaitMethod.
150 >     * Awaits condition "indefinitely" using the specified AwaitMethod.
151       */
152      void await(Condition c, AwaitMethod awaitMethod)
153              throws InterruptedException {
154 +        long timeoutMillis = 2 * LONG_DELAY_MS;
155          switch (awaitMethod) {
156          case await:
157              c.await();
158              break;
159 +        case awaitTimed:
160 +            assertTrue(c.await(timeoutMillis, MILLISECONDS));
161 +            break;
162          case awaitNanos:
163 <            long nanosRemaining = c.awaitNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS));
164 <            assertTrue(nanosRemaining > 0);
163 >            long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
164 >            long nanosRemaining = c.awaitNanos(timeoutNanos);
165 >            assertTrue(nanosRemaining > timeoutNanos / 2);
166 >            assertTrue(nanosRemaining <= timeoutNanos);
167              break;
168          case awaitUntil:
169 <            java.util.Date d = new java.util.Date();
156 <            assertTrue(c.awaitUntil(new java.util.Date(d.getTime() + 2 * LONG_DELAY_MS)));
169 >            assertTrue(c.awaitUntil(delayedDate(timeoutMillis)));
170              break;
171 +        default:
172 +            throw new AssertionError();
173          }
174      }
175  
# Line 195 | Line 210 | public class ReentrantLockTest extends J
210      public void testUnlock_IMSE()      { testUnlock_IMSE(false); }
211      public void testUnlock_IMSE_fair() { testUnlock_IMSE(true); }
212      public void testUnlock_IMSE(boolean fair) {
213 <        ReentrantLock lock = new ReentrantLock(fair);
213 >        final ReentrantLock lock = new ReentrantLock(fair);
214          try {
215              lock.unlock();
216              shouldThrow();
# Line 282 | Line 297 | public class ReentrantLockTest extends J
297      }
298  
299      /**
300 <     * hasQueuedThread reports whether a thread is queued.
300 >     * hasQueuedThread reports whether a thread is queued
301       */
302      public void testHasQueuedThread()      { testHasQueuedThread(false); }
303      public void testHasQueuedThread_fair() { testHasQueuedThread(true); }
# Line 343 | Line 358 | public class ReentrantLockTest extends J
358      }
359  
360      /**
361 <     * timed tryLock is interruptible.
361 >     * timed tryLock is interruptible
362       */
363      public void testTryLock_Interruptible()      { testTryLock_Interruptible(false); }
364      public void testTryLock_Interruptible_fair() { testTryLock_Interruptible(true); }
# Line 385 | Line 400 | public class ReentrantLockTest extends J
400      public void testTryLock_Timeout_fair() { testTryLock_Timeout(true); }
401      public void testTryLock_Timeout(boolean fair) {
402          final PublicReentrantLock lock = new PublicReentrantLock(fair);
403 +        final long timeoutMillis = timeoutMillis();
404          lock.lock();
405          Thread t = newStartedThread(new CheckedRunnable() {
406              public void realRun() throws InterruptedException {
407                  long startTime = System.nanoTime();
392                long timeoutMillis = 10;
408                  assertFalse(lock.tryLock(timeoutMillis, MILLISECONDS));
409                  assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
410              }});
# Line 404 | Line 419 | public class ReentrantLockTest extends J
419      public void testGetHoldCount()      { testGetHoldCount(false); }
420      public void testGetHoldCount_fair() { testGetHoldCount(true); }
421      public void testGetHoldCount(boolean fair) {
422 <        ReentrantLock lock = new ReentrantLock(fair);
422 >        final ReentrantLock lock = new ReentrantLock(fair);
423          for (int i = 1; i <= SIZE; i++) {
424              lock.lock();
425              assertEquals(i, lock.getHoldCount());
426          }
427          for (int i = SIZE; i > 0; i--) {
428              lock.unlock();
429 <            assertEquals(i-1, lock.getHoldCount());
429 >            assertEquals(i - 1, lock.getHoldCount());
430          }
431      }
432  
# Line 421 | Line 436 | public class ReentrantLockTest extends J
436      public void testIsLocked()      { testIsLocked(false); }
437      public void testIsLocked_fair() { testIsLocked(true); }
438      public void testIsLocked(boolean fair) {
439 +        final ReentrantLock lock = new ReentrantLock(fair);
440          try {
425            final ReentrantLock lock = new ReentrantLock(fair);
441              assertFalse(lock.isLocked());
442              lock.lock();
443              assertTrue(lock.isLocked());
# Line 447 | Line 462 | public class ReentrantLockTest extends J
462              barrier.await();
463              awaitTermination(t);
464              assertFalse(lock.isLocked());
465 <        } catch (Exception e) {
451 <            threadUnexpectedException(e);
452 <        }
465 >        } catch (Exception fail) { threadUnexpectedException(fail); }
466      }
467  
468      /**
# Line 461 | Line 474 | public class ReentrantLockTest extends J
474          final PublicReentrantLock lock = new PublicReentrantLock(fair);
475          try {
476              lock.lockInterruptibly();
477 <        } catch (InterruptedException ie) {
465 <            threadUnexpectedException(ie);
466 <        }
477 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
478          assertLockedByMoi(lock);
479          Thread t = newStartedThread(new InterruptedLockRunnable(lock));
480          waitForQueuedThread(lock, t);
# Line 482 | Line 493 | public class ReentrantLockTest extends J
493      public void testAwait_IMSE(boolean fair) {
494          final ReentrantLock lock = new ReentrantLock(fair);
495          final Condition c = lock.newCondition();
496 <        long startTime = System.nanoTime();
497 <        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) {}
495 <            try {
496 <                c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
497 <                shouldThrow();
498 <            } catch (IllegalMonitorStateException success) {}
496 >        for (AwaitMethod awaitMethod : AwaitMethod.values()) {
497 >            long startTime = System.nanoTime();
498              try {
499 <                c.awaitUninterruptibly();
499 >                await(c, awaitMethod);
500                  shouldThrow();
501 <            } catch (IllegalMonitorStateException success) {}
502 <        } catch (InterruptedException ie) {
503 <            threadUnexpectedException(ie);
501 >            } catch (IllegalMonitorStateException success) {
502 >            } catch (InterruptedException e) { threadUnexpectedException(e); }
503 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
504          }
506        assertTrue(millisElapsedSince(startTime) < MEDIUM_DELAY_MS);
505      }
506  
507      /**
# Line 526 | Line 524 | public class ReentrantLockTest extends J
524      public void testAwaitNanos_Timeout()      { testAwaitNanos_Timeout(false); }
525      public void testAwaitNanos_Timeout_fair() { testAwaitNanos_Timeout(true); }
526      public void testAwaitNanos_Timeout(boolean fair) {
527 +        final ReentrantLock lock = new ReentrantLock(fair);
528 +        final Condition c = lock.newCondition();
529 +        final long timeoutMillis = timeoutMillis();
530 +        final long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
531 +        lock.lock();
532 +        final long startTime = System.nanoTime();
533          try {
530            final ReentrantLock lock = new ReentrantLock(fair);
531            final Condition c = lock.newCondition();
532            lock.lock();
533            long startTime = System.nanoTime();
534            long timeoutMillis = 10;
535            long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
534              long nanosRemaining = c.awaitNanos(timeoutNanos);
535              assertTrue(nanosRemaining <= 0);
536 <            assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
537 <            lock.unlock();
538 <        } catch (InterruptedException e) {
541 <            threadUnexpectedException(e);
542 <        }
536 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
537 >        assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
538 >        lock.unlock();
539      }
540  
541      /**
# Line 548 | Line 544 | public class ReentrantLockTest extends J
544      public void testAwait_Timeout()      { testAwait_Timeout(false); }
545      public void testAwait_Timeout_fair() { testAwait_Timeout(true); }
546      public void testAwait_Timeout(boolean fair) {
547 +        final ReentrantLock lock = new ReentrantLock(fair);
548 +        final Condition c = lock.newCondition();
549 +        final long timeoutMillis = timeoutMillis();
550 +        lock.lock();
551 +        final long startTime = System.nanoTime();
552          try {
552            final ReentrantLock lock = new ReentrantLock(fair);
553            final Condition c = lock.newCondition();
554            lock.lock();
555            long startTime = System.nanoTime();
556            long timeoutMillis = 10;
553              assertFalse(c.await(timeoutMillis, MILLISECONDS));
554 <            assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
555 <            lock.unlock();
556 <        } catch (InterruptedException e) {
561 <            threadUnexpectedException(e);
562 <        }
554 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
555 >        assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
556 >        lock.unlock();
557      }
558  
559      /**
# Line 568 | Line 562 | public class ReentrantLockTest extends J
562      public void testAwaitUntil_Timeout()      { testAwaitUntil_Timeout(false); }
563      public void testAwaitUntil_Timeout_fair() { testAwaitUntil_Timeout(true); }
564      public void testAwaitUntil_Timeout(boolean fair) {
565 +        final ReentrantLock lock = new ReentrantLock(fair);
566 +        final Condition c = lock.newCondition();
567 +        lock.lock();
568 +        // We shouldn't assume that nanoTime and currentTimeMillis
569 +        // use the same time source, so don't use nanoTime here.
570 +        final java.util.Date delayedDate = delayedDate(timeoutMillis());
571          try {
572 <            final ReentrantLock lock = new ReentrantLock(fair);
573 <            final Condition c = lock.newCondition();
574 <            lock.lock();
575 <            long startTime = System.nanoTime();
576 <            long timeoutMillis = 10;
577 <            java.util.Date d = new java.util.Date();
578 <            assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + timeoutMillis)));
579 <            assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
580 <            lock.unlock();
581 <        } catch (InterruptedException e) {
582 <            threadUnexpectedException(e);
583 <        }
572 >            assertFalse(c.awaitUntil(delayedDate));
573 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
574 >        assertTrue(new java.util.Date().getTime() >= delayedDate.getTime());
575 >        lock.unlock();
576      }
577  
578      /**
# Line 744 | Line 736 | public class ReentrantLockTest extends J
736      public void testHasWaiters(boolean fair) {
737          final PublicReentrantLock lock = new PublicReentrantLock(fair);
738          final Condition c = lock.newCondition();
739 <        final CountDownLatch locked = new CountDownLatch(1);
739 >        final CountDownLatch pleaseSignal = new CountDownLatch(1);
740          Thread t = newStartedThread(new CheckedRunnable() {
741              public void realRun() throws InterruptedException {
742                  lock.lock();
743                  assertHasNoWaiters(lock, c);
744                  assertFalse(lock.hasWaiters(c));
745 <                locked.countDown();
745 >                pleaseSignal.countDown();
746                  c.await();
747                  assertHasNoWaiters(lock, c);
748                  assertFalse(lock.hasWaiters(c));
749                  lock.unlock();
750              }});
751  
752 <        await(locked);
752 >        await(pleaseSignal);
753          lock.lock();
754          assertHasWaiters(lock, c, t);
755          assertTrue(lock.hasWaiters(c));
# Line 888 | Line 880 | public class ReentrantLockTest extends J
880      }
881  
882      /**
883 <     * awaitUninterruptibly doesn't abort on interrupt
883 >     * awaitUninterruptibly is uninterruptible
884       */
885      public void testAwaitUninterruptibly()      { testAwaitUninterruptibly(false); }
886      public void testAwaitUninterruptibly_fair() { testAwaitUninterruptibly(true); }
887      public void testAwaitUninterruptibly(boolean fair) {
888          final ReentrantLock lock = new ReentrantLock(fair);
889 <        final Condition c = lock.newCondition();
890 <        final CountDownLatch locked = new CountDownLatch(1);
891 <        Thread t = newStartedThread(new CheckedRunnable() {
889 >        final Condition condition = lock.newCondition();
890 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(2);
891 >
892 >        Thread t1 = newStartedThread(new CheckedRunnable() {
893              public void realRun() {
894 +                // Interrupt before awaitUninterruptibly
895                  lock.lock();
896 <                locked.countDown();
897 <                c.awaitUninterruptibly();
896 >                pleaseInterrupt.countDown();
897 >                Thread.currentThread().interrupt();
898 >                condition.awaitUninterruptibly();
899                  assertTrue(Thread.interrupted());
900                  lock.unlock();
901              }});
902  
903 <        await(locked);
903 >        Thread t2 = newStartedThread(new CheckedRunnable() {
904 >            public void realRun() {
905 >                // Interrupt during awaitUninterruptibly
906 >                lock.lock();
907 >                pleaseInterrupt.countDown();
908 >                condition.awaitUninterruptibly();
909 >                assertTrue(Thread.interrupted());
910 >                lock.unlock();
911 >            }});
912 >
913 >        await(pleaseInterrupt);
914 >        t2.interrupt();
915          lock.lock();
916          lock.unlock();
917 <        t.interrupt();
918 <        long timeoutMillis = 10;
919 <        assertThreadStaysAlive(t, timeoutMillis);
917 >        assertThreadBlocks(t1, Thread.State.WAITING);
918 >        assertThreadBlocks(t2, Thread.State.WAITING);
919 >
920          lock.lock();
921 <        c.signal();
921 >        condition.signalAll();
922          lock.unlock();
923 <        awaitTermination(t);
923 >
924 >        awaitTermination(t1);
925 >        awaitTermination(t2);
926      }
927  
928      /**
# Line 922 | Line 930 | public class ReentrantLockTest extends J
930       */
931      public void testInterruptible_await()           { testInterruptible(false, AwaitMethod.await); }
932      public void testInterruptible_await_fair()      { testInterruptible(true,  AwaitMethod.await); }
933 +    public void testInterruptible_awaitTimed()      { testInterruptible(false, AwaitMethod.awaitTimed); }
934 +    public void testInterruptible_awaitTimed_fair() { testInterruptible(true,  AwaitMethod.awaitTimed); }
935      public void testInterruptible_awaitNanos()      { testInterruptible(false, AwaitMethod.awaitNanos); }
936      public void testInterruptible_awaitNanos_fair() { testInterruptible(true,  AwaitMethod.awaitNanos); }
937      public void testInterruptible_awaitUntil()      { testInterruptible(false, AwaitMethod.awaitUntil); }
# Line 930 | Line 940 | public class ReentrantLockTest extends J
940          final PublicReentrantLock lock =
941              new PublicReentrantLock(fair);
942          final Condition c = lock.newCondition();
943 <        final CountDownLatch locked = new CountDownLatch(1);
943 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
944          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
945              public void realRun() throws InterruptedException {
946                  lock.lock();
947                  assertLockedByMoi(lock);
948                  assertHasNoWaiters(lock, c);
949 <                locked.countDown();
949 >                pleaseInterrupt.countDown();
950                  try {
951                      await(c, awaitMethod);
952                  } finally {
# Line 947 | Line 957 | public class ReentrantLockTest extends J
957                  }
958              }});
959  
960 <        await(locked);
960 >        await(pleaseInterrupt);
961          assertHasWaiters(lock, c, t);
962          t.interrupt();
963          awaitTermination(t);
# Line 959 | Line 969 | public class ReentrantLockTest extends J
969       */
970      public void testSignalAll_await()           { testSignalAll(false, AwaitMethod.await); }
971      public void testSignalAll_await_fair()      { testSignalAll(true,  AwaitMethod.await); }
972 +    public void testSignalAll_awaitTimed()      { testSignalAll(false, AwaitMethod.awaitTimed); }
973 +    public void testSignalAll_awaitTimed_fair() { testSignalAll(true,  AwaitMethod.awaitTimed); }
974      public void testSignalAll_awaitNanos()      { testSignalAll(false, AwaitMethod.awaitNanos); }
975      public void testSignalAll_awaitNanos_fair() { testSignalAll(true,  AwaitMethod.awaitNanos); }
976      public void testSignalAll_awaitUntil()      { testSignalAll(false, AwaitMethod.awaitUntil); }
# Line 966 | Line 978 | public class ReentrantLockTest extends J
978      public void testSignalAll(boolean fair, final AwaitMethod awaitMethod) {
979          final PublicReentrantLock lock = new PublicReentrantLock(fair);
980          final Condition c = lock.newCondition();
981 <        final CountDownLatch locked = new CountDownLatch(2);
981 >        final CountDownLatch pleaseSignal = new CountDownLatch(2);
982          class Awaiter extends CheckedRunnable {
983              public void realRun() throws InterruptedException {
984                  lock.lock();
985 <                locked.countDown();
985 >                pleaseSignal.countDown();
986                  await(c, awaitMethod);
987                  lock.unlock();
988              }
# Line 979 | Line 991 | public class ReentrantLockTest extends J
991          Thread t1 = newStartedThread(new Awaiter());
992          Thread t2 = newStartedThread(new Awaiter());
993  
994 <        await(locked);
994 >        await(pleaseSignal);
995          lock.lock();
996          assertHasWaiters(lock, c, t1, t2);
997          c.signalAll();
# Line 990 | Line 1002 | public class ReentrantLockTest extends J
1002      }
1003  
1004      /**
1005 <     * signal wakes up waiting threads in FIFO order.
1005 >     * signal wakes up waiting threads in FIFO order
1006       */
1007      public void testSignalWakesFifo()      { testSignalWakesFifo(false); }
1008      public void testSignalWakesFifo_fair() { testSignalWakesFifo(true); }
# Line 1044 | Line 1056 | public class ReentrantLockTest extends J
1056      public void testAwaitLockCount(boolean fair) {
1057          final PublicReentrantLock lock = new PublicReentrantLock(fair);
1058          final Condition c = lock.newCondition();
1059 <        final CountDownLatch locked = new CountDownLatch(2);
1059 >        final CountDownLatch pleaseSignal = new CountDownLatch(2);
1060          Thread t1 = newStartedThread(new CheckedRunnable() {
1061              public void realRun() throws InterruptedException {
1062                  lock.lock();
1063                  assertLockedByMoi(lock);
1064                  assertEquals(1, lock.getHoldCount());
1065 <                locked.countDown();
1065 >                pleaseSignal.countDown();
1066                  c.await();
1067                  assertLockedByMoi(lock);
1068                  assertEquals(1, lock.getHoldCount());
# Line 1063 | Line 1075 | public class ReentrantLockTest extends J
1075                  lock.lock();
1076                  assertLockedByMoi(lock);
1077                  assertEquals(2, lock.getHoldCount());
1078 <                locked.countDown();
1078 >                pleaseSignal.countDown();
1079                  c.await();
1080                  assertLockedByMoi(lock);
1081                  assertEquals(2, lock.getHoldCount());
# Line 1071 | Line 1083 | public class ReentrantLockTest extends J
1083                  lock.unlock();
1084              }});
1085  
1086 <        await(locked);
1086 >        await(pleaseSignal);
1087          lock.lock();
1088          assertHasWaiters(lock, c, t1, t2);
1089          assertEquals(1, lock.getHoldCount());
# Line 1088 | Line 1100 | public class ReentrantLockTest extends J
1100      public void testSerialization()      { testSerialization(false); }
1101      public void testSerialization_fair() { testSerialization(true); }
1102      public void testSerialization(boolean fair) {
1103 <        ReentrantLock lock = new ReentrantLock(fair);
1103 >        final ReentrantLock lock = new ReentrantLock(fair);
1104          lock.lock();
1105  
1106          ReentrantLock clone = serialClone(lock);
# Line 1114 | Line 1126 | public class ReentrantLockTest extends J
1126      public void testToString()      { testToString(false); }
1127      public void testToString_fair() { testToString(true); }
1128      public void testToString(boolean fair) {
1129 <        ReentrantLock lock = new ReentrantLock(fair);
1130 <        String us = lock.toString();
1119 <        assertTrue(us.indexOf("Unlocked") >= 0);
1129 >        final ReentrantLock lock = new ReentrantLock(fair);
1130 >        assertTrue(lock.toString().contains("Unlocked"));
1131          lock.lock();
1132 <        String ls = lock.toString();
1133 <        assertTrue(ls.indexOf("Locked") >= 0);
1132 >        assertTrue(lock.toString().contains("Locked by"));
1133 >        lock.unlock();
1134 >        assertTrue(lock.toString().contains("Unlocked"));
1135      }
1136   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines