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
    Author:
    Tibor Digana (tibor17)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  Scheduler.ShutdownHandler
      There is a way to shutdown the hierarchy of schedulers.
    • Constructor Summary

      Constructors 
      Constructor Description
      Scheduler​(org.apache.maven.plugin.surefire.log.api.ConsoleLogger 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​(org.apache.maven.plugin.surefire.log.api.ConsoleLogger logger, org.junit.runner.Description description, Scheduler masterScheduler, SchedulingStrategy strategy, int concurrency)  
      Scheduler​(org.apache.maven.plugin.surefire.log.api.ConsoleLogger logger, org.junit.runner.Description description, Scheduler masterScheduler, SchedulingStrategy strategy, Balancer balancer)
      Can be used by e.g.
      Scheduler​(org.apache.maven.plugin.surefire.log.api.ConsoleLogger logger, org.junit.runner.Description description, SchedulingStrategy strategy)
      Use e.g.
      Scheduler​(org.apache.maven.plugin.surefire.log.api.ConsoleLogger 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.
      Scheduler​(org.apache.maven.plugin.surefire.log.api.ConsoleLogger 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.
    • Constructor Detail

      • Scheduler

        public Scheduler​(org.apache.maven.plugin.surefire.log.api.ConsoleLogger logger,
                         org.junit.runner.Description description,
                         SchedulingStrategy strategy)
        Use e.g. parallel classes have own non-shared thread pool, and methods another pool.
        You can use it with one infinite thread pool shared in strategies across all suites, class runners, etc.
        Parameters:
        logger - console logger
        description - JUnit description of class
        strategy - scheduling strategy
      • Scheduler

        public Scheduler​(org.apache.maven.plugin.surefire.log.api.ConsoleLogger 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. The schedulers share one pool.
        Unlike in Scheduler(ConsoleLogger, 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.
        Parameters:
        logger - current logger implementation
        description - description of current runner
        strategy - scheduling strategy which may share threads with other strategy
        balancer - determines maximum concurrent children scheduled a time via schedule(Runnable)
        Throws:
        java.lang.NullPointerException - if null strategy or balancer
      • Scheduler

        public Scheduler​(org.apache.maven.plugin.surefire.log.api.ConsoleLogger logger,
                         org.junit.runner.Description description,
                         Scheduler masterScheduler,
                         SchedulingStrategy strategy,
                         Balancer balancer)
        Can be used by e.g. a runner having parallel classes in use case with parallel suites, classes and methods sharing the same thread pool.
        Parameters:
        logger - current logger implementation
        description - description of current runner
        masterScheduler - scheduler sharing own threads with this slave
        strategy - scheduling strategy for this scheduler
        balancer - determines maximum concurrent children scheduled a time via schedule(Runnable)
        Throws:
        java.lang.NullPointerException - if null masterScheduler, strategy or balancer
      • Scheduler

        public Scheduler​(org.apache.maven.plugin.surefire.log.api.ConsoleLogger logger,
                         org.junit.runner.Description description,
                         Scheduler masterScheduler,
                         SchedulingStrategy strategy)
        Should be used with individual pools on suites, classes and methods, see ParallelComputerBuilder.useSeparatePools().
        Cached thread pool is infinite and can be always shared.
        Parameters:
        logger - console logger
        description - JUnit description of class
        masterScheduler - parent scheduler
        strategy - scheduling strategy
    • Method Detail

      • 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
      • 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