public class TestRunnable
extends java.lang.Object
implements java.lang.Runnable
This structure is used extensively within threadly's own unit tests. Please use those as examples using this class.
Constructor and Description |
---|
TestRunnable()
Constructs a new runnable for unit testing.
|
TestRunnable(int runTimeInMillis)
Constructs a new runnable for unit testing.
|
Modifier and Type | Method and Description |
---|---|
void |
blockTillFinished()
Blocks until run has completed at least once.
|
void |
blockTillFinished(int timeout)
Blocks until run has completed at least once.
|
void |
blockTillFinished(int timeout,
int expectedRunCount)
Blocks until run completed been called the provided quantity of times.
|
void |
blockTillStarted()
Blocks until run has been called at least once.
|
void |
blockTillStarted(int timeout)
Blocks until run has been called at least once.
|
long |
getCreationTime()
Returns the millis returned from
Clock.accurateForwardProgressingMillis() , that was
recorded when this runnable was constructed. |
long |
getDelayTillFirstRun()
This function blocks till the first run completes then will return the time until the first
run started it's call.
|
long |
getDelayTillRun(int runNumber)
This function blocks till the run provided, and then gets the time between creation and a
given run.
|
long |
getDelayTillRun(int runNumber,
int timeout)
This function blocks till the run provided, and
then gets the time between creation and a given run.
|
int |
getRunCount()
Getter for the number of times the run function has completed.
|
int |
getRunDelayInMillis()
Getter for the currently set amount of time the
TestRunnable will block after
handleRunStart() and before handleRunFinish() is called. |
void |
handleRunFinish()
Function to be overloaded by extending classes if more data or operations need to happen at
the run point.
|
void |
handleRunStart()
Function to be overloaded by extending classes if more data or operations need to happen at
the run point.
|
boolean |
isRunning()
Check to see if the run function has started but has not completed returned yet.
|
boolean |
ranConcurrently()
Check if this instance has ever been detected to run concurrently.
|
boolean |
ranOnce()
Getter to check if the runnable has run exactly once.
|
void |
run() |
void |
setRunDelayInMillis(int runDelayInMillis)
Changes the amount of time the runnable will sleep/block when called.
|
public TestRunnable()
public TestRunnable(int runTimeInMillis)
This constructor allows the parameter for the runnable to sleep after handleRunStart()
was called and before handleRunFinish()
is called.
runTimeInMillis
- time for runnable to sleep in millisecondspublic void setRunDelayInMillis(int runDelayInMillis)
runDelayInMillis
- new amount to wait when run is calledpublic int getRunDelayInMillis()
TestRunnable
will block after
handleRunStart()
and before handleRunFinish()
is called.public long getCreationTime()
Clock.accurateForwardProgressingMillis()
, that was
recorded when this runnable was constructed.TestRunnable
was constructedpublic boolean ranConcurrently()
handleRunStart()
,
handleRunFinish()
, or in the constructor increases the chances of detecting
concurrency.public boolean ranOnce()
true
if the runnable has been called oncepublic boolean isRunning()
public int getRunCount()
public long getDelayTillFirstRun()
public long getDelayTillRun(int runNumber)
runNumber
- the run count to get delay topublic long getDelayTillRun(int runNumber, int timeout)
runNumber
- the run count to get delay totimeout
- timeout to wait for given run count to finishpublic void blockTillFinished()
public void blockTillFinished(int timeout)
timeout
- time to wait for run to be called before throwing exceptionpublic void blockTillFinished(int timeout, int expectedRunCount)
timeout
- time to wait for run to be called before throwing exceptionexpectedRunCount
- run count to wait forpublic void blockTillStarted()
public void blockTillStarted(int timeout)
timeout
- time to wait for run to be called before throwing exceptionpublic final void run()
run
in interface java.lang.Runnable
public void handleRunStart() throws java.lang.InterruptedException
This is also the first call to be made in the runnable, but all necessary
TestRunnable
actions are in a finally block so it is safe to throw any exceptions
necessary here.
java.lang.InterruptedException
- only InterruptedExceptions will be swallowedpublic void handleRunFinish()
This is the last call to be made in the runnable. If you want a RuntimeException
to
get thrown to the caller, it must be thrown from here.