Class SemaphoreTest

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

public class SemaphoreTest
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
SemaphoreTest()
           
 
Method Summary
static void main(java.lang.String[] args)
           
static junit.framework.Test suite()
           
 void testAcquire_InterruptedException_fair()
          A waiting acquire blocks interruptibly
 void testAcquire_InterruptedException()
          A waiting acquire blocks interruptibly
 void testAcquireN_InterruptedException_fair()
          A waiting acquire(n) blocks interruptibly
 void testAcquireReleaseInDifferentThreads_fair()
          A release in one thread enables an acquire in another thread
 void testAcquireReleaseInDifferentThreads()
          A release in one thread enables an acquire in another thread
 void testAcquireReleaseInSameThread_fair()
          Acquire and release of semaphore succeed if initially available
 void testAcquireReleaseInSameThread()
          Acquire and release of semaphore succeed if initially available
 void testAcquireReleaseNInDifferentThreads_fair()
          release(n) in one thread enables acquire(n) in another thread
 void testAcquireReleaseNInDifferentThreads_fair2()
          release(n) in one thread enables acquire(n) in another thread
 void testAcquireReleaseNInSameThread_fair()
          Acquire(n) and release(n) of semaphore succeed if initially available
 void testAcquireUninterruptiblyReleaseInSameThread()
          Uninterruptible acquire and release of semaphore succeed if initially available
 void testAcquireUninterruptiblyReleaseNInSameThread_fair()
          Acquire(n) and release(n) of semaphore succeed if initially available
 void testConstructor_fair()
          Zero, negative, and positive initial values are allowed in constructor
 void testConstructor()
          Zero, negative, and positive initial values are allowed in constructor
 void testConstructor2()
          Constructor without fairness argument behaves as nonfair
 void testDrainPermits()
          drainPermits reports and removes given number of permits
 void testGetQueuedThreads()
          getQueuedThreads includes waiting threads
 void testGetQueueLength_fair()
          getQueueLength reports number of waiting threads
 void testGetQueueLength()
          getQueueLength reports number of waiting threads
 void testHasQueuedThreads()
          hasQueuedThreads reports whether there are waiting threads
 void testReducePermits()
          reducePermits reduces number of permits
 void testSerialization_fair()
          a deserialized serialized semaphore has same number of permits
 void testSerialization()
          a deserialized serialized semaphore has same number of permits
 void testTimedAcquireReleaseInDifferentThreads_fair()
          release in one thread enables timed acquire in another thread
 void testTimedAcquireReleaseInDifferentThreads()
          A release in one thread enables a timed acquire in another thread
 void testTimedAcquireReleaseInSameThread_fair()
          release in one thread enables timed acquire in another thread
 void testTimedAcquireReleaseInSameThread()
          Timed Acquire and release of semaphore succeed if initially available
 void testTimedAcquireReleaseNInDifferentThreads_fair()
          release(n) in one thread enables timed acquire(n) in another thread
 void testTimedAcquireReleaseNInSameThread_fair()
          release(n) in one thread enables timed acquire(n) in another thread
 void testToString()
          toString indicates current number of permits
 void testTryAcquire_InterruptedException_fair()
          A waiting tryAcquire blocks interruptibly
 void testTryAcquire_InterruptedException()
          A waiting timed acquire blocks interruptibly
 void testTryAcquireInSameThread_fair()
          tryAcquire succeeds when sufficient permits, else fails
 void testTryAcquireInSameThread()
          tryAcquire succeeds when sufficient permits, else fails
 void testTryAcquireN_InterruptedException_fair()
          A waiting tryAcquire(n) blocks interruptibly
 void testTryAcquireNInSameThread_fair()
          tryAcquire(n) succeeds when sufficient permits, else fails
 void testUninterruptibleAcquireReleaseInDifferentThreads()
          A release in one thread enables an uninterruptible acquire in another thread
 
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

SemaphoreTest

public SemaphoreTest()
Method Detail

main

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

suite

public static junit.framework.Test suite()

testConstructor

public void testConstructor()
Zero, negative, and positive initial values are allowed in constructor


testConstructor2

public void testConstructor2()
Constructor without fairness argument behaves as nonfair


testTryAcquireInSameThread

public void testTryAcquireInSameThread()
tryAcquire succeeds when sufficient permits, else fails


testAcquireReleaseInSameThread

public void testAcquireReleaseInSameThread()
                                    throws java.lang.InterruptedException
Acquire and release of semaphore succeed if initially available

Throws:
java.lang.InterruptedException

testAcquireUninterruptiblyReleaseInSameThread

public void testAcquireUninterruptiblyReleaseInSameThread()
                                                   throws java.lang.InterruptedException
Uninterruptible acquire and release of semaphore succeed if initially available

Throws:
java.lang.InterruptedException

testTimedAcquireReleaseInSameThread

public void testTimedAcquireReleaseInSameThread()
                                         throws java.lang.InterruptedException
Timed Acquire and release of semaphore succeed if initially available

Throws:
java.lang.InterruptedException

testAcquireReleaseInDifferentThreads

public void testAcquireReleaseInDifferentThreads()
                                          throws java.lang.InterruptedException
A release in one thread enables an acquire in another thread

Throws:
java.lang.InterruptedException

testUninterruptibleAcquireReleaseInDifferentThreads

public void testUninterruptibleAcquireReleaseInDifferentThreads()
                                                         throws java.lang.InterruptedException
A release in one thread enables an uninterruptible acquire in another thread

Throws:
java.lang.InterruptedException

testTimedAcquireReleaseInDifferentThreads

public void testTimedAcquireReleaseInDifferentThreads()
                                               throws java.lang.InterruptedException
A release in one thread enables a timed acquire in another thread

Throws:
java.lang.InterruptedException

testAcquire_InterruptedException

public void testAcquire_InterruptedException()
                                      throws java.lang.InterruptedException
A waiting acquire blocks interruptibly

Throws:
java.lang.InterruptedException

testTryAcquire_InterruptedException

public void testTryAcquire_InterruptedException()
                                         throws java.lang.InterruptedException
A waiting timed acquire blocks interruptibly

Throws:
java.lang.InterruptedException

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

testGetQueuedThreads

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

Throws:
java.lang.InterruptedException

testDrainPermits

public void testDrainPermits()
drainPermits reports and removes given number of permits


testReducePermits

public void testReducePermits()
reducePermits reduces number of permits


testSerialization

public void testSerialization()
                       throws java.lang.Exception
a deserialized serialized semaphore has same number of permits

Throws:
java.lang.Exception

testConstructor_fair

public void testConstructor_fair()
Zero, negative, and positive initial values are allowed in constructor


testTryAcquireInSameThread_fair

public void testTryAcquireInSameThread_fair()
tryAcquire succeeds when sufficient permits, else fails


testTryAcquireNInSameThread_fair

public void testTryAcquireNInSameThread_fair()
tryAcquire(n) succeeds when sufficient permits, else fails


testAcquireReleaseInSameThread_fair

public void testAcquireReleaseInSameThread_fair()
                                         throws java.lang.InterruptedException
Acquire and release of semaphore succeed if initially available

Throws:
java.lang.InterruptedException

testAcquireReleaseNInSameThread_fair

public void testAcquireReleaseNInSameThread_fair()
                                          throws java.lang.InterruptedException
Acquire(n) and release(n) of semaphore succeed if initially available

Throws:
java.lang.InterruptedException

testAcquireUninterruptiblyReleaseNInSameThread_fair

public void testAcquireUninterruptiblyReleaseNInSameThread_fair()
Acquire(n) and release(n) of semaphore succeed if initially available


testTimedAcquireReleaseNInSameThread_fair

public void testTimedAcquireReleaseNInSameThread_fair()
                                               throws java.lang.InterruptedException
release(n) in one thread enables timed acquire(n) in another thread

Throws:
java.lang.InterruptedException

testTimedAcquireReleaseInSameThread_fair

public void testTimedAcquireReleaseInSameThread_fair()
                                              throws java.lang.InterruptedException
release in one thread enables timed acquire in another thread

Throws:
java.lang.InterruptedException

testAcquireReleaseInDifferentThreads_fair

public void testAcquireReleaseInDifferentThreads_fair()
                                               throws java.lang.InterruptedException
A release in one thread enables an acquire in another thread

Throws:
java.lang.InterruptedException

testAcquireReleaseNInDifferentThreads_fair

public void testAcquireReleaseNInDifferentThreads_fair()
                                                throws java.lang.InterruptedException
release(n) in one thread enables acquire(n) in another thread

Throws:
java.lang.InterruptedException

testAcquireReleaseNInDifferentThreads_fair2

public void testAcquireReleaseNInDifferentThreads_fair2()
                                                 throws java.lang.InterruptedException
release(n) in one thread enables acquire(n) in another thread

Throws:
java.lang.InterruptedException

testTimedAcquireReleaseInDifferentThreads_fair

public void testTimedAcquireReleaseInDifferentThreads_fair()
                                                    throws java.lang.InterruptedException
release in one thread enables timed acquire in another thread

Throws:
java.lang.InterruptedException

testTimedAcquireReleaseNInDifferentThreads_fair

public void testTimedAcquireReleaseNInDifferentThreads_fair()
                                                     throws java.lang.InterruptedException
release(n) in one thread enables timed acquire(n) in another thread

Throws:
java.lang.InterruptedException

testAcquire_InterruptedException_fair

public void testAcquire_InterruptedException_fair()
                                           throws java.lang.InterruptedException
A waiting acquire blocks interruptibly

Throws:
java.lang.InterruptedException

testAcquireN_InterruptedException_fair

public void testAcquireN_InterruptedException_fair()
                                            throws java.lang.InterruptedException
A waiting acquire(n) blocks interruptibly

Throws:
java.lang.InterruptedException

testTryAcquire_InterruptedException_fair

public void testTryAcquire_InterruptedException_fair()
                                              throws java.lang.InterruptedException
A waiting tryAcquire blocks interruptibly

Throws:
java.lang.InterruptedException

testTryAcquireN_InterruptedException_fair

public void testTryAcquireN_InterruptedException_fair()
                                               throws java.lang.InterruptedException
A waiting tryAcquire(n) blocks interruptibly

Throws:
java.lang.InterruptedException

testGetQueueLength_fair

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

Throws:
java.lang.InterruptedException

testSerialization_fair

public void testSerialization_fair()
                            throws java.lang.Exception
a deserialized serialized semaphore has same number of permits

Throws:
java.lang.Exception

testToString

public void testToString()
toString indicates current number of permits