com.saucelabs.junit.Parallelized Maven / Gradle / Ivy
package com.saucelabs.junit;
import org.junit.runners.Parameterized;
import org.junit.runners.model.RunnerScheduler;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.*;
/**
* Creates a dynamically sized thread pool when running parallel tests.
*
* Inspired by http://hwellmann.blogspot.com/2009/12/running-parameterized-junit-tests-in.html
*
* @author Ross Rowe
*/
public class Parallelized extends Parameterized {
private static class NonBlockingAsynchronousRunner implements RunnerScheduler {
private final List> futures = Collections.synchronizedList(new ArrayList>());
private final ExecutorService fService;
public NonBlockingAsynchronousRunner() {
String threads = System.getProperty("junit.parallel.threads", "16");
int numThreads = Integer.parseInt(threads);
fService = Executors.newFixedThreadPool(numThreads);
}
public void schedule(final Runnable childStatement) {
final Callable