All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pantsbuild.tools.junit.impl.ConcurrentCompositeRequestRunner Maven / Gradle / Ivy

Go to download

A command line tool for running junit tests that provides functionality above and beyond that provided by org.junit.runner.JUnitCore.

There is a newer version: 1.0.30
Show newest version
// Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package org.pantsbuild.tools.junit.impl;

import java.util.List;

import org.junit.runner.Request;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;

/**
 * A Runner for running composite requests in a concurrent fashion.
 */
public class ConcurrentCompositeRequestRunner extends CompositeRequestRunner {

  private final ConcurrentRunnerScheduler runnerScheduler;

  public ConcurrentCompositeRequestRunner(List requests, Concurrency defaultConcurrency,
      int numThreads)
      throws InitializationError {
    super(requests);
    this.runnerScheduler = new ConcurrentRunnerScheduler(defaultConcurrency, numThreads);
    setScheduler(runnerScheduler);
  }

  @Override
  protected Statement childrenInvoker(final RunNotifier notifier) {
    return new Statement() {
      @Override
      public void evaluate() {
        for (final Request child : getChildren()) {
          Runnable runnable = new Runnable() {
            @Override
            public void run() {
              runChild(child, notifier);
            }
          };
          if (child instanceof AnnotatedClassRequest) {
            runnerScheduler.schedule(runnable, ((AnnotatedClassRequest) child).getClazz());
          } else {
            runnerScheduler.schedule(runnable);
          }
        }
        runnerScheduler.finished();
      }
    };
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy