public class Scheduler
extends java.lang.Object
implements org.junit.runners.model.RunnerScheduler
ParentRunner.setScheduler(org.junit.runners.model.RunnerScheduler)
.
Modifier and Type | Class and Description |
---|---|
private class |
Scheduler.Controller
If this is a master scheduler, the slaves can stop scheduling by the master through the controller.
|
class |
Scheduler.ShutdownHandler
There is a way to shutdown the hierarchy of schedulers.
|
Modifier and Type | Field and Description |
---|---|
private Balancer |
balancer |
private org.junit.runner.Description |
description |
private boolean |
finished |
private ConsoleStream |
logger |
private Scheduler.Controller |
masterController |
private boolean |
shutdown |
private java.util.Set<Scheduler.Controller> |
slaves |
private boolean |
started |
private SchedulingStrategy |
strategy |
Constructor and Description |
---|
Scheduler(ConsoleStream logger,
org.junit.runner.Description description,
Scheduler masterScheduler,
SchedulingStrategy strategy)
Should be used with individual pools on suites, classes and methods, see
ParallelComputerBuilder.useSeparatePools() . |
Scheduler(ConsoleStream logger,
org.junit.runner.Description description,
Scheduler masterScheduler,
SchedulingStrategy strategy,
Balancer balancer)
Can be used by e.g.
|
Scheduler(ConsoleStream logger,
org.junit.runner.Description description,
Scheduler masterScheduler,
SchedulingStrategy strategy,
int concurrency) |
Scheduler(ConsoleStream logger,
org.junit.runner.Description description,
SchedulingStrategy strategy)
Use e.g.
|
Scheduler(ConsoleStream logger,
org.junit.runner.Description description,
SchedulingStrategy strategy,
Balancer balancer)
New instances should be used by schedulers with limited concurrency by balancer
against other groups of schedulers.
|
Scheduler(ConsoleStream logger,
org.junit.runner.Description description,
SchedulingStrategy strategy,
int concurrency)
Should be used if schedulers in parallel children and parent use one instance of bounded thread pool.
|
Modifier and Type | Method and Description |
---|---|
protected void |
afterExecute() |
protected void |
beforeExecute() |
private boolean |
canSchedule() |
protected ShutdownResult |
describeStopped(boolean stopNow)
Attempts to stop all actively executing tasks and immediately returns a collection
of descriptions of those tasks which have started prior to this call.
|
void |
finished() |
protected void |
logQuietly(java.lang.String msg) |
protected void |
logQuietly(java.lang.Throwable t) |
protected Scheduler.ShutdownHandler |
newShutdownHandler() |
private boolean |
register(Scheduler slave) |
void |
schedule(java.lang.Runnable childStatement) |
private void |
setController(Scheduler.Controller masterController) |
protected boolean |
shutdownThreadPoolsAwaitingKilled() |
private void |
stop(java.util.Collection<org.junit.runner.Description> executedTests,
java.util.Collection<org.junit.runner.Description> incompleteTests,
boolean tryCancelFutures,
boolean stopNow)
Stop/Shutdown/Interrupt scheduler and its children (if any).
|
private java.lang.Runnable |
wrapTask(java.lang.Runnable task) |
private final Balancer balancer
private final SchedulingStrategy strategy
private final java.util.Set<Scheduler.Controller> slaves
private final org.junit.runner.Description description
private final ConsoleStream logger
private volatile boolean shutdown
private volatile boolean started
private volatile boolean finished
private volatile Scheduler.Controller masterController
public Scheduler(ConsoleStream logger, org.junit.runner.Description description, SchedulingStrategy strategy)
logger
- console loggerdescription
- JUnit description of classstrategy
- scheduling strategypublic Scheduler(ConsoleStream logger, org.junit.runner.Description description, SchedulingStrategy strategy, int concurrency)
Scheduler(ConsoleStream, org.junit.runner.Description, Scheduler, SchedulingStrategy)
or Scheduler(ConsoleStream, org.junit.runner.Description, Scheduler, SchedulingStrategy, int)
.logger
- current logger implementationdescription
- description of current runnerstrategy
- scheduling strategy with a shared thread poolconcurrency
- determines maximum concurrent children scheduled a time via schedule(Runnable)
java.lang.NullPointerException
- if null strategypublic Scheduler(ConsoleStream logger, org.junit.runner.Description description, SchedulingStrategy strategy, Balancer balancer)
Scheduler(ConsoleStream, org.junit.runner.Description, SchedulingStrategy, int)
which was
limiting the concurrency of children of a runner where this scheduler was set, this
balancer is limiting the concurrency of all children in runners having schedulers created by this
constructor.logger
- current logger implementationdescription
- description of current runnerstrategy
- scheduling strategy which may share threads with other strategybalancer
- determines maximum concurrent children scheduled a time via schedule(Runnable)
java.lang.NullPointerException
- if null strategy or balancerpublic Scheduler(ConsoleStream logger, org.junit.runner.Description description, Scheduler masterScheduler, SchedulingStrategy strategy, Balancer balancer)
logger
- current logger implementationdescription
- description of current runnermasterScheduler
- scheduler sharing own threads with this slavestrategy
- scheduling strategy for this schedulerbalancer
- determines maximum concurrent children scheduled a time via schedule(Runnable)
java.lang.NullPointerException
- if null masterScheduler, strategy or balancerpublic Scheduler(ConsoleStream logger, org.junit.runner.Description description, Scheduler masterScheduler, SchedulingStrategy strategy, int concurrency)
logger
- console loggerdescription
- JUnit description of classmasterScheduler
- a reference to
Scheduler(ConsoleStream, org.junit.runner.Description, SchedulingStrategy, int)
or Scheduler(ConsoleStream, org.junit.runner.Description, SchedulingStrategy)
strategy
- scheduling strategyconcurrency
- determines maximum concurrent children scheduled a time via schedule(Runnable)
Scheduler(ConsoleStream, org.junit.runner.Description, SchedulingStrategy)
,
Scheduler(ConsoleStream, org.junit.runner.Description, SchedulingStrategy, int)
public Scheduler(ConsoleStream logger, org.junit.runner.Description description, Scheduler masterScheduler, SchedulingStrategy strategy)
ParallelComputerBuilder.useSeparatePools()
.
logger
- console loggerdescription
- JUnit description of classmasterScheduler
- parent schedulerstrategy
- scheduling strategyprivate void setController(Scheduler.Controller masterController)
private boolean register(Scheduler slave)
slave
- a slave scheduler to registertrue
if successfully registered the slave.private boolean canSchedule()
true
if new tasks can be scheduled.protected void logQuietly(java.lang.Throwable t)
protected void logQuietly(java.lang.String msg)
protected ShutdownResult describeStopped(boolean stopNow)
register(Scheduler)
.
If shutdownNow is set, waiting methods will be interrupted via Thread.interrupt()
.stopNow
- if true
interrupts waiting test methodsprivate void stop(java.util.Collection<org.junit.runner.Description> executedTests, java.util.Collection<org.junit.runner.Description> incompleteTests, boolean tryCancelFutures, boolean stopNow)
executedTests
- Started tests which have finished normally or abruptly till called this method.incompleteTests
- Started tests which have finished incomplete due to shutdown.tryCancelFutures
- Useful to set to false
if a timeout is specified in plugin config.
When the runner of
Computer.getSuite(org.junit.runners.model.RunnerBuilder, Class[])
is finished in
ParentRunner.run(org.junit.runner.notification.RunNotifier)
all the thread-pools created by ParallelComputerBuilder.PC
are already dead.
See the unit test ParallelComputerBuilder#timeoutAndForcedShutdown()
.stopNow
- Interrupting tests by ExecutorService.shutdownNow()
or
Future#cancel(true)
or
Thread.interrupt()
.protected boolean shutdownThreadPoolsAwaitingKilled()
protected void beforeExecute()
protected void afterExecute()
public void schedule(java.lang.Runnable childStatement)
schedule
in interface org.junit.runners.model.RunnerScheduler
public void finished()
finished
in interface org.junit.runners.model.RunnerScheduler
private java.lang.Runnable wrapTask(java.lang.Runnable task)
protected Scheduler.ShutdownHandler newShutdownHandler()