Class Scheduler

java.lang.Object
org.apache.maven.surefire.junitcore.pc.Scheduler
All Implemented Interfaces:
org.junit.runners.model.RunnerScheduler

public class Scheduler extends Object implements org.junit.runners.model.RunnerScheduler
Schedules tests, controls thread resources, awaiting tests and other schedulers finished, and a master scheduler can shutdown slaves.
The scheduler objects should be first created (and wired) and set in runners ParentRunner.setScheduler(org.junit.runners.model.RunnerScheduler).
A new instance of scheduling strategy should be passed to the constructor of this scheduler.
Since:
2.16
  • Field Details

    • balancer

      private final Balancer balancer
    • strategy

      private final SchedulingStrategy strategy
    • slaves

      private final Set<Scheduler.Controller> slaves
    • description

      private final org.junit.runner.Description description
    • logger

      private final ConsoleLogger logger
    • shutdown

      private volatile boolean shutdown
    • started

      private volatile boolean started
    • finished

      private volatile boolean finished
    • masterController

      private volatile Scheduler.Controller masterController
  • Constructor Details

  • Method Details

    • setController

      private void setController(Scheduler.Controller masterController)
    • register

      private boolean register(Scheduler slave)
      Parameters:
      slave - a slave scheduler to register
      Returns:
      true if successfully registered the slave.
    • canSchedule

      private boolean canSchedule()
      Returns:
      true if new tasks can be scheduled.
    • logQuietly

      protected void logQuietly(Throwable t)
    • logQuietly

      protected void logQuietly(String msg)
    • describeStopped

      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.
      This scheduler and other registered schedulers will stop, see register(Scheduler). If shutdownNow is set, waiting methods will be interrupted via Thread.interrupt().
      Parameters:
      stopNow - if true interrupts waiting test methods
      Returns:
      collection of descriptions started before shutting down
    • stop

      private void stop(Collection<org.junit.runner.Description> executedTests, Collection<org.junit.runner.Description> incompleteTests, boolean tryCancelFutures, boolean stopNow)
      Stop/Shutdown/Interrupt scheduler and its children (if any).
      Parameters:
      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().
    • shutdownThreadPoolsAwaitingKilled

      protected boolean shutdownThreadPoolsAwaitingKilled()
    • beforeExecute

      protected void beforeExecute()
    • afterExecute

      protected void afterExecute()
    • schedule

      public void schedule(Runnable childStatement)
      Specified by:
      schedule in interface org.junit.runners.model.RunnerScheduler
    • finished

      public void finished()
      Specified by:
      finished in interface org.junit.runners.model.RunnerScheduler
    • wrapTask

      private Runnable wrapTask(Runnable task)
    • newShutdownHandler

      protected Scheduler.ShutdownHandler newShutdownHandler()