Class ReentrantLockTest

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

public class ReentrantLockTest
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
ReentrantLockTest()
           
 
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()
          getHoldCount returns number of recursive holds
 void testGetQueuedThreads()
          getQueuedThreads includes waiting threads
 void testGetQueueLength_fair()
          getQueueLength reports number of waiting threads
 void testGetQueueLength()
          getQueueLength reports number of waiting threads
 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 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 testIsLocked()
          isLocked is true when locked and false when not
 void testLock()
          locking an unlocked lock succeeds
 void testLockInterruptibly_Interrupted()
          lockInterruptibly is interruptible.
 void testLockInterruptibly_Interrupted2()
          lockInterruptibly succeeds when unlocked, else is interruptible
 void testSerialization()
          A serialized lock deserializes as unlocked
 void testSignal_IllegalMonitor()
          Calling signal without holding lock throws IllegalMonitorStateException
 void testSignalAll()
          signalAll wakes up all threads
 void testToString()
          toString indicates current lock state
 void testTryLock_Interrupted()
          timed tryLock is interruptible.
 void testTryLock_Timeout()
          Timed tryLock on a locked lock times out
 void testTryLock()
          tryLock on an unlocked lock succeeds
 void testTryLockWhenLocked()
          tryLock on a locked lock fails
 void testUnlock_IllegalMonitorStateException()
          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

ReentrantLockTest

public ReentrantLockTest()
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()
locking an unlocked lock succeeds


testFairLock

public void testFairLock()
locking an unlocked fair lock succeeds


testUnlock_IllegalMonitorStateException

public void testUnlock_IllegalMonitorStateException()
Unlocking an unlocked lock throws IllegalMonitorStateException


testTryLock

public void testTryLock()
tryLock on an unlocked lock succeeds


testHasQueuedThreads

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

Throws:
java.lang.InterruptedException

testGetQueueLength

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

Throws:
java.lang.InterruptedException

testGetQueueLength_fair

public void testGetQueueLength_fair()
                             throws java.lang.InterruptedException
getQueueLength reports number of 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

testGetQueuedThreads

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

Throws:
java.lang.InterruptedException

testTryLock_Interrupted

public void testTryLock_Interrupted()
                             throws java.lang.InterruptedException
timed tryLock is interruptible.

Throws:
java.lang.InterruptedException

testTryLockWhenLocked

public void testTryLockWhenLocked()
                           throws java.lang.InterruptedException
tryLock on a locked lock fails

Throws:
java.lang.InterruptedException

testTryLock_Timeout

public void testTryLock_Timeout()
                         throws java.lang.InterruptedException
Timed tryLock on a locked lock times out

Throws:
java.lang.InterruptedException

testGetHoldCount

public void testGetHoldCount()
getHoldCount returns number of recursive holds


testIsLocked

public void testIsLocked()
                  throws java.lang.Exception
isLocked is true when locked and false when not

Throws:
java.lang.Exception

testLockInterruptibly_Interrupted

public void testLockInterruptibly_Interrupted()
                                       throws java.lang.InterruptedException
lockInterruptibly is interruptible.

Throws:
java.lang.InterruptedException

testLockInterruptibly_Interrupted2

public void testLockInterruptibly_Interrupted2()
                                        throws java.lang.InterruptedException
lockInterruptibly succeeds when unlocked, 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


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

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

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

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

testToString

public void testToString()
toString indicates current lock state