Class Scheduler

  • All Implemented Interfaces:
    org.junit.runners.model.RunnerScheduler

    public class Scheduler
    extends java.lang.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 Detail

      • balancer

        private final Balancer balancer
      • description

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

        private volatile boolean shutdown
      • started

        private volatile boolean started
      • finished

        private volatile boolean finished
    • Method Detail

      • 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​(java.lang.Throwable t)
      • logQuietly

        protected void logQuietly​(java.lang.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​(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).
        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​(java.lang.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 java.lang.Runnable wrapTask​(java.lang.Runnable task)