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.9 by dl, Mon Dec 22 00:48:56 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 ReentrantReadWriteLockTest
57          public Collection<Thread> getQueuedThreads() {
58              return super.getQueuedThreads();
59          }
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
60      }
61  
62      /**
# Line 920 | Line 910 | public class ReentrantReadWriteLockTest
910       */
911      public void testHasWaiters() {
912          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();      
913 <        final ReentrantReadWriteLock.WriterConditionObject c = (ReentrantReadWriteLock.WriterConditionObject)(lock.writeLock().newCondition());
913 >        final AbstractQueuedSynchronizer.ConditionObject c = (lock.writeLock().newCondition());
914          Thread t = new Thread(new Runnable() {
915                  public void run() {
916                      try {
# Line 962 | Line 952 | public class ReentrantReadWriteLockTest
952       */
953      public void testGetWaitQueueLength() {
954          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();      
955 <        final ReentrantReadWriteLock.WriterConditionObject c = (ReentrantReadWriteLock.WriterConditionObject)(lock.writeLock().newCondition());
955 >        final AbstractQueuedSynchronizer.ConditionObject c = (lock.writeLock().newCondition());
956          Thread t1 = new Thread(new Runnable() {
957                  public void run() {
958                      try {
# Line 1017 | Line 1007 | public class ReentrantReadWriteLockTest
1007              unexpectedException();
1008          }
1009      }
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
1010   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines