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.8 by dl, Fri Dec 19 14:44:25 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(this);
61        }
62
63        static class PublicCondition extends ReentrantReadWriteLock.WriterConditionObject {
64            PublicCondition(PublicReentrantReadWriteLock l) { super(l); }
65            public Collection<Thread> getWaitingThreads() {
66                return super.getWaitingThreads();
67            }
68        }
69
59      }
60  
61      /**
# Line 76 | Line 65 | public class ReentrantReadWriteLockTest
65          ReentrantReadWriteLock rl = new ReentrantReadWriteLock();
66          assertFalse(rl.isFair());
67          assertFalse(rl.isWriteLocked());
68 <        assertEquals(0, rl.getReadLocks());
68 >        assertEquals(0, rl.getReadLockCount());
69          ReentrantReadWriteLock r2 = new ReentrantReadWriteLock(true);
70          assertTrue(r2.isFair());
71          assertFalse(r2.isWriteLocked());
72 <        assertEquals(0, r2.getReadLocks());
72 >        assertEquals(0, r2.getReadLockCount());
73      }
74  
75      /**
# Line 91 | Line 80 | public class ReentrantReadWriteLockTest
80          rl.writeLock().lock();
81          assertTrue(rl.isWriteLocked());
82          assertTrue(rl.isWriteLockedByCurrentThread());
83 <        assertEquals(0, rl.getReadLocks());
83 >        assertEquals(0, rl.getReadLockCount());
84          rl.writeLock().unlock();
85          assertFalse(rl.isWriteLocked());
86          assertFalse(rl.isWriteLockedByCurrentThread());
87 <        assertEquals(0, rl.getReadLocks());
87 >        assertEquals(0, rl.getReadLockCount());
88          rl.readLock().lock();
89          assertFalse(rl.isWriteLocked());
90          assertFalse(rl.isWriteLockedByCurrentThread());
91 <        assertEquals(1, rl.getReadLocks());
91 >        assertEquals(1, rl.getReadLockCount());
92          rl.readLock().unlock();
93          assertFalse(rl.isWriteLocked());
94          assertFalse(rl.isWriteLockedByCurrentThread());
95 <        assertEquals(0, rl.getReadLocks());
95 >        assertEquals(0, rl.getReadLockCount());
96      }
97  
98  
# Line 115 | Line 104 | public class ReentrantReadWriteLockTest
104          rl.writeLock().lock();
105          assertTrue(rl.isWriteLocked());
106          assertTrue(rl.isWriteLockedByCurrentThread());
107 <        assertEquals(0, rl.getReadLocks());
107 >        assertEquals(0, rl.getReadLockCount());
108          rl.writeLock().unlock();
109          assertFalse(rl.isWriteLocked());
110          assertFalse(rl.isWriteLockedByCurrentThread());
111 <        assertEquals(0, rl.getReadLocks());
111 >        assertEquals(0, rl.getReadLockCount());
112          rl.readLock().lock();
113          assertFalse(rl.isWriteLocked());
114          assertFalse(rl.isWriteLockedByCurrentThread());
115 <        assertEquals(1, rl.getReadLocks());
115 >        assertEquals(1, rl.getReadLockCount());
116          rl.readLock().unlock();
117          assertFalse(rl.isWriteLocked());
118          assertFalse(rl.isWriteLockedByCurrentThread());
119 <        assertEquals(0, rl.getReadLocks());
119 >        assertEquals(0, rl.getReadLockCount());
120      }
121  
122      /**
# 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