From 7f7dc316e3593bc4823f2cbc8e6f4814f233ce03 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 16 Sep 2013 08:50:16 +0300 Subject: Base files for TB3 tests (#12572) * Converted LabelModes to TB3 for validation Change-Id: Ic9e69d46623a16986961bdc8cc050b375622a91d --- .../com/vaadin/tests/tb3/ParallelScheduler.java | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/tb3/ParallelScheduler.java (limited to 'uitest/src/com/vaadin/tests/tb3/ParallelScheduler.java') diff --git a/uitest/src/com/vaadin/tests/tb3/ParallelScheduler.java b/uitest/src/com/vaadin/tests/tb3/ParallelScheduler.java new file mode 100644 index 0000000000..f8013169fa --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/ParallelScheduler.java @@ -0,0 +1,60 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.tb3; + +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; + +/** + * JUnit scheduler capable of running multiple tets in parallel. Each test is + * run in its own thread. Uses an {@link ExecutorService} to manage the threads. + * + * @author Vaadin Ltd + */ +public class ParallelScheduler implements RunnerScheduler { + private final List> fResults = new ArrayList>(); + + private final ExecutorService fService = Executors.newCachedThreadPool(); + + @Override + public void schedule(final Runnable childStatement) { + fResults.add(fService.submit(new Callable() { + @Override + public Object call() throws Exception { + childStatement.run(); + return null; + } + })); + } + + @Override + public void finished() { + for (Future each : fResults) { + try { + each.get(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } +} -- cgit v1.2.3 From bd0ae0581f265be57374b236cfe1b71043ab69aa Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 24 Sep 2013 18:19:45 +0300 Subject: Limit the number of tests run concurrently (#12572) Change-Id: I015e92ccc9be963543032c14dd9d051bcba58e53 --- uitest/src/com/vaadin/tests/tb3/ParallelScheduler.java | 13 +++++++++++-- uitest/src/com/vaadin/tests/tb3/TB3Runner.java | 16 +++++++++++++++- uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java | 17 ++++++++++++++++- 3 files changed, 42 insertions(+), 4 deletions(-) (limited to 'uitest/src/com/vaadin/tests/tb3/ParallelScheduler.java') diff --git a/uitest/src/com/vaadin/tests/tb3/ParallelScheduler.java b/uitest/src/com/vaadin/tests/tb3/ParallelScheduler.java index f8013169fa..912d7d010e 100644 --- a/uitest/src/com/vaadin/tests/tb3/ParallelScheduler.java +++ b/uitest/src/com/vaadin/tests/tb3/ParallelScheduler.java @@ -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> fResults = new ArrayList>(); + 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) { diff --git a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java index 5860ac42c0..b612b17caa 100644 --- a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java +++ b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java @@ -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 diff --git a/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java b/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java index dc187000d2..e1c8edfd60 100644 --- a/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java +++ b/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java @@ -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 baseClass, String basePackage, String[] ignorePackages) throws InitializationError { super(klass, findTests(baseClass, basePackage, ignorePackages)); - setScheduler(new ParallelScheduler()); + setScheduler(new ParallelScheduler(service)); } /** -- cgit v1.2.3