Make com.facebook.buck.util.concurrent.MoreExecutors available to our JUnitRunner. Summary: BuckBlockJUnit4ClassRunner contains some copy/paste code from MoreExecutors because our JUnit runner uses a restricted classpath. This diff refactors things to share the MoreExecutors code with our JUnitRunner. Also remove duplicate documentation in BuckBlockJUnit4ClassRunner. Test Plan: Sandcastle builds.
diff --git a/build.xml b/build.xml index 7e075b7..7520c21 100644 --- a/build.xml +++ b/build.xml
@@ -7,7 +7,6 @@ <property name="lib.dir" value="${basedir}/lib" /> <property name="third-party.dir" value="${basedir}/third-party" /> <property name="build.dir" value="${basedir}/build" /> - <property name="testrunner.src.dir" value="${src.dir}/com/facebook/buck/junit/" /> <property name="testrunner.classes.dir" value="${build.dir}/testrunner/classes" /> <property name="abi_processor.src.dir" value="${src.dir}/com/facebook/buck/java/abi/" /> <property name="abi_processor.classes.dir" value="${build.dir}/abi_processor/classes" /> @@ -90,7 +89,8 @@ <target name="compile-testrunner" depends="checkversion"> <mkdir dir="${testrunner.classes.dir}" /> - <javac srcdir="${testrunner.src.dir}" + <javac srcdir="${src.dir}" + includes="com/facebook/buck/junit/**,src/com/facebook/buck/util/concurrent/MoreExecutors.java" destdir="${testrunner.classes.dir}" classpathref="junit" debug="on"
diff --git a/src/com/facebook/buck/junit/BUCK b/src/com/facebook/buck/junit/BUCK index d91e09c..87e05ea 100644 --- a/src/com/facebook/buck/junit/BUCK +++ b/src/com/facebook/buck/junit/BUCK
@@ -6,6 +6,7 @@ # Java API. The objective is to limit the set of files added to the ClassLoader that runs the # test, as not to interfere with the results of the test. '//lib:junit', + '//src/com/facebook/buck/util/concurrent:concurrent_for_junit_runner', ], visibility = [ '//test/com/facebook/buck/junit:junit',
diff --git a/src/com/facebook/buck/junit/BuckBlockJUnit4ClassRunner.java b/src/com/facebook/buck/junit/BuckBlockJUnit4ClassRunner.java index 5674f34..f6e8962 100644 --- a/src/com/facebook/buck/junit/BuckBlockJUnit4ClassRunner.java +++ b/src/com/facebook/buck/junit/BuckBlockJUnit4ClassRunner.java
@@ -16,6 +16,8 @@ package com.facebook.buck.junit; +import com.facebook.buck.util.concurrent.MoreExecutors; + import org.junit.Rule; import org.junit.Test; import org.junit.rules.Timeout; @@ -36,8 +38,6 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -55,15 +55,7 @@ // Executors.newSingleThreadExecutor(). The problem with Executors.newSingleThreadExecutor() is // that it does not let us specify a RejectedExecutionHandler, which we need to ensure that // garbage is not spewed to the user's console if the build fails. - // Executors.newSingleThreadExecutor(). The problem with Executors.newSingleThreadExecutor() is - // that it does not let us specify a RejectedExecutionHandler, which we need to ensure that - // garbage is not spewed to the user's console if the build fails. - private final ExecutorService executor = new ThreadPoolExecutor( - /* corePoolSize */ 1, - /* maximumPoolSize */ 1, - /* keepAliveTime */ 0L, TimeUnit.MILLISECONDS, - /* workQueue */ new LinkedBlockingQueue<Runnable>(), - /* handler */ new ThreadPoolExecutor.DiscardPolicy()); + private final ExecutorService executor = MoreExecutors.newSingleThreadExecutor(); private final long defaultTestTimeoutMillis;
diff --git a/src/com/facebook/buck/util/concurrent/BUCK b/src/com/facebook/buck/util/concurrent/BUCK index 92540c6..8ef25f2 100644 --- a/src/com/facebook/buck/util/concurrent/BUCK +++ b/src/com/facebook/buck/util/concurrent/BUCK
@@ -7,3 +7,13 @@ visibility = ['PUBLIC'], ) +java_library( + name = 'concurrent_for_junit_runner', + srcs = [ 'MoreExecutors.java' ], + deps = [ + # IMPORTANT! This list is to remain empty. See src/com/facebook/buck/junit/BUCK. + ], + visibility = [ + '//src/com/facebook/buck/junit:junit', + ], +)