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.10 by dl, Sat Dec 27 14:16:33 2003 UTC vs.
Revision 1.11 by dl, Sat Dec 27 18:27:02 2003 UTC

# Line 56 | Line 56 | public class ReentrantLockTest extends J
56          public Collection<Thread> getQueuedThreads() {
57              return super.getQueuedThreads();
58          }
59        public ConditionObject newCondition() {
60            return new PublicCondition();
61        }
62
63        class PublicCondition extends ReentrantLock.ConditionObject {
64            PublicCondition() { }
65            public Collection<Thread> getWaitingThreads() {
66                return super.getWaitingThreads();
67            }
68        }
59  
60      }
61  
# Line 428 | Line 418 | public class ReentrantLockTest extends J
418       */
419      public void testAwait() {
420          final ReentrantLock lock = new ReentrantLock();
421 <        final ReentrantLock.ConditionObject c = lock.newCondition();
421 >        final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition();
422          Thread t = new Thread(new Runnable() {
423                  public void run() {
424                      try {
# Line 461 | Line 451 | public class ReentrantLockTest extends J
451       */
452      public void testHasWaiters() {
453          final ReentrantLock lock = new ReentrantLock();
454 <        final ReentrantLock.ConditionObject c = lock.newCondition();
454 >        final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition();
455          Thread t = new Thread(new Runnable() {
456                  public void run() {
457                      try {
# Line 503 | Line 493 | public class ReentrantLockTest extends J
493       */
494      public void testGetWaitQueueLength() {
495          final ReentrantLock lock = new ReentrantLock();
496 <        final ReentrantLock.ConditionObject c = lock.newCondition();
496 >        final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition();
497          Thread t1 = new Thread(new Runnable() {
498                  public void run() {
499                      try {
# Line 551 | Line 541 | public class ReentrantLockTest extends J
541              lock.unlock();
542              t1.join(SHORT_DELAY_MS);
543              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);
544              assertFalse(t1.isAlive());
545              assertFalse(t2.isAlive());
546          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines