|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.testing.threadtester.InterleavedRunner
public class InterleavedRunner
Utility class that tests two interleaved threads. The majority of methods in
this class are designed to be used with instrumented
classes, although there is one version of the interleave(MainRunnable, SecondaryRunnable, List) method that can be used
with non-instrumented classes.
| Method Summary | ||
|---|---|---|
static
|
interleave(M main,
SecondaryRunnable<T,M> secondary)
Invokes two runnable instances, interleaving the execution. |
|
static
|
interleave(M main,
SecondaryRunnable<T,M> secondary,
List<CodePosition> positions)
Invokes two runnable instances, interleaving the execution. |
|
static
|
interleaveAfter(M main,
SecondaryRunnable<T,M> secondary,
CodePosition position,
int posCount)
Invokes two runnable instances, interleaving the execution. |
|
static
|
interleaveAtBreakpoint(M main,
SecondaryRunnable<T,M> secondary,
ReusableBreakpoint breakpoint)
Version of interleave(MainRunnable, SecondaryRunnable, List)
that takes a single ReusableBreakpoint |
|
static RunResult |
interleaveAtBreakpoint(Runnable mainRunnable,
Runnable secondaryRunnable,
ReusableBreakpoint breakpoint)
Version of interleave(MainRunnable, SecondaryRunnable, List) that
uses ordinary Runnables, and takes a single ReusableBreakpoint. |
|
static
|
interleaveAtReusableBreakpoints(M main,
SecondaryRunnable<T,M> secondary,
List<ReusableBreakpoint> breakpoints)
Invokes two runnable instances, interleaving the execution using the supplied list of ReusableBreakpoints. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <M extends MainRunnable<T>,T> RunResult interleave(M main,
SecondaryRunnable<T,M> secondary)
MainRunnable.getMethod(). If N is the number of executable lines in
this method, then the main runnable will be executed N times, stopping at a
different line each time. When the main runnable is stopped, the secondary
runnable will be executed until it completes, and then the main runnable
will continue. This allows a test to verify that the main method behaves
correctly even if another method is called part way through its
execution. Note that the framework will correctly handle the case where the
second thread is blocked because of synchronization and/or locks in the
first method.
Due to the structure of the method being tested, not every executable line may be reached. (E.g. conditional or error-handling blocks may not be entered.) The InterleavedRunner will attempt to break execution at every line, but if a given line is not reached, the runner will continue until the end of the test method.
Note that the method being tested must be instrumented. See ClassInstrumentation.
main - the main runnablesecondary - the secondary runnable
IllegalArgumentException - if the main runnable does not specify a
valid instrumented class/method.
public static <M extends MainRunnable<T>,T> RunResult interleaveAfter(M main,
SecondaryRunnable<T,M> secondary,
CodePosition position,
int posCount)
interleave(M, com.google.testing.threadtester.SecondaryRunnable) , except that the main method will not stop
until the given code position is reached the given number of times. This
allows a test to simulate cases when a second thread is invoked after a
certain condition. (E.g. an event is received after the main method
registers a listener, but not before.)
Note that this method can only be invoked when the given runnables are
calling a method in an instrumented class. See ClassInstrumentation.
main - the main runnablesecondary - the secondary runnableposition - the secondary runnable will not start until the first
runnable has at least reached this position .posCount - the number of time the first runnable must reach the given
position
IllegalArgumentException - if the main runnable does not specify a
valid instrumented class/method, or if the code position does not specify a
position within the main method.
public static <M extends MainRunnable<T>,T> RunResult interleave(M main,
SecondaryRunnable<T,M> secondary,
List<CodePosition> positions)
It is the caller's responsibility to ensure that the main runnable will reach the given positions when executing.
Note that the method being tested must be instrumented. See ClassInstrumentation.
main - the main runnablesecondary - the secondary runnablepositions - a list of code positions where the main runnable will stop
IllegalArgumentException - if the main runnable does not specify a
valid instrumented class/method.
public static RunResult interleaveAtBreakpoint(Runnable mainRunnable,
Runnable secondaryRunnable,
ReusableBreakpoint breakpoint)
interleave(MainRunnable, SecondaryRunnable, List) that
uses ordinary Runnables, and takes a single ReusableBreakpoint. Because there is
only a single ReusableBreakpoint, the main and secondary Runnables will only be
executed once, and hence do not need to go through the full lifecycle
defined by the MainRunnable class.
public static <M extends MainRunnable<T>,T> RunResult interleaveAtBreakpoint(M main,
SecondaryRunnable<T,M> secondary,
ReusableBreakpoint breakpoint)
interleave(MainRunnable, SecondaryRunnable, List)
that takes a single ReusableBreakpoint
public static <M extends MainRunnable<T>,T> RunResult interleaveAtReusableBreakpoints(M main,
SecondaryRunnable<T,M> secondary,
List<ReusableBreakpoint> breakpoints)
ReusableBreakpoints. The main runnable will be executed
once for every ReusableBreakpoint in the list, stopping at each ReusableBreakpoint in turn.
When stopped, the secondary runnable will be executed until it completes,
and then the main runnable will continue. This allows a test to verify that
the main method behaves correctly even if another method is called part way
through its execution. Note that the framework will correctly handle the
case where the second thread is blocked because of synchronization and/or
locks in the first method.
Internally, this method will create new Threads, and will invoke
ReusableBreakpoint.setThread(java.lang.Thread) on the given ReusableBreakpoints, to ensure
that the main runnable stops correctly.
Note that the methodName and class defined by the main runnable will be ignored. This method can be invoked even when the runnables are not calling into an instrumented method, provided that the given breakpoints do not require instrumentation. In general, this method is designed to be used with non-instrumented classes.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||