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.45 by jsr166, Sat May 7 19:03:26 2011 UTC vs.
Revision 1.49 by jsr166, Tue May 24 23:40:14 2011 UTC

# Line 65 | Line 65 | public class ReentrantLockTest extends J
65       * Releases write lock, checking that it had a hold count of 1.
66       */
67      void releaseLock(PublicReentrantLock lock) {
68 <        assertLockedBy(lock, Thread.currentThread());
68 >        assertLockedByMoi(lock);
69          lock.unlock();
70          assertFalse(lock.isHeldByCurrentThread());
71          assertNotLocked(lock);
# Line 78 | Line 78 | public class ReentrantLockTest extends J
78          long startTime = System.nanoTime();
79          while (!lock.hasQueuedThread(t)) {
80              if (millisElapsedSince(startTime) > LONG_DELAY_MS)
81 <                throw new AssertionError("timed out");
81 >                throw new AssertionFailedError("timed out");
82              Thread.yield();
83          }
84          assertTrue(t.isAlive());
# Line 108 | Line 108 | public class ReentrantLockTest extends J
108      }
109  
110      /**
111 +     * Checks that lock is locked by the current thread.
112 +     */
113 +    void assertLockedByMoi(PublicReentrantLock lock) {
114 +        assertLockedBy(lock, Thread.currentThread());
115 +    }
116 +
117 +    /**
118       * Checks that condition c has no waiters.
119       */
120      void assertHasNoWaiters(PublicReentrantLock lock, Condition c) {
# Line 129 | Line 136 | public class ReentrantLockTest extends J
136          lock.unlock();
137      }
138  
139 +    enum AwaitMethod { await, awaitTimed, awaitNanos, awaitUntil };
140 +
141 +    /**
142 +     * Awaits condition using the specified AwaitMethod.
143 +     */
144 +    void await(Condition c, AwaitMethod awaitMethod)
145 +            throws InterruptedException {
146 +        long timeoutMillis = 2 * LONG_DELAY_MS;
147 +        switch (awaitMethod) {
148 +        case await:
149 +            c.await();
150 +            break;
151 +        case awaitTimed:
152 +            assertTrue(c.await(timeoutMillis, MILLISECONDS));
153 +            break;
154 +        case awaitNanos:
155 +            long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
156 +            long nanosRemaining = c.awaitNanos(nanosTimeout);
157 +            assertTrue(nanosRemaining > 0);
158 +            break;
159 +        case awaitUntil:
160 +            assertTrue(c.awaitUntil(delayedDate(timeoutMillis)));
161 +            break;
162 +        }
163 +    }
164 +
165      /**
166       * Constructor sets given fairness, and is in unlocked state
167       */
# Line 151 | Line 184 | public class ReentrantLockTest extends J
184      /**
185       * locking an unlocked lock succeeds
186       */
187 <    public void testLock() {
188 <        PublicReentrantLock lock = new PublicReentrantLock();
187 >    public void testLock()      { testLock(false); }
188 >    public void testLock_fair() { testLock(true); }
189 >    public void testLock(boolean fair) {
190 >        PublicReentrantLock lock = new PublicReentrantLock(fair);
191          lock.lock();
192 <        assertLockedBy(lock, Thread.currentThread());
158 <        releaseLock(lock);
159 <    }
160 <
161 <    /**
162 <     * locking an unlocked fair lock succeeds
163 <     */
164 <    public void testFairLock() {
165 <        PublicReentrantLock lock = new PublicReentrantLock(true);
166 <        lock.lock();
167 <        assertLockedBy(lock, Thread.currentThread());
192 >        assertLockedByMoi(lock);
193          releaseLock(lock);
194      }
195  
196      /**
197       * Unlocking an unlocked lock throws IllegalMonitorStateException
198       */
199 <    public void testUnlock_IllegalMonitorStateException() {
200 <        ReentrantLock lock = new ReentrantLock();
199 >    public void testUnlock_IMSE()      { testUnlock_IMSE(false); }
200 >    public void testUnlock_IMSE_fair() { testUnlock_IMSE(true); }
201 >    public void testUnlock_IMSE(boolean fair) {
202 >        ReentrantLock lock = new ReentrantLock(fair);
203          try {
204              lock.unlock();
205              shouldThrow();
# Line 182 | Line 209 | public class ReentrantLockTest extends J
209      /**
210       * tryLock on an unlocked lock succeeds
211       */
212 <    public void testTryLock() {
213 <        PublicReentrantLock lock = new PublicReentrantLock();
212 >    public void testTryLock()      { testTryLock(false); }
213 >    public void testTryLock_fair() { testTryLock(true); }
214 >    public void testTryLock(boolean fair) {
215 >        PublicReentrantLock lock = new PublicReentrantLock(fair);
216          assertTrue(lock.tryLock());
217 <        assertLockedBy(lock, Thread.currentThread());
217 >        assertLockedByMoi(lock);
218 >        assertTrue(lock.tryLock());
219 >        assertLockedByMoi(lock);
220 >        lock.unlock();
221          releaseLock(lock);
222      }
223  
224      /**
225       * hasQueuedThreads reports whether there are waiting threads
226       */
227 <    public void testHasQueuedThreads() throws InterruptedException {
228 <        final PublicReentrantLock lock = new PublicReentrantLock();
227 >    public void testHasQueuedThreads()      { testHasQueuedThreads(false); }
228 >    public void testHasQueuedThreads_fair() { testHasQueuedThreads(true); }
229 >    public void testHasQueuedThreads(boolean fair) {
230 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
231          Thread t1 = new Thread(new InterruptedLockRunnable(lock));
232          Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
233          assertFalse(lock.hasQueuedThreads());
# Line 216 | Line 250 | public class ReentrantLockTest extends J
250      /**
251       * getQueueLength reports number of waiting threads
252       */
253 <    public void testGetQueueLength() throws InterruptedException {
254 <        final PublicReentrantLock lock = new PublicReentrantLock();
255 <        Thread t1 = new Thread(new InterruptedLockRunnable(lock));
256 <        Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
223 <        assertEquals(0, lock.getQueueLength());
224 <        lock.lock();
225 <        t1.start();
226 <        waitForQueuedThread(lock, t1);
227 <        assertEquals(1, lock.getQueueLength());
228 <        t2.start();
229 <        waitForQueuedThread(lock, t2);
230 <        assertEquals(2, lock.getQueueLength());
231 <        t1.interrupt();
232 <        awaitTermination(t1);
233 <        assertEquals(1, lock.getQueueLength());
234 <        lock.unlock();
235 <        awaitTermination(t2);
236 <        assertEquals(0, lock.getQueueLength());
237 <    }
238 <
239 <    /**
240 <     * getQueueLength reports number of waiting threads
241 <     */
242 <    public void testGetQueueLength_fair() throws InterruptedException {
243 <        final PublicReentrantLock lock = new PublicReentrantLock(true);
253 >    public void testGetQueueLength()      { testGetQueueLength(false); }
254 >    public void testGetQueueLength_fair() { testGetQueueLength(true); }
255 >    public void testGetQueueLength(boolean fair) {
256 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
257          Thread t1 = new Thread(new InterruptedLockRunnable(lock));
258          Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
259          assertEquals(0, lock.getQueueLength());
# Line 262 | Line 275 | public class ReentrantLockTest extends J
275      /**
276       * hasQueuedThread(null) throws NPE
277       */
278 <    public void testHasQueuedThreadNPE() {
279 <        final ReentrantLock lock = new ReentrantLock();
278 >    public void testHasQueuedThreadNPE()      { testHasQueuedThreadNPE(false); }
279 >    public void testHasQueuedThreadNPE_fair() { testHasQueuedThreadNPE(true); }
280 >    public void testHasQueuedThreadNPE(boolean fair) {
281 >        final ReentrantLock lock = new ReentrantLock(fair);
282          try {
283              lock.hasQueuedThread(null);
284              shouldThrow();
# Line 271 | Line 286 | public class ReentrantLockTest extends J
286      }
287  
288      /**
289 <     * hasQueuedThread reports whether a thread is queued.
289 >     * hasQueuedThread reports whether a thread is queued
290       */
291 <    public void testHasQueuedThread() throws InterruptedException {
292 <        final PublicReentrantLock lock = new PublicReentrantLock();
291 >    public void testHasQueuedThread()      { testHasQueuedThread(false); }
292 >    public void testHasQueuedThread_fair() { testHasQueuedThread(true); }
293 >    public void testHasQueuedThread(boolean fair) {
294 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
295          Thread t1 = new Thread(new InterruptedLockRunnable(lock));
296          Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
297          assertFalse(lock.hasQueuedThread(t1));
# Line 301 | Line 318 | public class ReentrantLockTest extends J
318      /**
319       * getQueuedThreads includes waiting threads
320       */
321 <    public void testGetQueuedThreads() throws InterruptedException {
322 <        final PublicReentrantLock lock = new PublicReentrantLock();
321 >    public void testGetQueuedThreads()      { testGetQueuedThreads(false); }
322 >    public void testGetQueuedThreads_fair() { testGetQueuedThreads(true); }
323 >    public void testGetQueuedThreads(boolean fair) {
324 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
325          Thread t1 = new Thread(new InterruptedLockRunnable(lock));
326          Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
327          assertTrue(lock.getQueuedThreads().isEmpty());
# Line 328 | Line 347 | public class ReentrantLockTest extends J
347      }
348  
349      /**
350 <     * timed tryLock is interruptible.
350 >     * timed tryLock is interruptible
351       */
352 <    public void testTryLock_Interrupted() throws InterruptedException {
353 <        final PublicReentrantLock lock = new PublicReentrantLock();
352 >    public void testTryLock_Interruptible()      { testTryLock_Interruptible(false); }
353 >    public void testTryLock_Interruptible_fair() { testTryLock_Interruptible(true); }
354 >    public void testTryLock_Interruptible(boolean fair) {
355 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
356          lock.lock();
357          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
358              public void realRun() throws InterruptedException {
# Line 347 | Line 368 | public class ReentrantLockTest extends J
368      /**
369       * tryLock on a locked lock fails
370       */
371 <    public void testTryLockWhenLocked() throws InterruptedException {
372 <        final PublicReentrantLock lock = new PublicReentrantLock();
371 >    public void testTryLockWhenLocked()      { testTryLockWhenLocked(false); }
372 >    public void testTryLockWhenLocked_fair() { testTryLockWhenLocked(true); }
373 >    public void testTryLockWhenLocked(boolean fair) {
374 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
375          lock.lock();
376          Thread t = newStartedThread(new CheckedRunnable() {
377              public void realRun() {
# Line 362 | Line 385 | public class ReentrantLockTest extends J
385      /**
386       * Timed tryLock on a locked lock times out
387       */
388 <    public void testTryLock_Timeout() throws InterruptedException {
389 <        final PublicReentrantLock lock = new PublicReentrantLock();
388 >    public void testTryLock_Timeout()      { testTryLock_Timeout(false); }
389 >    public void testTryLock_Timeout_fair() { testTryLock_Timeout(true); }
390 >    public void testTryLock_Timeout(boolean fair) {
391 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
392          lock.lock();
393          Thread t = newStartedThread(new CheckedRunnable() {
394              public void realRun() throws InterruptedException {
# Line 380 | Line 405 | public class ReentrantLockTest extends J
405      /**
406       * getHoldCount returns number of recursive holds
407       */
408 <    public void testGetHoldCount() {
409 <        ReentrantLock lock = new ReentrantLock();
408 >    public void testGetHoldCount()      { testGetHoldCount(false); }
409 >    public void testGetHoldCount_fair() { testGetHoldCount(true); }
410 >    public void testGetHoldCount(boolean fair) {
411 >        ReentrantLock lock = new ReentrantLock(fair);
412          for (int i = 1; i <= SIZE; i++) {
413              lock.lock();
414              assertEquals(i, lock.getHoldCount());
# Line 395 | Line 422 | public class ReentrantLockTest extends J
422      /**
423       * isLocked is true when locked and false when not
424       */
425 <    public void testIsLocked() throws Exception {
426 <        final ReentrantLock lock = new ReentrantLock();
427 <        assertFalse(lock.isLocked());
428 <        lock.lock();
429 <        assertTrue(lock.isLocked());
430 <        lock.lock();
431 <        assertTrue(lock.isLocked());
432 <        lock.unlock();
433 <        assertTrue(lock.isLocked());
434 <        lock.unlock();
435 <        assertFalse(lock.isLocked());
436 <        final CyclicBarrier barrier = new CyclicBarrier(2);
437 <        Thread t = newStartedThread(new CheckedRunnable() {
438 <            public void realRun() throws Exception {
439 <                lock.lock();
440 <                assertTrue(lock.isLocked());
441 <                barrier.await();
442 <                barrier.await();
443 <                lock.unlock();
444 <            }});
445 <
446 <        barrier.await();
447 <        assertTrue(lock.isLocked());
448 <        barrier.await();
449 <        awaitTermination(t);
450 <        assertFalse(lock.isLocked());
451 <    }
452 <
453 <    /**
454 <     * lockInterruptibly is interruptible.
455 <     */
456 <    public void testLockInterruptibly_Interrupted() throws InterruptedException {
430 <        final PublicReentrantLock lock = new PublicReentrantLock();
431 <        lock.lock();
432 <        Thread t = newStartedThread(new InterruptedLockRunnable(lock));
433 <        waitForQueuedThread(lock, t);
434 <        t.interrupt();
435 <        awaitTermination(t);
436 <        releaseLock(lock);
425 >    public void testIsLocked()      { testIsLocked(false); }
426 >    public void testIsLocked_fair() { testIsLocked(true); }
427 >    public void testIsLocked(boolean fair) {
428 >        try {
429 >            final ReentrantLock lock = new ReentrantLock(fair);
430 >            assertFalse(lock.isLocked());
431 >            lock.lock();
432 >            assertTrue(lock.isLocked());
433 >            lock.lock();
434 >            assertTrue(lock.isLocked());
435 >            lock.unlock();
436 >            assertTrue(lock.isLocked());
437 >            lock.unlock();
438 >            assertFalse(lock.isLocked());
439 >            final CyclicBarrier barrier = new CyclicBarrier(2);
440 >            Thread t = newStartedThread(new CheckedRunnable() {
441 >                    public void realRun() throws Exception {
442 >                        lock.lock();
443 >                        assertTrue(lock.isLocked());
444 >                        barrier.await();
445 >                        barrier.await();
446 >                        lock.unlock();
447 >                    }});
448 >
449 >            barrier.await();
450 >            assertTrue(lock.isLocked());
451 >            barrier.await();
452 >            awaitTermination(t);
453 >            assertFalse(lock.isLocked());
454 >        } catch (Exception e) {
455 >            threadUnexpectedException(e);
456 >        }
457      }
458  
459      /**
460       * lockInterruptibly succeeds when unlocked, else is interruptible
461       */
462 <    public void testLockInterruptibly_Interrupted2() throws InterruptedException {
463 <        final PublicReentrantLock lock = new PublicReentrantLock();
464 <        lock.lockInterruptibly();
462 >    public void testLockInterruptibly()      { testLockInterruptibly(false); }
463 >    public void testLockInterruptibly_fair() { testLockInterruptibly(true); }
464 >    public void testLockInterruptibly(boolean fair) {
465 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
466 >        try {
467 >            lock.lockInterruptibly();
468 >        } catch (InterruptedException ie) {
469 >            threadUnexpectedException(ie);
470 >        }
471 >        assertLockedByMoi(lock);
472          Thread t = newStartedThread(new InterruptedLockRunnable(lock));
473          waitForQueuedThread(lock, t);
474          t.interrupt();
# Line 454 | Line 481 | public class ReentrantLockTest extends J
481      /**
482       * Calling await without holding lock throws IllegalMonitorStateException
483       */
484 <    public void testAwait_IllegalMonitor() throws InterruptedException {
485 <        final ReentrantLock lock = new ReentrantLock();
486 <        final Condition c = lock.newCondition();
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(100);
497 <            shouldThrow();
471 <        } catch (IllegalMonitorStateException success) {}
472 <        try {
473 <            c.awaitUninterruptibly();
474 <            shouldThrow();
475 <        } catch (IllegalMonitorStateException success) {}
484 >    public void testAwait_IMSE()      { testAwait_IMSE(false); }
485 >    public void testAwait_IMSE_fair() { testAwait_IMSE(true); }
486 >    public void testAwait_IMSE(boolean fair) {
487 >        final ReentrantLock lock = new ReentrantLock(fair);
488 >        final Condition c = lock.newCondition();
489 >        for (AwaitMethod awaitMethod : AwaitMethod.values()) {
490 >            long startTime = System.nanoTime();
491 >            try {
492 >                await(c, awaitMethod);
493 >                shouldThrow();
494 >            } catch (IllegalMonitorStateException success) {
495 >            } catch (InterruptedException e) { threadUnexpectedException(e); }
496 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
497 >        }
498      }
499  
500      /**
501       * Calling signal without holding lock throws IllegalMonitorStateException
502       */
503 <    public void testSignal_IllegalMonitor() {
504 <        final ReentrantLock lock = new ReentrantLock();
503 >    public void testSignal_IMSE()      { testSignal_IMSE(false); }
504 >    public void testSignal_IMSE_fair() { testSignal_IMSE(true); }
505 >    public void testSignal_IMSE(boolean fair) {
506 >        final ReentrantLock lock = new ReentrantLock(fair);
507          final Condition c = lock.newCondition();
508          try {
509              c.signal();
# Line 490 | Line 514 | public class ReentrantLockTest extends J
514      /**
515       * awaitNanos without a signal times out
516       */
517 <    public void testAwaitNanos_Timeout() throws InterruptedException {
518 <        final ReentrantLock lock = new ReentrantLock();
519 <        final Condition c = lock.newCondition();
520 <        lock.lock();
521 <        long startTime = System.nanoTime();
522 <        long timeoutMillis = 10;
523 <        long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
524 <        long nanosRemaining = c.awaitNanos(timeoutNanos);
525 <        assertTrue(nanosRemaining <= 0);
526 <        assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
527 <        lock.unlock();
517 >    public void testAwaitNanos_Timeout()      { testAwaitNanos_Timeout(false); }
518 >    public void testAwaitNanos_Timeout_fair() { testAwaitNanos_Timeout(true); }
519 >    public void testAwaitNanos_Timeout(boolean fair) {
520 >        try {
521 >            final ReentrantLock lock = new ReentrantLock(fair);
522 >            final Condition c = lock.newCondition();
523 >            lock.lock();
524 >            long startTime = System.nanoTime();
525 >            long timeoutMillis = 10;
526 >            long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
527 >            long nanosRemaining = c.awaitNanos(timeoutNanos);
528 >            assertTrue(nanosRemaining <= 0);
529 >            assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
530 >            lock.unlock();
531 >        } catch (InterruptedException e) {
532 >            threadUnexpectedException(e);
533 >        }
534      }
535  
536      /**
537       * timed await without a signal times out
538       */
539 <    public void testAwait_Timeout() throws InterruptedException {
540 <        final ReentrantLock lock = new ReentrantLock();
541 <        final Condition c = lock.newCondition();
542 <        lock.lock();
543 <        long startTime = System.nanoTime();
544 <        long timeoutMillis = 10;
545 <        assertFalse(c.await(timeoutMillis, MILLISECONDS));
546 <        assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
547 <        lock.unlock();
539 >    public void testAwait_Timeout()      { testAwait_Timeout(false); }
540 >    public void testAwait_Timeout_fair() { testAwait_Timeout(true); }
541 >    public void testAwait_Timeout(boolean fair) {
542 >        try {
543 >            final ReentrantLock lock = new ReentrantLock(fair);
544 >            final Condition c = lock.newCondition();
545 >            lock.lock();
546 >            long startTime = System.nanoTime();
547 >            long timeoutMillis = 10;
548 >            assertFalse(c.await(timeoutMillis, MILLISECONDS));
549 >            assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
550 >            lock.unlock();
551 >        } catch (InterruptedException e) {
552 >            threadUnexpectedException(e);
553 >        }
554      }
555  
556      /**
557       * awaitUntil without a signal times out
558       */
559 <    public void testAwaitUntil_Timeout() throws InterruptedException {
560 <        final ReentrantLock lock = new ReentrantLock();
561 <        final Condition c = lock.newCondition();
562 <        lock.lock();
563 <        long startTime = System.nanoTime();
564 <        long timeoutMillis = 10;
565 <        java.util.Date d = new java.util.Date();
566 <        assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + timeoutMillis)));
567 <        assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
568 <        lock.unlock();
559 >    public void testAwaitUntil_Timeout()      { testAwaitUntil_Timeout(false); }
560 >    public void testAwaitUntil_Timeout_fair() { testAwaitUntil_Timeout(true); }
561 >    public void testAwaitUntil_Timeout(boolean fair) {
562 >        try {
563 >            final ReentrantLock lock = new ReentrantLock(fair);
564 >            final Condition c = lock.newCondition();
565 >            lock.lock();
566 >            long startTime = System.nanoTime();
567 >            long timeoutMillis = 10;
568 >            java.util.Date d = new java.util.Date();
569 >            assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + timeoutMillis)));
570 >            assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
571 >            lock.unlock();
572 >        } catch (InterruptedException e) {
573 >            threadUnexpectedException(e);
574 >        }
575      }
576  
577      /**
578       * await returns when signalled
579       */
580 <    public void testAwait() throws InterruptedException {
581 <        final PublicReentrantLock lock = new PublicReentrantLock();
580 >    public void testAwait()      { testAwait(false); }
581 >    public void testAwait_fair() { testAwait(true); }
582 >    public void testAwait(boolean fair) {
583 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
584          final Condition c = lock.newCondition();
585          final CountDownLatch locked = new CountDownLatch(1);
586          Thread t = newStartedThread(new CheckedRunnable() {
# Line 547 | Line 591 | public class ReentrantLockTest extends J
591                  lock.unlock();
592              }});
593  
594 <        locked.await();
594 >        await(locked);
595          lock.lock();
596          assertHasWaiters(lock, c, t);
597          c.signal();
# Line 560 | Line 604 | public class ReentrantLockTest extends J
604      /**
605       * hasWaiters throws NPE if null
606       */
607 <    public void testHasWaitersNPE() {
608 <        final ReentrantLock lock = new ReentrantLock();
607 >    public void testHasWaitersNPE()      { testHasWaitersNPE(false); }
608 >    public void testHasWaitersNPE_fair() { testHasWaitersNPE(true); }
609 >    public void testHasWaitersNPE(boolean fair) {
610 >        final ReentrantLock lock = new ReentrantLock(fair);
611          try {
612              lock.hasWaiters(null);
613              shouldThrow();
# Line 571 | Line 617 | public class ReentrantLockTest extends J
617      /**
618       * getWaitQueueLength throws NPE if null
619       */
620 <    public void testGetWaitQueueLengthNPE() {
621 <        final ReentrantLock lock = new ReentrantLock();
620 >    public void testGetWaitQueueLengthNPE()      { testGetWaitQueueLengthNPE(false); }
621 >    public void testGetWaitQueueLengthNPE_fair() { testGetWaitQueueLengthNPE(true); }
622 >    public void testGetWaitQueueLengthNPE(boolean fair) {
623 >        final ReentrantLock lock = new ReentrantLock(fair);
624          try {
625              lock.getWaitQueueLength(null);
626              shouldThrow();
# Line 582 | Line 630 | public class ReentrantLockTest extends J
630      /**
631       * getWaitingThreads throws NPE if null
632       */
633 <    public void testGetWaitingThreadsNPE() {
634 <        final PublicReentrantLock lock = new PublicReentrantLock();
633 >    public void testGetWaitingThreadsNPE()      { testGetWaitingThreadsNPE(false); }
634 >    public void testGetWaitingThreadsNPE_fair() { testGetWaitingThreadsNPE(true); }
635 >    public void testGetWaitingThreadsNPE(boolean fair) {
636 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
637          try {
638              lock.getWaitingThreads(null);
639              shouldThrow();
# Line 593 | Line 643 | public class ReentrantLockTest extends J
643      /**
644       * hasWaiters throws IllegalArgumentException if not owned
645       */
646 <    public void testHasWaitersIAE() {
647 <        final ReentrantLock lock = new ReentrantLock();
646 >    public void testHasWaitersIAE()      { testHasWaitersIAE(false); }
647 >    public void testHasWaitersIAE_fair() { testHasWaitersIAE(true); }
648 >    public void testHasWaitersIAE(boolean fair) {
649 >        final ReentrantLock lock = new ReentrantLock(fair);
650          final Condition c = lock.newCondition();
651 <        final ReentrantLock lock2 = new ReentrantLock();
651 >        final ReentrantLock lock2 = new ReentrantLock(fair);
652          try {
653              lock2.hasWaiters(c);
654              shouldThrow();
# Line 606 | Line 658 | public class ReentrantLockTest extends J
658      /**
659       * hasWaiters throws IllegalMonitorStateException if not locked
660       */
661 <    public void testHasWaitersIMSE() {
662 <        final ReentrantLock lock = new ReentrantLock();
661 >    public void testHasWaitersIMSE()      { testHasWaitersIMSE(false); }
662 >    public void testHasWaitersIMSE_fair() { testHasWaitersIMSE(true); }
663 >    public void testHasWaitersIMSE(boolean fair) {
664 >        final ReentrantLock lock = new ReentrantLock(fair);
665          final Condition c = lock.newCondition();
666          try {
667              lock.hasWaiters(c);
# Line 618 | Line 672 | public class ReentrantLockTest extends J
672      /**
673       * getWaitQueueLength throws IllegalArgumentException if not owned
674       */
675 <    public void testGetWaitQueueLengthIAE() {
676 <        final ReentrantLock lock = new ReentrantLock();
675 >    public void testGetWaitQueueLengthIAE()      { testGetWaitQueueLengthIAE(false); }
676 >    public void testGetWaitQueueLengthIAE_fair() { testGetWaitQueueLengthIAE(true); }
677 >    public void testGetWaitQueueLengthIAE(boolean fair) {
678 >        final ReentrantLock lock = new ReentrantLock(fair);
679          final Condition c = lock.newCondition();
680 <        final ReentrantLock lock2 = new ReentrantLock();
680 >        final ReentrantLock lock2 = new ReentrantLock(fair);
681          try {
682              lock2.getWaitQueueLength(c);
683              shouldThrow();
# Line 631 | Line 687 | public class ReentrantLockTest extends J
687      /**
688       * getWaitQueueLength throws IllegalMonitorStateException if not locked
689       */
690 <    public void testGetWaitQueueLengthIMSE() {
691 <        final ReentrantLock lock = new ReentrantLock();
690 >    public void testGetWaitQueueLengthIMSE()      { testGetWaitQueueLengthIMSE(false); }
691 >    public void testGetWaitQueueLengthIMSE_fair() { testGetWaitQueueLengthIMSE(true); }
692 >    public void testGetWaitQueueLengthIMSE(boolean fair) {
693 >        final ReentrantLock lock = new ReentrantLock(fair);
694          final Condition c = lock.newCondition();
695          try {
696              lock.getWaitQueueLength(c);
# Line 643 | Line 701 | public class ReentrantLockTest extends J
701      /**
702       * getWaitingThreads throws IllegalArgumentException if not owned
703       */
704 <    public void testGetWaitingThreadsIAE() {
705 <        final PublicReentrantLock lock = new PublicReentrantLock();
704 >    public void testGetWaitingThreadsIAE()      { testGetWaitingThreadsIAE(false); }
705 >    public void testGetWaitingThreadsIAE_fair() { testGetWaitingThreadsIAE(true); }
706 >    public void testGetWaitingThreadsIAE(boolean fair) {
707 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
708          final Condition c = lock.newCondition();
709 <        final PublicReentrantLock lock2 = new PublicReentrantLock();
709 >        final PublicReentrantLock lock2 = new PublicReentrantLock(fair);
710          try {
711              lock2.getWaitingThreads(c);
712              shouldThrow();
# Line 656 | Line 716 | public class ReentrantLockTest extends J
716      /**
717       * getWaitingThreads throws IllegalMonitorStateException if not locked
718       */
719 <    public void testGetWaitingThreadsIMSE() {
720 <        final PublicReentrantLock lock = new PublicReentrantLock();
719 >    public void testGetWaitingThreadsIMSE()      { testGetWaitingThreadsIMSE(false); }
720 >    public void testGetWaitingThreadsIMSE_fair() { testGetWaitingThreadsIMSE(true); }
721 >    public void testGetWaitingThreadsIMSE(boolean fair) {
722 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
723          final Condition c = lock.newCondition();
724          try {
725              lock.getWaitingThreads(c);
# Line 668 | Line 730 | public class ReentrantLockTest extends J
730      /**
731       * hasWaiters returns true when a thread is waiting, else false
732       */
733 <    public void testHasWaiters() throws InterruptedException {
734 <        final PublicReentrantLock lock = new PublicReentrantLock();
733 >    public void testHasWaiters()      { testHasWaiters(false); }
734 >    public void testHasWaiters_fair() { testHasWaiters(true); }
735 >    public void testHasWaiters(boolean fair) {
736 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
737          final Condition c = lock.newCondition();
738          final CountDownLatch locked = new CountDownLatch(1);
739          Thread t = newStartedThread(new CheckedRunnable() {
# Line 684 | Line 748 | public class ReentrantLockTest extends J
748                  lock.unlock();
749              }});
750  
751 <        locked.await();
751 >        await(locked);
752          lock.lock();
753          assertHasWaiters(lock, c, t);
754          assertTrue(lock.hasWaiters(c));
# Line 699 | Line 763 | public class ReentrantLockTest extends J
763      /**
764       * getWaitQueueLength returns number of waiting threads
765       */
766 <    public void testGetWaitQueueLength() throws InterruptedException {
767 <        final PublicReentrantLock lock = new PublicReentrantLock();
766 >    public void testGetWaitQueueLength()      { testGetWaitQueueLength(false); }
767 >    public void testGetWaitQueueLength_fair() { testGetWaitQueueLength(true); }
768 >    public void testGetWaitQueueLength(boolean fair) {
769 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
770          final Condition c = lock.newCondition();
771          final CountDownLatch locked1 = new CountDownLatch(1);
772          final CountDownLatch locked2 = new CountDownLatch(1);
# Line 729 | Line 795 | public class ReentrantLockTest extends J
795          lock.unlock();
796  
797          t1.start();
798 <        locked1.await();
798 >        await(locked1);
799  
800          lock.lock();
801          assertHasWaiters(lock, c, t1);
# Line 737 | Line 803 | public class ReentrantLockTest extends J
803          lock.unlock();
804  
805          t2.start();
806 <        locked2.await();
806 >        await(locked2);
807  
808          lock.lock();
809          assertHasWaiters(lock, c, t1, t2);
# Line 755 | Line 821 | public class ReentrantLockTest extends J
821      /**
822       * getWaitingThreads returns only and all waiting threads
823       */
824 <    public void testGetWaitingThreads() throws InterruptedException {
825 <        final PublicReentrantLock lock = new PublicReentrantLock();
824 >    public void testGetWaitingThreads()      { testGetWaitingThreads(false); }
825 >    public void testGetWaitingThreads_fair() { testGetWaitingThreads(true); }
826 >    public void testGetWaitingThreads(boolean fair) {
827 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
828          final Condition c = lock.newCondition();
829          final CountDownLatch locked1 = new CountDownLatch(1);
830          final CountDownLatch locked2 = new CountDownLatch(1);
# Line 783 | Line 851 | public class ReentrantLockTest extends J
851          lock.unlock();
852  
853          t1.start();
854 <        locked1.await();
854 >        await(locked1);
855  
856          lock.lock();
857          assertHasWaiters(lock, c, t1);
# Line 793 | Line 861 | public class ReentrantLockTest extends J
861          lock.unlock();
862  
863          t2.start();
864 <        locked2.await();
864 >        await(locked2);
865  
866          lock.lock();
867          assertHasWaiters(lock, c, t1, t2);
# Line 813 | Line 881 | public class ReentrantLockTest extends J
881      /**
882       * awaitUninterruptibly doesn't abort on interrupt
883       */
884 <    public void testAwaitUninterruptibly() throws InterruptedException {
885 <        final ReentrantLock lock = new ReentrantLock();
884 >    public void testAwaitUninterruptibly()      { testAwaitUninterruptibly(false); }
885 >    public void testAwaitUninterruptibly_fair() { testAwaitUninterruptibly(true); }
886 >    public void testAwaitUninterruptibly(boolean fair) {
887 >        final ReentrantLock lock = new ReentrantLock(fair);
888          final Condition c = lock.newCondition();
889          final CountDownLatch locked = new CountDownLatch(1);
890          Thread t = newStartedThread(new CheckedRunnable() {
# Line 826 | Line 896 | public class ReentrantLockTest extends J
896                  lock.unlock();
897              }});
898  
899 <        locked.await();
899 >        await(locked);
900          lock.lock();
901          lock.unlock();
902          t.interrupt();
903          long timeoutMillis = 10;
904 <        assertThreadJoinTimesOut(t, timeoutMillis);
904 >        assertThreadStaysAlive(t, timeoutMillis);
905          lock.lock();
906          c.signal();
907          lock.unlock();
# Line 839 | Line 909 | public class ReentrantLockTest extends J
909      }
910  
911      /**
912 <     * await is interruptible
912 >     * await/awaitNanos/awaitUntil is interruptible
913       */
914 <    public void testAwait_Interrupt() throws InterruptedException {
915 <        final PublicReentrantLock lock = new PublicReentrantLock();
914 >    public void testInterruptible_await()           { testInterruptible(false, AwaitMethod.await); }
915 >    public void testInterruptible_await_fair()      { testInterruptible(true,  AwaitMethod.await); }
916 >    public void testInterruptible_awaitTimed()      { testInterruptible(false, AwaitMethod.awaitTimed); }
917 >    public void testInterruptible_awaitTimed_fair() { testInterruptible(true,  AwaitMethod.awaitTimed); }
918 >    public void testInterruptible_awaitNanos()      { testInterruptible(false, AwaitMethod.awaitNanos); }
919 >    public void testInterruptible_awaitNanos_fair() { testInterruptible(true,  AwaitMethod.awaitNanos); }
920 >    public void testInterruptible_awaitUntil()      { testInterruptible(false, AwaitMethod.awaitUntil); }
921 >    public void testInterruptible_awaitUntil_fair() { testInterruptible(true,  AwaitMethod.awaitUntil); }
922 >    public void testInterruptible(boolean fair, final AwaitMethod awaitMethod) {
923 >        final PublicReentrantLock lock =
924 >            new PublicReentrantLock(fair);
925          final Condition c = lock.newCondition();
926          final CountDownLatch locked = new CountDownLatch(1);
927          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
928              public void realRun() throws InterruptedException {
929                  lock.lock();
930 <                assertTrue(lock.isLocked());
852 <                assertTrue(lock.isHeldByCurrentThread());
930 >                assertLockedByMoi(lock);
931                  assertHasNoWaiters(lock, c);
932                  locked.countDown();
933                  try {
934 <                    c.await();
934 >                    await(c, awaitMethod);
935                  } finally {
936 <                    assertTrue(lock.isLocked());
859 <                    assertTrue(lock.isHeldByCurrentThread());
936 >                    assertLockedByMoi(lock);
937                      assertHasNoWaiters(lock, c);
938                      lock.unlock();
939                      assertFalse(Thread.interrupted());
940                  }
941              }});
942  
943 <        locked.await();
943 >        await(locked);
944          assertHasWaiters(lock, c, t);
945          t.interrupt();
946          awaitTermination(t);
947 <        assertFalse(lock.isLocked());
947 >        assertNotLocked(lock);
948      }
949  
950      /**
951 <     * awaitNanos is interruptible
951 >     * signalAll wakes up all threads
952       */
953 <    public void testAwaitNanos_Interrupt() throws InterruptedException {
954 <        final PublicReentrantLock lock = new PublicReentrantLock();
953 >    public void testSignalAll_await()           { testSignalAll(false, AwaitMethod.await); }
954 >    public void testSignalAll_await_fair()      { testSignalAll(true,  AwaitMethod.await); }
955 >    public void testSignalAll_awaitTimed()      { testSignalAll(false, AwaitMethod.awaitTimed); }
956 >    public void testSignalAll_awaitTimed_fair() { testSignalAll(true,  AwaitMethod.awaitTimed); }
957 >    public void testSignalAll_awaitNanos()      { testSignalAll(false, AwaitMethod.awaitNanos); }
958 >    public void testSignalAll_awaitNanos_fair() { testSignalAll(true,  AwaitMethod.awaitNanos); }
959 >    public void testSignalAll_awaitUntil()      { testSignalAll(false, AwaitMethod.awaitUntil); }
960 >    public void testSignalAll_awaitUntil_fair() { testSignalAll(true,  AwaitMethod.awaitUntil); }
961 >    public void testSignalAll(boolean fair, final AwaitMethod awaitMethod) {
962 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
963          final Condition c = lock.newCondition();
964 <        final CountDownLatch locked = new CountDownLatch(1);
965 <        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
964 >        final CountDownLatch locked = new CountDownLatch(2);
965 >        class Awaiter extends CheckedRunnable {
966              public void realRun() throws InterruptedException {
967                  lock.lock();
883                assertTrue(lock.isLocked());
884                assertTrue(lock.isHeldByCurrentThread());
885                assertHasNoWaiters(lock, c);
968                  locked.countDown();
969 <                try {
970 <                    c.awaitNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS));
971 <                } finally {
972 <                    assertTrue(lock.isLocked());
891 <                    assertTrue(lock.isHeldByCurrentThread());
892 <                    assertHasNoWaiters(lock, c);
893 <                    lock.unlock();
894 <                    assertFalse(Thread.interrupted());
895 <                }
896 <            }});
897 <
898 <        locked.await();
899 <        assertHasWaiters(lock, c, t);
900 <        t.interrupt();
901 <        awaitTermination(t);
902 <        assertFalse(lock.isLocked());
903 <    }
969 >                await(c, awaitMethod);
970 >                lock.unlock();
971 >            }
972 >        }
973  
974 <    /**
975 <     * awaitUntil is interruptible
907 <     */
908 <    public void testAwaitUntil_Interrupt() throws InterruptedException {
909 <        final PublicReentrantLock lock = new PublicReentrantLock();
910 <        final Condition c = lock.newCondition();
911 <        final CountDownLatch locked = new CountDownLatch(1);
912 <        Thread t = newStartedThread(new CheckedInterruptedRunnable() {
913 <            public void realRun() throws InterruptedException {
914 <                lock.lock();
915 <                assertTrue(lock.isLocked());
916 <                assertTrue(lock.isHeldByCurrentThread());
917 <                assertHasNoWaiters(lock, c);
918 <                locked.countDown();
919 <                java.util.Date d = new java.util.Date();
920 <                try {
921 <                    c.awaitUntil(new java.util.Date(d.getTime() + 2 * LONG_DELAY_MS));
922 <                } finally {
923 <                    assertTrue(lock.isLocked());
924 <                    assertTrue(lock.isHeldByCurrentThread());
925 <                    assertHasNoWaiters(lock, c);
926 <                    lock.unlock();
927 <                    assertFalse(Thread.interrupted());
928 <                }
929 <            }});
974 >        Thread t1 = newStartedThread(new Awaiter());
975 >        Thread t2 = newStartedThread(new Awaiter());
976  
977 <        locked.await();
978 <        assertHasWaiters(lock, c, t);
979 <        t.interrupt();
980 <        awaitTermination(t);
981 <        assertFalse(lock.isLocked());
977 >        await(locked);
978 >        lock.lock();
979 >        assertHasWaiters(lock, c, t1, t2);
980 >        c.signalAll();
981 >        assertHasNoWaiters(lock, c);
982 >        lock.unlock();
983 >        awaitTermination(t1);
984 >        awaitTermination(t2);
985      }
986  
987      /**
988 <     * signalAll wakes up all threads
988 >     * signal wakes up waiting threads in FIFO order
989       */
990 <    public void testSignalAll() throws InterruptedException {
991 <        final PublicReentrantLock lock = new PublicReentrantLock();
990 >    public void testSignalWakesFifo()      { testSignalWakesFifo(false); }
991 >    public void testSignalWakesFifo_fair() { testSignalWakesFifo(true); }
992 >    public void testSignalWakesFifo(boolean fair) {
993 >        final PublicReentrantLock lock =
994 >            new PublicReentrantLock(fair);
995          final Condition c = lock.newCondition();
996 <        final CountDownLatch locked = new CountDownLatch(2);
996 >        final CountDownLatch locked1 = new CountDownLatch(1);
997 >        final CountDownLatch locked2 = new CountDownLatch(1);
998          Thread t1 = newStartedThread(new CheckedRunnable() {
999              public void realRun() throws InterruptedException {
1000                  lock.lock();
1001 <                locked.countDown();
1001 >                locked1.countDown();
1002                  c.await();
1003                  lock.unlock();
1004              }});
1005  
1006 +        await(locked1);
1007 +
1008          Thread t2 = newStartedThread(new CheckedRunnable() {
1009              public void realRun() throws InterruptedException {
1010                  lock.lock();
1011 <                locked.countDown();
1011 >                locked2.countDown();
1012                  c.await();
1013                  lock.unlock();
1014              }});
1015  
1016 <        locked.await();
1016 >        await(locked2);
1017 >
1018          lock.lock();
1019          assertHasWaiters(lock, c, t1, t2);
1020 <        c.signalAll();
1020 >        assertFalse(lock.hasQueuedThreads());
1021 >        c.signal();
1022 >        assertHasWaiters(lock, c, t2);
1023 >        assertTrue(lock.hasQueuedThread(t1));
1024 >        assertFalse(lock.hasQueuedThread(t2));
1025 >        c.signal();
1026          assertHasNoWaiters(lock, c);
1027 +        assertTrue(lock.hasQueuedThread(t1));
1028 +        assertTrue(lock.hasQueuedThread(t2));
1029          lock.unlock();
1030          awaitTermination(t1);
1031          awaitTermination(t2);
# Line 971 | Line 1034 | public class ReentrantLockTest extends J
1034      /**
1035       * await after multiple reentrant locking preserves lock count
1036       */
1037 <    public void testAwaitLockCount() throws InterruptedException {
1038 <        final PublicReentrantLock lock = new PublicReentrantLock();
1037 >    public void testAwaitLockCount()      { testAwaitLockCount(false); }
1038 >    public void testAwaitLockCount_fair() { testAwaitLockCount(true); }
1039 >    public void testAwaitLockCount(boolean fair) {
1040 >        final PublicReentrantLock lock = new PublicReentrantLock(fair);
1041          final Condition c = lock.newCondition();
1042          final CountDownLatch locked = new CountDownLatch(2);
1043          Thread t1 = newStartedThread(new CheckedRunnable() {
1044              public void realRun() throws InterruptedException {
1045                  lock.lock();
1046 <                assertLockedBy(lock, Thread.currentThread());
1046 >                assertLockedByMoi(lock);
1047                  assertEquals(1, lock.getHoldCount());
1048                  locked.countDown();
1049                  c.await();
1050 <                assertLockedBy(lock, Thread.currentThread());
1050 >                assertLockedByMoi(lock);
1051                  assertEquals(1, lock.getHoldCount());
1052                  lock.unlock();
1053              }});
# Line 991 | Line 1056 | public class ReentrantLockTest extends J
1056              public void realRun() throws InterruptedException {
1057                  lock.lock();
1058                  lock.lock();
1059 <                assertLockedBy(lock, Thread.currentThread());
1059 >                assertLockedByMoi(lock);
1060                  assertEquals(2, lock.getHoldCount());
1061                  locked.countDown();
1062                  c.await();
1063 <                assertLockedBy(lock, Thread.currentThread());
1063 >                assertLockedByMoi(lock);
1064                  assertEquals(2, lock.getHoldCount());
1065                  lock.unlock();
1066                  lock.unlock();
1067              }});
1068  
1069 <        locked.await();
1069 >        await(locked);
1070          lock.lock();
1071          assertHasWaiters(lock, c, t1, t2);
1072          assertEquals(1, lock.getHoldCount());
# Line 1015 | Line 1080 | public class ReentrantLockTest extends J
1080      /**
1081       * A serialized lock deserializes as unlocked
1082       */
1083 <    public void testSerialization() throws Exception {
1084 <        ReentrantLock l = new ReentrantLock();
1085 <        l.lock();
1086 <        l.unlock();
1087 <
1088 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1089 <        ObjectOutputStream out =
1090 <            new ObjectOutputStream(new BufferedOutputStream(bout));
1091 <        out.writeObject(l);
1092 <        out.close();
1093 <
1094 <        ByteArrayInputStream bin =
1095 <            new ByteArrayInputStream(bout.toByteArray());
1096 <        ObjectInputStream in =
1097 <            new ObjectInputStream(new BufferedInputStream(bin));
1098 <        ReentrantLock r = (ReentrantLock) in.readObject();
1099 <        r.lock();
1100 <        r.unlock();
1083 >    public void testSerialization()      { testSerialization(false); }
1084 >    public void testSerialization_fair() { testSerialization(true); }
1085 >    public void testSerialization(boolean fair) {
1086 >        ReentrantLock lock = new ReentrantLock(fair);
1087 >        lock.lock();
1088 >
1089 >        ReentrantLock clone = serialClone(lock);
1090 >        assertEquals(lock.isFair(), clone.isFair());
1091 >        assertTrue(lock.isLocked());
1092 >        assertFalse(clone.isLocked());
1093 >        assertEquals(1, lock.getHoldCount());
1094 >        assertEquals(0, clone.getHoldCount());
1095 >        clone.lock();
1096 >        clone.lock();
1097 >        assertTrue(clone.isLocked());
1098 >        assertEquals(2, clone.getHoldCount());
1099 >        assertEquals(1, lock.getHoldCount());
1100 >        clone.unlock();
1101 >        clone.unlock();
1102 >        assertTrue(lock.isLocked());
1103 >        assertFalse(clone.isLocked());
1104      }
1105  
1106      /**
1107       * toString indicates current lock state
1108       */
1109 <    public void testToString() {
1110 <        ReentrantLock lock = new ReentrantLock();
1111 <        String us = lock.toString();
1112 <        assertTrue(us.indexOf("Unlocked") >= 0);
1109 >    public void testToString()      { testToString(false); }
1110 >    public void testToString_fair() { testToString(true); }
1111 >    public void testToString(boolean fair) {
1112 >        ReentrantLock lock = new ReentrantLock(fair);
1113 >        assertTrue(lock.toString().contains("Unlocked"));
1114          lock.lock();
1115 <        String ls = lock.toString();
1116 <        assertTrue(ls.indexOf("Locked") >= 0);
1115 >        assertTrue(lock.toString().contains("Locked"));
1116 >        lock.unlock();
1117 >        assertTrue(lock.toString().contains("Unlocked"));
1118      }
1119   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines