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.9 by dl, Mon Nov 3 13:50:07 2003 UTC vs.
Revision 1.12 by dl, Sat Dec 27 19:26:43 2003 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
2 > * Written by Doug Lea with assistance from members of JCP JSR-166
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/licenses/publicdomain
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
# Line 56 | Line 57 | public class ReentrantLockTest extends J
57          public Collection<Thread> getQueuedThreads() {
58              return super.getQueuedThreads();
59          }
59        public ConditionObject newCondition() {
60            return new PublicCondition(this);
61        }
62
63        static class PublicCondition extends ReentrantLock.ConditionObject {
64            PublicCondition(PublicReentrantLock l) { super(l); }
65            public Collection<Thread> getWaitingThreads() {
66                return super.getWaitingThreads();
67            }
68        }
60  
61      }
62  
# Line 428 | Line 419 | public class ReentrantLockTest extends J
419       */
420      public void testAwait() {
421          final ReentrantLock lock = new ReentrantLock();
422 <        final ReentrantLock.ConditionObject c = lock.newCondition();
422 >        final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition();
423          Thread t = new Thread(new Runnable() {
424                  public void run() {
425                      try {
# Line 461 | Line 452 | public class ReentrantLockTest extends J
452       */
453      public void testHasWaiters() {
454          final ReentrantLock lock = new ReentrantLock();
455 <        final ReentrantLock.ConditionObject c = lock.newCondition();
455 >        final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition();
456          Thread t = new Thread(new Runnable() {
457                  public void run() {
458                      try {
# Line 503 | Line 494 | public class ReentrantLockTest extends J
494       */
495      public void testGetWaitQueueLength() {
496          final ReentrantLock lock = new ReentrantLock();
497 <        final ReentrantLock.ConditionObject c = lock.newCondition();
497 >        final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition();
498          Thread t1 = new Thread(new Runnable() {
499                  public void run() {
500                      try {
# Line 551 | Line 542 | public class ReentrantLockTest extends J
542              lock.unlock();
543              t1.join(SHORT_DELAY_MS);
544              t2.join(SHORT_DELAY_MS);
554            assertFalse(t1.isAlive());
555            assertFalse(t2.isAlive());
556        }
557        catch (Exception ex) {
558            unexpectedException();
559        }
560    }
561
562    /**
563     * getWaitingThreads returns only and all waiting threads
564     */
565    public void testGetWaitingThreads() {
566        final PublicReentrantLock lock = new PublicReentrantLock();    
567        final PublicReentrantLock.PublicCondition c = (PublicReentrantLock.PublicCondition)lock.newCondition();
568        Thread t1 = new Thread(new Runnable() {
569                public void run() {
570                    try {
571                        lock.lock();
572                        threadAssertTrue(c.getWaitingThreads().isEmpty());
573                        c.await();
574                        lock.unlock();
575                    }
576                    catch(InterruptedException e) {
577                        threadUnexpectedException();
578                    }
579                }
580            });
581
582        Thread t2 = new Thread(new Runnable() {
583                public void run() {
584                    try {
585                        lock.lock();
586                        threadAssertFalse(c.getWaitingThreads().isEmpty());
587                        c.await();
588                        lock.unlock();
589                    }
590                    catch(InterruptedException e) {
591                        threadUnexpectedException();
592                    }
593                }
594            });
595
596        try {
597            lock.lock();
598            assertTrue(c.getWaitingThreads().isEmpty());
599            lock.unlock();
600            t1.start();
601            Thread.sleep(SHORT_DELAY_MS);
602            t2.start();
603            Thread.sleep(SHORT_DELAY_MS);
604            lock.lock();
605            assertTrue(c.hasWaiters());
606            assertTrue(c.getWaitingThreads().contains(t1));
607            assertTrue(c.getWaitingThreads().contains(t2));
608            c.signalAll();
609            lock.unlock();
610            Thread.sleep(SHORT_DELAY_MS);
611            lock.lock();
612            assertFalse(c.hasWaiters());
613            assertTrue(c.getWaitingThreads().isEmpty());
614            lock.unlock();
615            t1.join(SHORT_DELAY_MS);
616            t2.join(SHORT_DELAY_MS);
545              assertFalse(t1.isAlive());
546              assertFalse(t2.isAlive());
547          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines