Class PhaserTest

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

public class PhaserTest
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
PhaserTest()
           
 
Method Summary
protected  void assertState(Phaser phaser, int phase, int parties, int unarrived)
          Checks state of unterminated phaser.
protected  void assertTerminated(Phaser phaser, int maxPhase)
           
protected  void assertTerminated(Phaser phaser, int maxPhase, int parties)
          Checks state of terminated phaser.
static void main(java.lang.String[] args)
           
static junit.framework.Test suite()
           
 void testArrive1()
          arrive() on a registered phaser increments phase.
 void testArrive2()
          arriveAndDeregister does not wait for others to arrive at barrier
 void testArrive3()
          arrive() returns a negative number if the Phaser is terminated
 void testArriveAndAwaitAdvance1()
          arriveAndAwaitAdvance throws IllegalStateException with no unarrived parties
 void testArriveAndAwaitAdvance3()
          arriveAndAwaitAdvance waits for all threads to arrive, the number of arrived parties is the same number that is accounted for when the main thread awaitsAdvance
 void testArriveAndAwaitAdvanceAfterInterrupt()
          arriveAndAwaitAdvance continues waiting if interrupted before waiting
 void testArriveAndAwaitAdvanceBeforeInterrupt()
          arriveAndAwaitAdvance continues waiting if interrupted while waiting
 void testArriveAndDeregister()
          arriveAndDeregister does not wait for others to arrive at barrier
 void testArriveAndDeregister1()
          arriveAndDeregister() throws IllegalStateException if number of registered or unarrived parties would become negative
 void testArriveAndDeregister2()
          arriveAndDeregister reduces the number of arrived parties
 void testArriveAndDeregister3()
          arriveAndDeregister arrives at the barrier on a phaser with a parent and when a deregistration occurs and causes the phaser to have zero parties its parent will be deregistered as well
 void testArriveAndDeregister4()
          arriveAndDeregister deregisters one party from its parent when the number of parties of child is zero after deregistration
 void testArriveAndDeregister5()
          arriveAndDeregister deregisters one party from its parent when the number of parties of root is nonzero after deregistration.
 void testArriveAndDeregister6()
          arriveAndDeregister returns the phase in which it leaves the phaser in after deregistration
 void testAwaitAdvance1()
          awaitAdvance succeeds upon advance
 void testAwaitAdvance2()
          awaitAdvance with a negative parameter will return without affecting the phaser
 void testAwaitAdvance4()
          awaitAdvance atomically waits for all parties within the same phase to complete before continuing
 void testAwaitAdvance5()
          awaitAdvance returns the current phase
 void testAwaitAdvance6()
          awaitAdvance returns when the phaser is externally terminated
 void testAwaitAdvanceAfterInterrupt()
          awaitAdvance continues waiting if interrupted before waiting
 void testAwaitAdvanceBeforeInterrupt()
          awaitAdvance continues waiting if interrupted while waiting
 void testAwaitAdvanceTieredPhaser()
          awaitAdvance returns the current phase in child phasers
 void testBulkRegister1()
          Invoking bulkRegister with a negative parameter throws an IllegalArgumentException
 void testBulkRegister2()
          bulkRegister should correctly record the number of unarrived parties with the number of parties being registered
 void testBulkRegister3()
          Registering with a number of parties greater than or equal to 1<<16 throws IllegalStateException.
 void testConstructor3()
          The parent provided to the constructor should be returned from a later call to getParent
 void testConstructor5()
          The parent being input into the parameter should equal the original parent when being returned
 void testConstructorDefaultValues()
          Empty constructor builds a new Phaser with no parent, no registered parties and initial phase number of 0
 void testConstructorNegativeParties()
          Constructing with a negative number of parties throws IllegalArgumentException
 void testConstructorNegativeParties2()
          Constructing with a negative number of parties throws IllegalArgumentException
 void testConstructorPartiesExceedsLimit()
          Constructing with a number of parties > 65535 throws IllegalArgumentException
 void testPhaseIncrement1()
          the phase number increments correctly when tripping the barrier
 void testRegister1()
          register() will increment the number of unarrived parties by one and not affect its arrived parties
 void testRegister2()
          Registering more than 65536 parties causes IllegalStateException
 void testRegister3()
          register() correctly returns the current barrier phase number when invoked
 void testRegister4()
          register causes the next arrive to not increment the phase rather retain the phase number
 
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

PhaserTest

public PhaserTest()
Method Detail

main

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

suite

public static junit.framework.Test suite()

assertState

protected void assertState(Phaser phaser,
                           int phase,
                           int parties,
                           int unarrived)
Checks state of unterminated phaser.


assertTerminated

protected void assertTerminated(Phaser phaser,
                                int maxPhase,
                                int parties)
Checks state of terminated phaser.


assertTerminated

protected void assertTerminated(Phaser phaser,
                                int maxPhase)

testConstructorDefaultValues

public void testConstructorDefaultValues()
Empty constructor builds a new Phaser with no parent, no registered parties and initial phase number of 0


testConstructorNegativeParties

public void testConstructorNegativeParties()
Constructing with a negative number of parties throws IllegalArgumentException


testConstructorNegativeParties2

public void testConstructorNegativeParties2()
Constructing with a negative number of parties throws IllegalArgumentException


testConstructorPartiesExceedsLimit

public void testConstructorPartiesExceedsLimit()
Constructing with a number of parties > 65535 throws IllegalArgumentException


testConstructor3

public void testConstructor3()
The parent provided to the constructor should be returned from a later call to getParent


testConstructor5

public void testConstructor5()
The parent being input into the parameter should equal the original parent when being returned


testRegister1

public void testRegister1()
register() will increment the number of unarrived parties by one and not affect its arrived parties


testRegister2

public void testRegister2()
Registering more than 65536 parties causes IllegalStateException


testRegister3

public void testRegister3()
register() correctly returns the current barrier phase number when invoked


testRegister4

public void testRegister4()
register causes the next arrive to not increment the phase rather retain the phase number


testBulkRegister1

public void testBulkRegister1()
Invoking bulkRegister with a negative parameter throws an IllegalArgumentException


testBulkRegister2

public void testBulkRegister2()
bulkRegister should correctly record the number of unarrived parties with the number of parties being registered


testBulkRegister3

public void testBulkRegister3()
Registering with a number of parties greater than or equal to 1<<16 throws IllegalStateException.


testPhaseIncrement1

public void testPhaseIncrement1()
the phase number increments correctly when tripping the barrier


testArrive1

public void testArrive1()
arrive() on a registered phaser increments phase.


testArriveAndDeregister

public void testArriveAndDeregister()
                             throws java.lang.InterruptedException
arriveAndDeregister does not wait for others to arrive at barrier

Throws:
java.lang.InterruptedException

testArrive2

public void testArrive2()
                 throws java.lang.InterruptedException
arriveAndDeregister does not wait for others to arrive at barrier

Throws:
java.lang.InterruptedException

testArrive3

public void testArrive3()
arrive() returns a negative number if the Phaser is terminated


testArriveAndDeregister1

public void testArriveAndDeregister1()
arriveAndDeregister() throws IllegalStateException if number of registered or unarrived parties would become negative


testArriveAndDeregister2

public void testArriveAndDeregister2()
arriveAndDeregister reduces the number of arrived parties


testArriveAndDeregister3

public void testArriveAndDeregister3()
arriveAndDeregister arrives at the barrier on a phaser with a parent and when a deregistration occurs and causes the phaser to have zero parties its parent will be deregistered as well


testArriveAndDeregister4

public void testArriveAndDeregister4()
arriveAndDeregister deregisters one party from its parent when the number of parties of child is zero after deregistration


testArriveAndDeregister5

public void testArriveAndDeregister5()
arriveAndDeregister deregisters one party from its parent when the number of parties of root is nonzero after deregistration.


testArriveAndDeregister6

public void testArriveAndDeregister6()
                              throws java.lang.InterruptedException
arriveAndDeregister returns the phase in which it leaves the phaser in after deregistration

Throws:
java.lang.InterruptedException

testAwaitAdvance1

public void testAwaitAdvance1()
awaitAdvance succeeds upon advance


testAwaitAdvance2

public void testAwaitAdvance2()
awaitAdvance with a negative parameter will return without affecting the phaser


testAwaitAdvanceAfterInterrupt

public void testAwaitAdvanceAfterInterrupt()
                                    throws java.lang.InterruptedException
awaitAdvance continues waiting if interrupted before waiting

Throws:
java.lang.InterruptedException

testAwaitAdvanceBeforeInterrupt

public void testAwaitAdvanceBeforeInterrupt()
                                     throws java.lang.InterruptedException
awaitAdvance continues waiting if interrupted while waiting

Throws:
java.lang.InterruptedException

testArriveAndAwaitAdvanceAfterInterrupt

public void testArriveAndAwaitAdvanceAfterInterrupt()
                                             throws java.lang.InterruptedException
arriveAndAwaitAdvance continues waiting if interrupted before waiting

Throws:
java.lang.InterruptedException

testArriveAndAwaitAdvanceBeforeInterrupt

public void testArriveAndAwaitAdvanceBeforeInterrupt()
                                              throws java.lang.InterruptedException
arriveAndAwaitAdvance continues waiting if interrupted while waiting

Throws:
java.lang.InterruptedException

testAwaitAdvance4

public void testAwaitAdvance4()
                       throws java.lang.InterruptedException
awaitAdvance atomically waits for all parties within the same phase to complete before continuing

Throws:
java.lang.InterruptedException

testAwaitAdvance5

public void testAwaitAdvance5()
                       throws java.lang.InterruptedException
awaitAdvance returns the current phase

Throws:
java.lang.InterruptedException

testAwaitAdvanceTieredPhaser

public void testAwaitAdvanceTieredPhaser()
                                  throws java.lang.Exception
awaitAdvance returns the current phase in child phasers

Throws:
java.lang.Exception

testAwaitAdvance6

public void testAwaitAdvance6()
                       throws java.lang.InterruptedException
awaitAdvance returns when the phaser is externally terminated

Throws:
java.lang.InterruptedException

testArriveAndAwaitAdvance1

public void testArriveAndAwaitAdvance1()
arriveAndAwaitAdvance throws IllegalStateException with no unarrived parties


testArriveAndAwaitAdvance3

public void testArriveAndAwaitAdvance3()
                                throws java.lang.InterruptedException
arriveAndAwaitAdvance waits for all threads to arrive, the number of arrived parties is the same number that is accounted for when the main thread awaitsAdvance

Throws:
java.lang.InterruptedException