Class ReentrantReadWriteLockTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by JSR166TestCase
              extended by ReentrantReadWriteLockTest
All Implemented Interfaces:
junit.framework.Test

public class ReentrantReadWriteLockTest
extends JSR166TestCase


Nested Class Summary
 
Nested classes/interfaces inherited from class JSR166TestCase
JSR166TestCase.AdjustablePolicy, JSR166TestCase.CallableOne, JSR166TestCase.CheckedBarrier, JSR166TestCase.CheckedCallable<T>, JSR166TestCase.CheckedInterruptedCallable<T>, JSR166TestCase.CheckedInterruptedRunnable, JSR166TestCase.CheckedRecursiveAction, JSR166TestCase.CheckedRecursiveTask<T>, JSR166TestCase.CheckedRunnable, JSR166TestCase.LongPossiblyInterruptedRunnable, JSR166TestCase.MediumInterruptedRunnable, JSR166TestCase.MediumPossiblyInterruptedRunnable, JSR166TestCase.MediumRunnable, JSR166TestCase.NoOpCallable, JSR166TestCase.NoOpREHandler, JSR166TestCase.NoOpRunnable, JSR166TestCase.NPETask, JSR166TestCase.RunnableShouldThrow, JSR166TestCase.ShortInterruptedRunnable, JSR166TestCase.ShortRunnable, JSR166TestCase.SimpleThreadFactory, JSR166TestCase.SmallCallable, JSR166TestCase.SmallPossiblyInterruptedRunnable, JSR166TestCase.SmallRunnable, JSR166TestCase.StringTask, JSR166TestCase.ThreadShouldThrow, JSR166TestCase.TrackedCallable, JSR166TestCase.TrackedLongRunnable, JSR166TestCase.TrackedMediumRunnable, JSR166TestCase.TrackedNoOpRunnable, JSR166TestCase.TrackedRunnable, JSR166TestCase.TrackedShortRunnable, JSR166TestCase.TrackedSmallRunnable
 
Field Summary
 
Fields inherited from class JSR166TestCase
eight, expensiveTests, five, four, LONG_DELAY_MS, m1, m10, m2, m3, m4, m5, m6, MEDIUM_DELAY_MS, nine, one, seven, SHORT_DELAY_MS, six, SIZE, SMALL_DELAY_MS, TEST_STRING, three, two, zero
 
Constructor Summary
ReentrantReadWriteLockTest()
           
 
Method Summary
static void main(java.lang.String[] args)
           
static junit.framework.Test suite()
           
 void testAwait_IllegalMonitor()
          Calling await without holding lock throws IllegalMonitorStateException
 void testAwait_Interrupt()
          await is interruptible
 void testAwait_Timeout()
          timed await without a signal times out
 void testAwait()
          await returns when signalled
 void testAwaitLockCount()
          await after multiple reentrant locking preserves lock count
 void testAwaitNanos_Interrupt()
          awaitNanos is interruptible
 void testAwaitNanos_Timeout()
          awaitNanos without a signal times out
 void testAwaitUninterruptibly()
          awaitUninterruptibly doesn't abort on interrupt
 void testAwaitUntil_Interrupt()
          awaitUntil is interruptible
 void testAwaitUntil_Timeout()
          awaitUntil without a signal times out
 void testConstructor()
          Constructor sets given fairness, and is in unlocked state
 void testFairLock()
          locking an unlocked fair lock succeeds
 void testGetHoldCount()
          WriteLock.getHoldCount returns number of recursive holds
 void testGetQueuedThreads()
          getQueuedThreads includes waiting threads
 void testGetQueueLength()
          getQueueLength reports number of waiting threads
 void testGetReadHoldCount()
          getReadHoldCount returns number of recursive holds
 void testGetWaitingThreads()
          getWaitingThreads returns only and all waiting threads
 void testGetWaitingThreadsIAE()
          getWaitingThreads throws IllegalArgumentException if not owned
 void testGetWaitingThreadsIMSE()
          getWaitingThreads throws IllegalMonitorStateException if not locked
 void testGetWaitingThreadsNPE()
          getWaitingThreads throws NPE if null
 void testGetWaitQueueLength()
          getWaitQueueLength returns number of waiting threads
 void testGetWaitQueueLengthIAE()
          getWaitQueueLength throws IllegalArgumentException if not owned
 void testGetWaitQueueLengthIMSE()
          getWaitQueueLength throws IllegalMonitorStateException if not locked
 void testGetWaitQueueLengthNPE()
          getWaitQueueLength throws NPE if null
 void testGetWriteHoldCount()
          getWriteHoldCount returns number of recursive holds
 void testHasQueuedThread()
          hasQueuedThread reports whether a thread is queued.
 void testHasQueuedThreadNPE()
          hasQueuedThread(null) throws NPE
 void testHasQueuedThreads()
          hasQueuedThreads reports whether there are waiting threads
 void testHasWaiters()
          hasWaiters returns true when a thread is waiting, else false
 void testHasWaitersIAE()
          hasWaiters throws IllegalArgumentException if not owned
 void testHasWaitersIMSE()
          hasWaiters throws IllegalMonitorStateException if not locked
 void testHasWaitersNPE()
          hasWaiters throws NPE if null
 void testLock()
          write-locking and read-locking an unlocked lock succeed
 void testMultipleReadLocks()
          Multiple threads can hold a read lock when not write-locked
 void testReadAfterWriteLock()
          Readlocks succeed only after a writing thread unlocks
 void testReaderWriterReaderFairFifo()
          A thread that tries to acquire a fair read lock (non-reentrantly) will block if there is a waiting writer thread.
 void testReadHoldingWriteLock()
          Read trylock succeeds if write locked by current thread
 void testReadHoldingWriteLock2()
          Read lock succeeds if write locked by current thread even if other threads are waiting for readlock
 void testReadHoldingWriteLock3()
          Read lock succeeds if write locked by current thread even if other threads are waiting for writelock
 void testReadHoldingWriteLockFair()
          Fair Read trylock succeeds if write locked by current thread
 void testReadHoldingWriteLockFair2()
          Fair Read lock succeeds if write locked by current thread even if other threads are waiting for readlock
 void testReadHoldingWriteLockFair3()
          Fair Read lock succeeds if write locked by current thread even if other threads are waiting for writelock
 void testReadLockInterruptibly_Interrupted()
          read-lockInterruptibly is interruptible
 void testReadLockInterruptibly()
          read lockInterruptibly succeeds if lock free else is interruptible
 void testReadLockToString()
          readLock.toString indicates current lock state
 void testReadTryLock_Interrupted()
          timed read-tryLock is interruptible
 void testReadTryLock_Timeout()
          read timed tryLock times out if write-locked
 void testReadTryLockWhenLocked()
          read-tryLock fails if locked
 void testReadUnlock_IllegalMonitorStateException()
          read-unlocking an unlocked lock throws IllegalMonitorStateException
 void testSerialization()
          A serialized lock deserializes as unlocked
 void testSignal_IllegalMonitor()
          Calling signal without holding lock throws IllegalMonitorStateException
 void testSignalAll_IllegalMonitor()
          Calling signalAll without holding lock throws IllegalMonitorStateException
 void testSignalAll()
          signalAll wakes up all threads
 void testSignalWakesFifo()
          signal wakes up waiting threads in FIFO order.
 void testToString()
          toString indicates current lock state
 void testTryLockWhenReadLocked()
          Read tryLock succeeds if readlocked but not writelocked
 void testTryLockWhenReadLockedFair()
          Fair Read tryLock succeeds if readlocked but not writelocked
 void testWriteAfterMultipleReadLocks()
          A writelock succeeds only after reading threads unlock
 void testWriteAfterReadLock()
          A writelock succeeds only after a reading thread unlocks
 void testWriteHoldingWriteLock4()
          Write lock succeeds if write locked by current thread even if other threads are waiting for writelock
 void testWriteHoldingWriteLockFair4()
          Fair Write lock succeeds if write locked by current thread even if other threads are waiting for writelock
 void testWriteLockInterruptibly_Interrupted()
          write-lockInterruptibly is interruptible
 void testWriteLockInterruptibly()
          write lockInterruptibly succeeds if lock free else is interruptible
 void testWriteLockToString()
          writeLock.toString indicates current lock state
 void testWriteTryLock_Interrupted()
          timed write-tryLock is interruptible
 void testWriteTryLock_Timeout()
          write timed tryLock times out if locked
 void testWriteTryLockWhenLocked()
          write-tryLock fails if locked
 void testWriteTryLockWhenReadLocked()
          write tryLock fails when readlocked
 void testWriteTryLockWhenReadLockedFair()
          Fair write tryLock fails when readlocked
 void testWriteUnlock_IllegalMonitorStateException()
          write-unlocking an unlocked lock throws IllegalMonitorStateException
 
Methods inherited from class JSR166TestCase
assertThreadJoinTimesOut, awaiter, checkEmpty, delay, getShortDelay, joinPool, latchAwaitingStringTask, newTestSuite, permissivePolicy, possiblyInterruptedRunnable, runTest, runTestProfiled, runWithoutPermissions, runWithPermissions, setDelays, setUp, shouldThrow, shouldThrow, tearDown, threadAssertEquals, threadAssertEquals, threadAssertFalse, threadAssertNull, threadAssertSame, threadAssertTrue, threadFail, threadRecordFailure, threadShouldThrow, threadShouldThrow, threadUnexpectedException, trackedRunnable
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReentrantReadWriteLockTest

public ReentrantReadWriteLockTest()
Method Detail

main

public static void main(java.lang.String[] args)

suite

public static junit.framework.Test suite()

testConstructor

public void testConstructor()
Constructor sets given fairness, and is in unlocked state


testLock

public void testLock()
write-locking and read-locking an unlocked lock succeed


testFairLock

public void testFairLock()
locking an unlocked fair lock succeeds


testGetWriteHoldCount

public void testGetWriteHoldCount()
getWriteHoldCount returns number of recursive holds


testGetHoldCount

public void testGetHoldCount()
WriteLock.getHoldCount returns number of recursive holds


testGetReadHoldCount

public void testGetReadHoldCount()
getReadHoldCount returns number of recursive holds


testWriteUnlock_IllegalMonitorStateException

public void testWriteUnlock_IllegalMonitorStateException()
write-unlocking an unlocked lock throws IllegalMonitorStateException


testReadUnlock_IllegalMonitorStateException

public void testReadUnlock_IllegalMonitorStateException()
read-unlocking an unlocked lock throws IllegalMonitorStateException


testWriteLockInterruptibly_Interrupted

public void testWriteLockInterruptibly_Interrupted()
                                            throws java.lang.Exception
write-lockInterruptibly is interruptible

Throws:
java.lang.Exception

testWriteTryLock_Interrupted

public void testWriteTryLock_Interrupted()
                                  throws java.lang.InterruptedException
timed write-tryLock is interruptible

Throws:
java.lang.InterruptedException

testReadLockInterruptibly_Interrupted

public void testReadLockInterruptibly_Interrupted()
                                           throws java.lang.InterruptedException
read-lockInterruptibly is interruptible

Throws:
java.lang.InterruptedException

testReadTryLock_Interrupted

public void testReadTryLock_Interrupted()
                                 throws java.lang.InterruptedException
timed read-tryLock is interruptible

Throws:
java.lang.InterruptedException

testWriteTryLockWhenLocked

public void testWriteTryLockWhenLocked()
                                throws java.lang.InterruptedException
write-tryLock fails if locked

Throws:
java.lang.InterruptedException

testReadTryLockWhenLocked

public void testReadTryLockWhenLocked()
                               throws java.lang.InterruptedException
read-tryLock fails if locked

Throws:
java.lang.InterruptedException

testMultipleReadLocks

public void testMultipleReadLocks()
                           throws java.lang.InterruptedException
Multiple threads can hold a read lock when not write-locked

Throws:
java.lang.InterruptedException

testWriteAfterReadLock

public void testWriteAfterReadLock()
                            throws java.lang.InterruptedException
A writelock succeeds only after a reading thread unlocks

Throws:
java.lang.InterruptedException

testWriteAfterMultipleReadLocks

public void testWriteAfterMultipleReadLocks()
                                     throws java.lang.InterruptedException
A writelock succeeds only after reading threads unlock

Throws:
java.lang.InterruptedException

testReaderWriterReaderFairFifo

public void testReaderWriterReaderFairFifo()
                                    throws java.lang.InterruptedException
A thread that tries to acquire a fair read lock (non-reentrantly) will block if there is a waiting writer thread.

Throws:
java.lang.InterruptedException

testReadAfterWriteLock

public void testReadAfterWriteLock()
                            throws java.lang.InterruptedException
Readlocks succeed only after a writing thread unlocks

Throws:
java.lang.InterruptedException

testReadHoldingWriteLock

public void testReadHoldingWriteLock()
Read trylock succeeds if write locked by current thread


testReadHoldingWriteLock2

public void testReadHoldingWriteLock2()
                               throws java.lang.InterruptedException
Read lock succeeds if write locked by current thread even if other threads are waiting for readlock

Throws:
java.lang.InterruptedException

testReadHoldingWriteLock3

public void testReadHoldingWriteLock3()
                               throws java.lang.InterruptedException
Read lock succeeds if write locked by current thread even if other threads are waiting for writelock

Throws:
java.lang.InterruptedException

testWriteHoldingWriteLock4

public void testWriteHoldingWriteLock4()
                                throws java.lang.InterruptedException
Write lock succeeds if write locked by current thread even if other threads are waiting for writelock

Throws:
java.lang.InterruptedException

testReadHoldingWriteLockFair

public void testReadHoldingWriteLockFair()
Fair Read trylock succeeds if write locked by current thread


testReadHoldingWriteLockFair2

public void testReadHoldingWriteLockFair2()
                                   throws java.lang.InterruptedException
Fair Read lock succeeds if write locked by current thread even if other threads are waiting for readlock

Throws:
java.lang.InterruptedException

testReadHoldingWriteLockFair3

public void testReadHoldingWriteLockFair3()
                                   throws java.lang.InterruptedException
Fair Read lock succeeds if write locked by current thread even if other threads are waiting for writelock

Throws:
java.lang.InterruptedException

testWriteHoldingWriteLockFair4

public void testWriteHoldingWriteLockFair4()
                                    throws java.lang.InterruptedException
Fair Write lock succeeds if write locked by current thread even if other threads are waiting for writelock

Throws:
java.lang.InterruptedException

testTryLockWhenReadLocked

public void testTryLockWhenReadLocked()
                               throws java.lang.InterruptedException
Read tryLock succeeds if readlocked but not writelocked

Throws:
java.lang.InterruptedException

testWriteTryLockWhenReadLocked

public void testWriteTryLockWhenReadLocked()
                                    throws java.lang.InterruptedException
write tryLock fails when readlocked

Throws:
java.lang.InterruptedException

testTryLockWhenReadLockedFair

public void testTryLockWhenReadLockedFair()
                                   throws java.lang.InterruptedException
Fair Read tryLock succeeds if readlocked but not writelocked

Throws:
java.lang.InterruptedException

testWriteTryLockWhenReadLockedFair

public void testWriteTryLockWhenReadLockedFair()
                                        throws java.lang.InterruptedException
Fair write tryLock fails when readlocked

Throws:
java.lang.InterruptedException

testWriteTryLock_Timeout

public void testWriteTryLock_Timeout()
                              throws java.lang.InterruptedException
write timed tryLock times out if locked

Throws:
java.lang.InterruptedException

testReadTryLock_Timeout

public void testReadTryLock_Timeout()
                             throws java.lang.InterruptedException
read timed tryLock times out if write-locked

Throws:
java.lang.InterruptedException

testWriteLockInterruptibly

public void testWriteLockInterruptibly()
                                throws java.lang.InterruptedException
write lockInterruptibly succeeds if lock free else is interruptible

Throws:
java.lang.InterruptedException

testReadLockInterruptibly

public void testReadLockInterruptibly()
                               throws java.lang.InterruptedException
read lockInterruptibly succeeds if lock free else is interruptible

Throws:
java.lang.InterruptedException

testAwait_IllegalMonitor

public void testAwait_IllegalMonitor()
                              throws java.lang.InterruptedException
Calling await without holding lock throws IllegalMonitorStateException

Throws:
java.lang.InterruptedException

testSignal_IllegalMonitor

public void testSignal_IllegalMonitor()
Calling signal without holding lock throws IllegalMonitorStateException


testSignalAll_IllegalMonitor

public void testSignalAll_IllegalMonitor()
Calling signalAll without holding lock throws IllegalMonitorStateException


testAwaitNanos_Timeout

public void testAwaitNanos_Timeout()
                            throws java.lang.InterruptedException
awaitNanos without a signal times out

Throws:
java.lang.InterruptedException

testAwait_Timeout

public void testAwait_Timeout()
                       throws java.lang.InterruptedException
timed await without a signal times out

Throws:
java.lang.InterruptedException

testAwaitUntil_Timeout

public void testAwaitUntil_Timeout()
                            throws java.lang.InterruptedException
awaitUntil without a signal times out

Throws:
java.lang.InterruptedException

testAwait

public void testAwait()
               throws java.lang.InterruptedException
await returns when signalled

Throws:
java.lang.InterruptedException

testAwaitUninterruptibly

public void testAwaitUninterruptibly()
                              throws java.lang.InterruptedException
awaitUninterruptibly doesn't abort on interrupt

Throws:
java.lang.InterruptedException

testAwait_Interrupt

public void testAwait_Interrupt()
                         throws java.lang.InterruptedException
await is interruptible

Throws:
java.lang.InterruptedException

testAwaitNanos_Interrupt

public void testAwaitNanos_Interrupt()
                              throws java.lang.InterruptedException
awaitNanos is interruptible

Throws:
java.lang.InterruptedException

testAwaitUntil_Interrupt

public void testAwaitUntil_Interrupt()
                              throws java.lang.InterruptedException
awaitUntil is interruptible

Throws:
java.lang.InterruptedException

testSignalAll

public void testSignalAll()
                   throws java.lang.InterruptedException
signalAll wakes up all threads

Throws:
java.lang.InterruptedException

testSignalWakesFifo

public void testSignalWakesFifo()
                         throws java.lang.InterruptedException
signal wakes up waiting threads in FIFO order.

Throws:
java.lang.InterruptedException

testAwaitLockCount

public void testAwaitLockCount()
                        throws java.lang.InterruptedException
await after multiple reentrant locking preserves lock count

Throws:
java.lang.InterruptedException

testSerialization

public void testSerialization()
                       throws java.lang.Exception
A serialized lock deserializes as unlocked

Throws:
java.lang.Exception

testHasQueuedThreads

public void testHasQueuedThreads()
                          throws java.lang.InterruptedException
hasQueuedThreads reports whether there are waiting threads

Throws:
java.lang.InterruptedException

testHasQueuedThreadNPE

public void testHasQueuedThreadNPE()
hasQueuedThread(null) throws NPE


testHasQueuedThread

public void testHasQueuedThread()
                         throws java.lang.InterruptedException
hasQueuedThread reports whether a thread is queued.

Throws:
java.lang.InterruptedException

testGetQueueLength

public void testGetQueueLength()
                        throws java.lang.InterruptedException
getQueueLength reports number of waiting threads

Throws:
java.lang.InterruptedException

testGetQueuedThreads

public void testGetQueuedThreads()
                          throws java.lang.InterruptedException
getQueuedThreads includes waiting threads

Throws:
java.lang.InterruptedException

testHasWaitersNPE

public void testHasWaitersNPE()
hasWaiters throws NPE if null


testGetWaitQueueLengthNPE

public void testGetWaitQueueLengthNPE()
getWaitQueueLength throws NPE if null


testGetWaitingThreadsNPE

public void testGetWaitingThreadsNPE()
getWaitingThreads throws NPE if null


testHasWaitersIAE

public void testHasWaitersIAE()
hasWaiters throws IllegalArgumentException if not owned


testHasWaitersIMSE

public void testHasWaitersIMSE()
hasWaiters throws IllegalMonitorStateException if not locked


testGetWaitQueueLengthIAE

public void testGetWaitQueueLengthIAE()
getWaitQueueLength throws IllegalArgumentException if not owned


testGetWaitQueueLengthIMSE

public void testGetWaitQueueLengthIMSE()
getWaitQueueLength throws IllegalMonitorStateException if not locked


testGetWaitingThreadsIAE

public void testGetWaitingThreadsIAE()
getWaitingThreads throws IllegalArgumentException if not owned


testGetWaitingThreadsIMSE

public void testGetWaitingThreadsIMSE()
getWaitingThreads throws IllegalMonitorStateException if not locked


testHasWaiters

public void testHasWaiters()
                    throws java.lang.InterruptedException
hasWaiters returns true when a thread is waiting, else false

Throws:
java.lang.InterruptedException

testGetWaitQueueLength

public void testGetWaitQueueLength()
                            throws java.lang.InterruptedException
getWaitQueueLength returns number of waiting threads

Throws:
java.lang.InterruptedException

testGetWaitingThreads

public void testGetWaitingThreads()
                           throws java.lang.InterruptedException
getWaitingThreads returns only and all waiting threads

Throws:
java.lang.InterruptedException

testToString

public void testToString()
toString indicates current lock state


testReadLockToString

public void testReadLockToString()
readLock.toString indicates current lock state


testWriteLockToString

public void testWriteLockToString()
writeLock.toString indicates current lock state