ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ReentrantReadWriteLockTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ReentrantReadWriteLockTest.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 ReentrantReadWriteLockTest
56          public Collection<Thread> getQueuedThreads() {
57              return super.getQueuedThreads();
58          }
59        public PublicCondition newCondition() {
60            return new PublicCondition();
61        }
62
63        class PublicCondition extends ReentrantReadWriteLock.WriterConditionObject {
64            PublicCondition() { }
65            public Collection<Thread> getWaitingThreads() {
66                return super.getWaitingThreads();
67            }
68        }
69
59      }
60  
61      /**
# Line 920 | Line 909 | public class ReentrantReadWriteLockTest
909       */
910      public void testHasWaiters() {
911          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();      
912 <        final ReentrantReadWriteLock.WriterConditionObject c = (ReentrantReadWriteLock.WriterConditionObject)(lock.writeLock().newCondition());
912 >        final AbstractQueuedSynchronizer.ConditionObject c = (lock.writeLock().newCondition());
913          Thread t = new Thread(new Runnable() {
914                  public void run() {
915                      try {
# Line 962 | Line 951 | public class ReentrantReadWriteLockTest
951       */
952      public void testGetWaitQueueLength() {
953          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();      
954 <        final ReentrantReadWriteLock.WriterConditionObject c = (ReentrantReadWriteLock.WriterConditionObject)(lock.writeLock().newCondition());
954 >        final AbstractQueuedSynchronizer.ConditionObject c = (lock.writeLock().newCondition());
955          Thread t1 = new Thread(new Runnable() {
956                  public void run() {
957                      try {
# Line 1017 | Line 1006 | public class ReentrantReadWriteLockTest
1006              unexpectedException();
1007          }
1008      }
1020
1021    /**
1022     * getWaitingThreads returns only and all waiting threads
1023     */
1024    public void testGetWaitingThreads() {
1025        final PublicReentrantReadWriteLock lock = new PublicReentrantReadWriteLock();  
1026        final PublicReentrantReadWriteLock.PublicCondition c = (PublicReentrantReadWriteLock.PublicCondition)lock.newCondition();
1027        Thread t1 = new Thread(new Runnable() {
1028                public void run() {
1029                    try {
1030                        lock.writeLock().lock();
1031                        threadAssertTrue(c.getWaitingThreads().isEmpty());
1032                        c.await();
1033                        lock.writeLock().unlock();
1034                    }
1035                    catch(InterruptedException e) {
1036                        threadUnexpectedException();
1037                    }
1038                }
1039            });
1040
1041        Thread t2 = new Thread(new Runnable() {
1042                public void run() {
1043                    try {
1044                        lock.writeLock().lock();
1045                        threadAssertFalse(c.getWaitingThreads().isEmpty());
1046                        c.await();
1047                        lock.writeLock().unlock();
1048                    }
1049                    catch(InterruptedException e) {
1050                        threadUnexpectedException();
1051                    }
1052                }
1053            });
1054
1055        try {
1056            lock.writeLock().lock();
1057            assertTrue(c.getWaitingThreads().isEmpty());
1058            lock.writeLock().unlock();
1059            t1.start();
1060            Thread.sleep(SHORT_DELAY_MS);
1061            t2.start();
1062            Thread.sleep(SHORT_DELAY_MS);
1063            lock.writeLock().lock();
1064            assertTrue(c.hasWaiters());
1065            assertTrue(c.getWaitingThreads().contains(t1));
1066            assertTrue(c.getWaitingThreads().contains(t2));
1067            c.signalAll();
1068            lock.writeLock().unlock();
1069            Thread.sleep(SHORT_DELAY_MS);
1070            lock.writeLock().lock();
1071            assertFalse(c.hasWaiters());
1072            assertTrue(c.getWaitingThreads().isEmpty());
1073            lock.writeLock().unlock();
1074            t1.join(SHORT_DELAY_MS);
1075            t2.join(SHORT_DELAY_MS);
1076            assertFalse(t1.isAlive());
1077            assertFalse(t2.isAlive());
1078        }
1079        catch (Exception ex) {
1080            unexpectedException();
1081        }
1082    }
1083
1009   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines