Class ScheduledExecutorTest

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

public class ScheduledExecutorTest
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
ScheduledExecutorTest()
           
 
Method Summary
static void main(java.lang.String[] args)
           
static junit.framework.Test suite()
           
 void testExecute()
          execute successfully executes a runnable
 void testExecuteNull()
          execute(null) throws NPE
 void testFixedDelaySequence()
          scheduleWithFixedDelay executes series of tasks with given period
 void testFixedRateSequence()
          scheduleAtFixedRate executes series of tasks at given rate
 void testGetActiveCount()
          getActiveCount increases but doesn't overestimate, when a thread becomes active
 void testGetCompletedTaskCount()
          getCompletedTaskCount increases, but doesn't overestimate, when tasks complete
 void testGetCorePoolSize()
          getCorePoolSize returns size given in constructor if not otherwise set
 void testGetLargestPoolSize()
          getLargestPoolSize increases, but doesn't overestimate, when multiple threads active
 void testGetPoolSize()
          getPoolSize increases, but doesn't overestimate, when threads become active
 void testGetQueue()
          getQueue returns the work queue, which contains queued tasks
 void testGetTaskCount()
          getTaskCount increases, but doesn't overestimate, when tasks submitted
 void testGetThreadFactory()
          getThreadFactory returns factory in constructor if not set
 void testInvokeAll1()
          invokeAll(null) throws NPE
 void testInvokeAll2()
          invokeAll(empty collection) returns empty collection
 void testInvokeAll3()
          invokeAll(c) throws NPE if c has null elements
 void testInvokeAll4()
          get of invokeAll(c) throws exception on failed task
 void testInvokeAll5()
          invokeAll(c) returns results of all completed tasks
 void testInvokeAny1()
          invokeAny(null) throws NPE
 void testInvokeAny2()
          invokeAny(empty collection) throws IAE
 void testInvokeAny3()
          invokeAny(c) throws NPE if c has null elements
 void testInvokeAny4()
          invokeAny(c) throws ExecutionException if no task completes
 void testInvokeAny5()
          invokeAny(c) returns result of some task
 void testIsShutdown()
          isShutdown is false before shutdown, true after
 void testIsTerminated()
          isTerminated is false before termination, true after
 void testIsTerminating()
          isTerminating is not true when running or when terminated
 void testPurge()
          purge eventually removes cancelled tasks from the queue
 void testRemove()
          remove(task) removes queued task, and fails to remove active task
 void testSchedule1_RejectedExecutionException()
          execute throws RejectedExecutionException if shutdown
 void testSchedule1()
          delayed schedule of callable successfully executes after delay
 void testSchedule2_RejectedExecutionException()
          schedule throws RejectedExecutionException if shutdown
 void testSchedule3_RejectedExecutionException()
          schedule callable throws RejectedExecutionException if shutdown
 void testSchedule3()
          delayed schedule of runnable successfully executes after delay
 void testSchedule4()
          scheduleAtFixedRate executes runnable after given initial delay
 void testSchedule5()
          scheduleWithFixedDelay executes runnable after given initial delay
 void testScheduleAtFixedRate1_RejectedExecutionException()
          scheduleAtFixedRate throws RejectedExecutionException if shutdown
 void testScheduleNull()
          schedule(null) throws NPE
 void testScheduleWithFixedDelay1_RejectedExecutionException()
          scheduleWithFixedDelay throws RejectedExecutionException if shutdown
 void testSetThreadFactory()
          setThreadFactory sets the thread factory returned by getThreadFactory
 void testSetThreadFactoryNull()
          setThreadFactory(null) throws NPE
 void testShutdown1()
          In default setting, shutdown cancels periodic but not delayed tasks at shutdown
 void testShutdown2()
          If setExecuteExistingDelayedTasksAfterShutdownPolicy is false, delayed tasks are cancelled at shutdown
 void testShutdown3()
          If setContinueExistingPeriodicTasksAfterShutdownPolicy is set false, periodic tasks are cancelled at shutdown
 void testShutdown4()
          if setContinueExistingPeriodicTasksAfterShutdownPolicy is true, periodic tasks are not cancelled at shutdown
 void testShutdownNow()
          shutdownNow returns a list containing tasks that were not run
 void testSubmitCallable()
          completed submit of callable returns result
 void testSubmitRunnable()
          completed submit of runnable returns successfully
 void testSubmitRunnable2()
          completed submit of (runnable, result) returns result
 void testTimedInvokeAll1()
          timed invokeAll(null) throws NPE
 void testTimedInvokeAll2()
          timed invokeAll(empty collection) returns empty collection
 void testTimedInvokeAll3()
          timed invokeAll(c) throws NPE if c has null elements
 void testTimedInvokeAll4()
          get of element of invokeAll(c) throws exception on failed task
 void testTimedInvokeAll5()
          timed invokeAll(c) returns results of all completed tasks
 void testTimedInvokeAll6()
          timed invokeAll(c) cancels tasks not completed by timeout
 void testTimedInvokeAllNullTimeUnit()
          timed invokeAll(,,null) throws NPE
 void testTimedInvokeAny1()
          timed invokeAny(null) throws NPE
 void testTimedInvokeAny2()
          timed invokeAny(empty collection) throws IAE
 void testTimedInvokeAny3()
          timed invokeAny(c) throws NPE if c has null elements
 void testTimedInvokeAny4()
          timed invokeAny(c) throws ExecutionException if no task completes
 void testTimedInvokeAny5()
          timed invokeAny(c) returns result of some task
 void testTimedInvokeAnyNullTimeUnit()
          timed invokeAny(,,null) throws NPE
 
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

ScheduledExecutorTest

public ScheduledExecutorTest()
Method Detail

main

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

suite

public static junit.framework.Test suite()

testExecute

public void testExecute()
                 throws java.lang.InterruptedException
execute successfully executes a runnable

Throws:
java.lang.InterruptedException

testSchedule1

public void testSchedule1()
                   throws java.lang.Exception
delayed schedule of callable successfully executes after delay

Throws:
java.lang.Exception

testSchedule3

public void testSchedule3()
                   throws java.lang.Exception
delayed schedule of runnable successfully executes after delay

Throws:
java.lang.Exception

testSchedule4

public void testSchedule4()
                   throws java.lang.Exception
scheduleAtFixedRate executes runnable after given initial delay

Throws:
java.lang.Exception

testSchedule5

public void testSchedule5()
                   throws java.lang.InterruptedException
scheduleWithFixedDelay executes runnable after given initial delay

Throws:
java.lang.InterruptedException

testFixedRateSequence

public void testFixedRateSequence()
                           throws java.lang.InterruptedException
scheduleAtFixedRate executes series of tasks at given rate

Throws:
java.lang.InterruptedException

testFixedDelaySequence

public void testFixedDelaySequence()
                            throws java.lang.InterruptedException
scheduleWithFixedDelay executes series of tasks with given period

Throws:
java.lang.InterruptedException

testExecuteNull

public void testExecuteNull()
                     throws java.lang.InterruptedException
execute(null) throws NPE

Throws:
java.lang.InterruptedException

testScheduleNull

public void testScheduleNull()
                      throws java.lang.InterruptedException
schedule(null) throws NPE

Throws:
java.lang.InterruptedException

testSchedule1_RejectedExecutionException

public void testSchedule1_RejectedExecutionException()
                                              throws java.lang.InterruptedException
execute throws RejectedExecutionException if shutdown

Throws:
java.lang.InterruptedException

testSchedule2_RejectedExecutionException

public void testSchedule2_RejectedExecutionException()
                                              throws java.lang.InterruptedException
schedule throws RejectedExecutionException if shutdown

Throws:
java.lang.InterruptedException

testSchedule3_RejectedExecutionException

public void testSchedule3_RejectedExecutionException()
                                              throws java.lang.InterruptedException
schedule callable throws RejectedExecutionException if shutdown

Throws:
java.lang.InterruptedException

testScheduleAtFixedRate1_RejectedExecutionException

public void testScheduleAtFixedRate1_RejectedExecutionException()
                                                         throws java.lang.InterruptedException
scheduleAtFixedRate throws RejectedExecutionException if shutdown

Throws:
java.lang.InterruptedException

testScheduleWithFixedDelay1_RejectedExecutionException

public void testScheduleWithFixedDelay1_RejectedExecutionException()
                                                            throws java.lang.InterruptedException
scheduleWithFixedDelay throws RejectedExecutionException if shutdown

Throws:
java.lang.InterruptedException

testGetActiveCount

public void testGetActiveCount()
                        throws java.lang.InterruptedException
getActiveCount increases but doesn't overestimate, when a thread becomes active

Throws:
java.lang.InterruptedException

testGetCompletedTaskCount

public void testGetCompletedTaskCount()
                               throws java.lang.InterruptedException
getCompletedTaskCount increases, but doesn't overestimate, when tasks complete

Throws:
java.lang.InterruptedException

testGetCorePoolSize

public void testGetCorePoolSize()
                         throws java.lang.InterruptedException
getCorePoolSize returns size given in constructor if not otherwise set

Throws:
java.lang.InterruptedException

testGetLargestPoolSize

public void testGetLargestPoolSize()
                            throws java.lang.InterruptedException
getLargestPoolSize increases, but doesn't overestimate, when multiple threads active

Throws:
java.lang.InterruptedException

testGetPoolSize

public void testGetPoolSize()
                     throws java.lang.InterruptedException
getPoolSize increases, but doesn't overestimate, when threads become active

Throws:
java.lang.InterruptedException

testGetTaskCount

public void testGetTaskCount()
                      throws java.lang.InterruptedException
getTaskCount increases, but doesn't overestimate, when tasks submitted

Throws:
java.lang.InterruptedException

testGetThreadFactory

public void testGetThreadFactory()
                          throws java.lang.InterruptedException
getThreadFactory returns factory in constructor if not set

Throws:
java.lang.InterruptedException

testSetThreadFactory

public void testSetThreadFactory()
                          throws java.lang.InterruptedException
setThreadFactory sets the thread factory returned by getThreadFactory

Throws:
java.lang.InterruptedException

testSetThreadFactoryNull

public void testSetThreadFactoryNull()
                              throws java.lang.InterruptedException
setThreadFactory(null) throws NPE

Throws:
java.lang.InterruptedException

testIsShutdown

public void testIsShutdown()
isShutdown is false before shutdown, true after


testIsTerminated

public void testIsTerminated()
                      throws java.lang.InterruptedException
isTerminated is false before termination, true after

Throws:
java.lang.InterruptedException

testIsTerminating

public void testIsTerminating()
                       throws java.lang.InterruptedException
isTerminating is not true when running or when terminated

Throws:
java.lang.InterruptedException

testGetQueue

public void testGetQueue()
                  throws java.lang.InterruptedException
getQueue returns the work queue, which contains queued tasks

Throws:
java.lang.InterruptedException

testRemove

public void testRemove()
                throws java.lang.InterruptedException
remove(task) removes queued task, and fails to remove active task

Throws:
java.lang.InterruptedException

testPurge

public void testPurge()
               throws java.lang.InterruptedException
purge eventually removes cancelled tasks from the queue

Throws:
java.lang.InterruptedException

testShutdownNow

public void testShutdownNow()
shutdownNow returns a list containing tasks that were not run


testShutdown1

public void testShutdown1()
                   throws java.lang.InterruptedException
In default setting, shutdown cancels periodic but not delayed tasks at shutdown

Throws:
java.lang.InterruptedException

testShutdown2

public void testShutdown2()
                   throws java.lang.InterruptedException
If setExecuteExistingDelayedTasksAfterShutdownPolicy is false, delayed tasks are cancelled at shutdown

Throws:
java.lang.InterruptedException

testShutdown3

public void testShutdown3()
                   throws java.lang.InterruptedException
If setContinueExistingPeriodicTasksAfterShutdownPolicy is set false, periodic tasks are cancelled at shutdown

Throws:
java.lang.InterruptedException

testShutdown4

public void testShutdown4()
                   throws java.lang.InterruptedException
if setContinueExistingPeriodicTasksAfterShutdownPolicy is true, periodic tasks are not cancelled at shutdown

Throws:
java.lang.InterruptedException

testSubmitCallable

public void testSubmitCallable()
                        throws java.lang.Exception
completed submit of callable returns result

Throws:
java.lang.Exception

testSubmitRunnable

public void testSubmitRunnable()
                        throws java.lang.Exception
completed submit of runnable returns successfully

Throws:
java.lang.Exception

testSubmitRunnable2

public void testSubmitRunnable2()
                         throws java.lang.Exception
completed submit of (runnable, result) returns result

Throws:
java.lang.Exception

testInvokeAny1

public void testInvokeAny1()
                    throws java.lang.Exception
invokeAny(null) throws NPE

Throws:
java.lang.Exception

testInvokeAny2

public void testInvokeAny2()
                    throws java.lang.Exception
invokeAny(empty collection) throws IAE

Throws:
java.lang.Exception

testInvokeAny3

public void testInvokeAny3()
                    throws java.lang.Exception
invokeAny(c) throws NPE if c has null elements

Throws:
java.lang.Exception

testInvokeAny4

public void testInvokeAny4()
                    throws java.lang.Exception
invokeAny(c) throws ExecutionException if no task completes

Throws:
java.lang.Exception

testInvokeAny5

public void testInvokeAny5()
                    throws java.lang.Exception
invokeAny(c) returns result of some task

Throws:
java.lang.Exception

testInvokeAll1

public void testInvokeAll1()
                    throws java.lang.Exception
invokeAll(null) throws NPE

Throws:
java.lang.Exception

testInvokeAll2

public void testInvokeAll2()
                    throws java.lang.Exception
invokeAll(empty collection) returns empty collection

Throws:
java.lang.Exception

testInvokeAll3

public void testInvokeAll3()
                    throws java.lang.Exception
invokeAll(c) throws NPE if c has null elements

Throws:
java.lang.Exception

testInvokeAll4

public void testInvokeAll4()
                    throws java.lang.Exception
get of invokeAll(c) throws exception on failed task

Throws:
java.lang.Exception

testInvokeAll5

public void testInvokeAll5()
                    throws java.lang.Exception
invokeAll(c) returns results of all completed tasks

Throws:
java.lang.Exception

testTimedInvokeAny1

public void testTimedInvokeAny1()
                         throws java.lang.Exception
timed invokeAny(null) throws NPE

Throws:
java.lang.Exception

testTimedInvokeAnyNullTimeUnit

public void testTimedInvokeAnyNullTimeUnit()
                                    throws java.lang.Exception
timed invokeAny(,,null) throws NPE

Throws:
java.lang.Exception

testTimedInvokeAny2

public void testTimedInvokeAny2()
                         throws java.lang.Exception
timed invokeAny(empty collection) throws IAE

Throws:
java.lang.Exception

testTimedInvokeAny3

public void testTimedInvokeAny3()
                         throws java.lang.Exception
timed invokeAny(c) throws NPE if c has null elements

Throws:
java.lang.Exception

testTimedInvokeAny4

public void testTimedInvokeAny4()
                         throws java.lang.Exception
timed invokeAny(c) throws ExecutionException if no task completes

Throws:
java.lang.Exception

testTimedInvokeAny5

public void testTimedInvokeAny5()
                         throws java.lang.Exception
timed invokeAny(c) returns result of some task

Throws:
java.lang.Exception

testTimedInvokeAll1

public void testTimedInvokeAll1()
                         throws java.lang.Exception
timed invokeAll(null) throws NPE

Throws:
java.lang.Exception

testTimedInvokeAllNullTimeUnit

public void testTimedInvokeAllNullTimeUnit()
                                    throws java.lang.Exception
timed invokeAll(,,null) throws NPE

Throws:
java.lang.Exception

testTimedInvokeAll2

public void testTimedInvokeAll2()
                         throws java.lang.Exception
timed invokeAll(empty collection) returns empty collection

Throws:
java.lang.Exception

testTimedInvokeAll3

public void testTimedInvokeAll3()
                         throws java.lang.Exception
timed invokeAll(c) throws NPE if c has null elements

Throws:
java.lang.Exception

testTimedInvokeAll4

public void testTimedInvokeAll4()
                         throws java.lang.Exception
get of element of invokeAll(c) throws exception on failed task

Throws:
java.lang.Exception

testTimedInvokeAll5

public void testTimedInvokeAll5()
                         throws java.lang.Exception
timed invokeAll(c) returns results of all completed tasks

Throws:
java.lang.Exception

testTimedInvokeAll6

public void testTimedInvokeAll6()
                         throws java.lang.Exception
timed invokeAll(c) cancels tasks not completed by timeout

Throws:
java.lang.Exception