Skip to content

Instantly share code, notes, and snippets.

@volyx
Forked from mustafau/ParallelParameterized.java
Created November 10, 2019 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save volyx/ae78f6f5e47e7fb526ae2f5c1c93dd56 to your computer and use it in GitHub Desktop.
Save volyx/ae78f6f5e47e7fb526ae2f5c1c93dd56 to your computer and use it in GitHub Desktop.
Parallelize JUnit parameterized tests.
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.junit.runners.Parameterized;
import org.junit.runners.model.RunnerScheduler;
public class ParallelParameterized extends Parameterized {
public ParallelParameterized(Class<?> arg0) throws Throwable {
super(arg0);
setScheduler(new RunnerScheduler() {
private final ExecutorService service = Executors.newFixedThreadPool(8);
public void schedule(Runnable childStatement) {
service.submit(childStatement);
}
public void finished() {
try {
service.shutdown();
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
e.printStackTrace(System.err);
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment