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.15 by dl, Mon Dec 29 19:05:40 2003 UTC vs.
Revision 1.18 by dl, Sat Jan 10 01:41:59 2004 UTC

# Line 156 | Line 156 | public class ReentrantReadWriteLockTest
156       */
157      public void testWriteLockInterruptibly_Interrupted() {
158          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
159        lock.writeLock().lock();
159          Thread t = new Thread(new Runnable() {
160                  public void run() {
161                      try {
162                          lock.writeLock().lockInterruptibly();
163 <                        threadShouldThrow();
163 >                        lock.writeLock().unlock();
164 >                        lock.writeLock().lockInterruptibly();
165 >                        lock.writeLock().unlock();
166                      } catch(InterruptedException success){}
167                  }
168              });
169          try {
170 +            lock.writeLock().lock();
171              t.start();
172              t.interrupt();
173              lock.writeLock().unlock();
# Line 185 | Line 187 | public class ReentrantReadWriteLockTest
187                  public void run() {
188                      try {
189                          lock.writeLock().tryLock(1000,TimeUnit.MILLISECONDS);
188                        threadShouldThrow();
190                      } catch(InterruptedException success){}
191                  }
192              });
# Line 209 | Line 210 | public class ReentrantReadWriteLockTest
210                  public void run() {
211                      try {
212                          lock.readLock().lockInterruptibly();
212                        threadShouldThrow();
213                      } catch(InterruptedException success){}
214                  }
215              });
# Line 1224 | Line 1224 | public class ReentrantReadWriteLockTest
1224          }
1225      }
1226  
1227 +    /**
1228 +     * toString indicates current lock state
1229 +     */
1230 +    public void testToString() {
1231 +        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1232 +        String us = lock.toString();
1233 +        assertTrue(us.indexOf("Write locks = 0") >= 0);
1234 +        assertTrue(us.indexOf("Read locks = 0") >= 0);
1235 +        lock.writeLock().lock();
1236 +        String ws = lock.toString();
1237 +        assertTrue(ws.indexOf("Write locks = 1") >= 0);
1238 +        assertTrue(ws.indexOf("Read locks = 0") >= 0);
1239 +        lock.writeLock().unlock();
1240 +        lock.readLock().lock();
1241 +        lock.readLock().lock();
1242 +        String rs = lock.toString();
1243 +        assertTrue(rs.indexOf("Write locks = 0") >= 0);
1244 +        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1245 +    }
1246 +
1247 +    /**
1248 +     * readLock.toString indicates current lock state
1249 +     */
1250 +    public void testReadLockToString() {
1251 +        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1252 +        String us = lock.readLock().toString();
1253 +        assertTrue(us.indexOf("Read locks = 0") >= 0);
1254 +        lock.readLock().lock();
1255 +        lock.readLock().lock();
1256 +        String rs = lock.readLock().toString();
1257 +        assertTrue(rs.indexOf("Read locks = 2") >= 0);
1258 +    }
1259 +
1260 +    /**
1261 +     * writeLock.toString indicates current lock state
1262 +     */
1263 +    public void testWriteLockToString() {
1264 +        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1265 +        String us = lock.writeLock().toString();
1266 +        assertTrue(us.indexOf("Unlocked") >= 0);
1267 +        lock.writeLock().lock();
1268 +        String ls = lock.writeLock().toString();
1269 +        assertTrue(ls.indexOf("Locked") >= 0);
1270 +    }
1271 +
1272   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines