507 |
|
|
508 |
|
/** |
509 |
|
* A thread that tries to acquire a fair read lock (non-reentrantly) |
510 |
< |
* will block if there is a waiting writer thread. |
510 |
> |
* will block if there is a waiting writer thread |
511 |
|
*/ |
512 |
|
public void testReaderWriterReaderFairFifo() { |
513 |
|
final PublicReentrantReadWriteLock lock = |
584 |
|
} |
585 |
|
|
586 |
|
/** |
587 |
< |
* Read trylock succeeds (barging) even in the presence of waiting readers and/or writers. |
587 |
> |
* Read trylock succeeds (barging) even in the presence of waiting |
588 |
> |
* readers and/or writers |
589 |
|
*/ |
590 |
|
public void testReadTryLockBarging() { testReadTryLockBarging(false); } |
591 |
|
public void testReadTryLockBarging_fair() { testReadTryLockBarging(true); } |
1112 |
|
} |
1113 |
|
|
1114 |
|
/** |
1115 |
< |
* signal wakes up waiting threads in FIFO order. |
1115 |
> |
* signal wakes up waiting threads in FIFO order |
1116 |
|
*/ |
1117 |
|
public void testSignalWakesFifo() { testSignalWakesFifo(false); } |
1118 |
|
public void testSignalWakesFifo_fair() { testSignalWakesFifo(true); } |
1273 |
|
} |
1274 |
|
|
1275 |
|
/** |
1276 |
< |
* hasQueuedThread reports whether a thread is queued. |
1276 |
> |
* hasQueuedThread reports whether a thread is queued |
1277 |
|
*/ |
1278 |
|
public void testHasQueuedThread() { testHasQueuedThread(false); } |
1279 |
|
public void testHasQueuedThread_fair() { testHasQueuedThread(true); } |
1614 |
|
public void testToString_fair() { testToString(true); } |
1615 |
|
public void testToString(boolean fair) { |
1616 |
|
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair); |
1617 |
< |
String us = lock.toString(); |
1618 |
< |
assertTrue(us.indexOf("Write locks = 0") >= 0); |
1619 |
< |
assertTrue(us.indexOf("Read locks = 0") >= 0); |
1620 |
< |
lock.writeLock().lock(); |
1621 |
< |
String ws = lock.toString(); |
1621 |
< |
assertTrue(ws.indexOf("Write locks = 1") >= 0); |
1622 |
< |
assertTrue(ws.indexOf("Read locks = 0") >= 0); |
1617 |
> |
assertTrue(lock.toString().contains("Write locks = 0")); |
1618 |
> |
assertTrue(lock.toString().contains("Read locks = 0")); |
1619 |
> |
lock.writeLock().lock(); |
1620 |
> |
assertTrue(lock.toString().contains("Write locks = 1")); |
1621 |
> |
assertTrue(lock.toString().contains("Read locks = 0")); |
1622 |
|
lock.writeLock().unlock(); |
1623 |
|
lock.readLock().lock(); |
1624 |
|
lock.readLock().lock(); |
1625 |
< |
String rs = lock.toString(); |
1626 |
< |
assertTrue(rs.indexOf("Write locks = 0") >= 0); |
1628 |
< |
assertTrue(rs.indexOf("Read locks = 2") >= 0); |
1625 |
> |
assertTrue(lock.toString().contains("Write locks = 0")); |
1626 |
> |
assertTrue(lock.toString().contains("Read locks = 2")); |
1627 |
|
} |
1628 |
|
|
1629 |
|
/** |
1633 |
|
public void testReadLockToString_fair() { testReadLockToString(true); } |
1634 |
|
public void testReadLockToString(boolean fair) { |
1635 |
|
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair); |
1636 |
< |
String us = lock.readLock().toString(); |
1639 |
< |
assertTrue(us.indexOf("Read locks = 0") >= 0); |
1636 |
> |
assertTrue(lock.readLock().toString().contains("Read locks = 0")); |
1637 |
|
lock.readLock().lock(); |
1638 |
|
lock.readLock().lock(); |
1639 |
< |
String rs = lock.readLock().toString(); |
1643 |
< |
assertTrue(rs.indexOf("Read locks = 2") >= 0); |
1639 |
> |
assertTrue(lock.readLock().toString().contains("Read locks = 2")); |
1640 |
|
} |
1641 |
|
|
1642 |
|
/** |
1646 |
|
public void testWriteLockToString_fair() { testWriteLockToString(true); } |
1647 |
|
public void testWriteLockToString(boolean fair) { |
1648 |
|
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair); |
1649 |
< |
String us = lock.writeLock().toString(); |
1654 |
< |
assertTrue(us.indexOf("Unlocked") >= 0); |
1649 |
> |
assertTrue(lock.writeLock().toString().contains("Unlocked")); |
1650 |
|
lock.writeLock().lock(); |
1651 |
< |
String ls = lock.writeLock().toString(); |
1652 |
< |
assertTrue(ls.indexOf("Locked") >= 0); |
1651 |
> |
assertTrue(lock.writeLock().toString().contains("Locked")); |
1652 |
> |
lock.writeLock().unlock(); |
1653 |
> |
assertTrue(lock.writeLock().toString().contains("Unlocked")); |
1654 |
|
} |
1655 |
|
|
1656 |
|
} |