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.43 by jsr166, Sat May 7 03:36:23 2011 UTC vs.
Revision 1.44 by jsr166, Sat May 7 03:40:45 2011 UTC

# Line 789 | Line 789 | public class ReentrantLockTest extends J
789       * awaitNanos is interruptible
790       */
791      public void testAwaitNanos_Interrupt() throws InterruptedException {
792 <        final ReentrantLock lock = new ReentrantLock();
792 >        final PublicReentrantLock lock = new PublicReentrantLock();
793          final Condition c = lock.newCondition();
794 +        final CountDownLatch locked = new CountDownLatch(1);
795          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
796              public void realRun() throws InterruptedException {
797                  lock.lock();
798 <                c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
798 >                assertTrue(lock.isLocked());
799 >                assertTrue(lock.isHeldByCurrentThread());
800 >                assertHasNoWaiters(lock, c);
801 >                locked.countDown();
802 >                try {
803 >                    c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
804 >                } finally {
805 >                    assertTrue(lock.isLocked());
806 >                    assertTrue(lock.isHeldByCurrentThread());
807 >                    assertHasNoWaiters(lock, c);
808 >                    lock.unlock();
809 >                    assertFalse(Thread.interrupted());
810 >                }
811              }});
812  
813 <        delay(SHORT_DELAY_MS);
813 >        locked.await();
814 >        assertHasWaiters(lock, c, t);
815          t.interrupt();
816          awaitTermination(t);
817 +        assertFalse(lock.isLocked());
818      }
819  
820      /**
821       * awaitUntil is interruptible
822       */
823      public void testAwaitUntil_Interrupt() throws InterruptedException {
824 <        final ReentrantLock lock = new ReentrantLock();
824 >        final PublicReentrantLock lock = new PublicReentrantLock();
825          final Condition c = lock.newCondition();
826 +        final CountDownLatch locked = new CountDownLatch(1);
827          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
828              public void realRun() throws InterruptedException {
829                  lock.lock();
830 +                assertTrue(lock.isLocked());
831 +                assertTrue(lock.isHeldByCurrentThread());
832 +                assertHasNoWaiters(lock, c);
833 +                locked.countDown();
834                  java.util.Date d = new java.util.Date();
835 <                c.awaitUntil(new java.util.Date(d.getTime() + 10000));
835 >                try {
836 >                    c.awaitUntil(new java.util.Date(d.getTime() + 10000));
837 >                } finally {
838 >                    assertTrue(lock.isLocked());
839 >                    assertTrue(lock.isHeldByCurrentThread());
840 >                    assertHasNoWaiters(lock, c);
841 >                    lock.unlock();
842 >                    assertFalse(Thread.interrupted());
843 >                }
844              }});
845  
846 <        delay(SHORT_DELAY_MS);
846 >        locked.await();
847 >        assertHasWaiters(lock, c, t);
848          t.interrupt();
849          awaitTermination(t);
850 +        assertFalse(lock.isLocked());
851      }
852  
853      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines