Change-Id: I015e92ccc9be963543032c14dd9d051bcba58e53tags/7.1.7
@@ -20,7 +20,6 @@ import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.concurrent.Callable; | |||
import java.util.concurrent.ExecutorService; | |||
import java.util.concurrent.Executors; | |||
import java.util.concurrent.Future; | |||
import org.junit.runners.model.RunnerScheduler; | |||
@@ -33,8 +32,18 @@ import org.junit.runners.model.RunnerScheduler; | |||
*/ | |||
public class ParallelScheduler implements RunnerScheduler { | |||
private final List<Future<Object>> fResults = new ArrayList<Future<Object>>(); | |||
private ExecutorService fService; | |||
private final ExecutorService fService = Executors.newCachedThreadPool(); | |||
/** | |||
* Creates a parallel scheduler which will use the given executor service | |||
* when submitting test jobs. | |||
* | |||
* @param service | |||
* The service to use for tests | |||
*/ | |||
public ParallelScheduler(ExecutorService service) { | |||
fService = service; | |||
} | |||
@Override | |||
public void schedule(final Runnable childStatement) { |
@@ -19,6 +19,8 @@ package com.vaadin.tests.tb3; | |||
import java.lang.reflect.Method; | |||
import java.util.LinkedList; | |||
import java.util.List; | |||
import java.util.concurrent.ExecutorService; | |||
import java.util.concurrent.Executors; | |||
import org.junit.Test; | |||
import org.junit.runners.BlockJUnit4ClassRunner; | |||
@@ -40,9 +42,21 @@ import com.vaadin.tests.tb3.AbstractTB3Test.BrowserUtil; | |||
*/ | |||
public class TB3Runner extends BlockJUnit4ClassRunner { | |||
/** | |||
* This is the total limit of actual JUnit test instances run in parallel | |||
*/ | |||
private static final int MAX_CONCURRENT_TESTS = 50; | |||
/** | |||
* This is static so it is shared by all tests running concurrently on the | |||
* same machine and thus can limit the number of threads in use. | |||
*/ | |||
private static final ExecutorService service = Executors | |||
.newFixedThreadPool(MAX_CONCURRENT_TESTS); | |||
public TB3Runner(Class<?> klass) throws InitializationError { | |||
super(klass); | |||
setScheduler(new ParallelScheduler()); | |||
setScheduler(new ParallelScheduler(service)); | |||
} | |||
@Override |
@@ -28,6 +28,8 @@ import java.util.Collections; | |||
import java.util.Comparator; | |||
import java.util.Enumeration; | |||
import java.util.List; | |||
import java.util.concurrent.ExecutorService; | |||
import java.util.concurrent.Executors; | |||
import java.util.jar.JarEntry; | |||
import org.junit.runners.Suite; | |||
@@ -41,11 +43,24 @@ import org.junit.runners.model.InitializationError; | |||
*/ | |||
public class TB3TestSuite extends Suite { | |||
/** | |||
* This only restricts the number of test suites running concurrently. The | |||
* number of tests to run concurrently are configured in {@link TB3Runner}. | |||
*/ | |||
private static final int MAX_CONCURRENT_TEST_SUITES = 20; | |||
/** | |||
* This is static so it is shared by all test suites running concurrently on | |||
* the same machine and thus can limit the number of threads in use. | |||
*/ | |||
private final ExecutorService service = Executors | |||
.newFixedThreadPool(MAX_CONCURRENT_TEST_SUITES); | |||
public TB3TestSuite(Class<?> klass, | |||
Class<? extends AbstractTB3Test> baseClass, String basePackage, | |||
String[] ignorePackages) throws InitializationError { | |||
super(klass, findTests(baseClass, basePackage, ignorePackages)); | |||
setScheduler(new ParallelScheduler()); | |||
setScheduler(new ParallelScheduler(service)); | |||
} | |||
/** |