HADOOP-11984. Enable parallel JUnit tests in pre-commit (Contributed by Chris Nauroth)

(cherry picked from commit f0f984e4e6)
This commit is contained in:
Vinayakumar B 2015-09-27 14:12:07 +05:30
parent 2dca55be00
commit 1c7b3b98c1
11 changed files with 142 additions and 60 deletions

View File

@ -599,6 +599,8 @@ function hadoop_usage
echo "--run-tests Run all relevant tests below the base directory" echo "--run-tests Run all relevant tests below the base directory"
echo "--skip-system-plugins Do not load plugins from ${BINDIR}/test-patch.d" echo "--skip-system-plugins Do not load plugins from ${BINDIR}/test-patch.d"
echo "--testlist=<list> Specify which subsystem tests to use (comma delimited)" echo "--testlist=<list> Specify which subsystem tests to use (comma delimited)"
echo "--test-parallel=<bool> Run multiple tests in parallel (default false in developer mode, true in Jenkins mode)"
echo "--test-threads=<int> Number of tests to run in parallel (default defined in ${PROJECT_NAME} build)"
echo "Shell binary overrides:" echo "Shell binary overrides:"
echo "--awk-cmd=<cmd> The 'awk' command to use (default 'awk')" echo "--awk-cmd=<cmd> The 'awk' command to use (default 'awk')"
@ -691,6 +693,7 @@ function parse_args
;; ;;
--jenkins) --jenkins)
JENKINS=true JENKINS=true
TEST_PARALLEL=${TEST_PARALLEL:-true}
;; ;;
--jira-cmd=*) --jira-cmd=*)
JIRACLI=${i#*=} JIRACLI=${i#*=}
@ -749,6 +752,12 @@ function parse_args
add_test "${j}" add_test "${j}"
done done
;; ;;
--test-parallel=*)
TEST_PARALLEL=${i#*=}
;;
--test-threads=*)
TEST_THREADS=${i#*=}
;;
--wget-cmd=*) --wget-cmd=*)
WGET=${i#*=} WGET=${i#*=}
;; ;;
@ -811,6 +820,13 @@ function parse_args
PATCH_DIR=$(cd -P -- "${PATCH_DIR}" >/dev/null && pwd -P) PATCH_DIR=$(cd -P -- "${PATCH_DIR}" >/dev/null && pwd -P)
GITDIFFLINES=${PATCH_DIR}/gitdifflines.txt GITDIFFLINES=${PATCH_DIR}/gitdifflines.txt
if [[ ${TEST_PARALLEL} == "true" ]] ; then
PARALLEL_TESTS_PROFILE=-Pparallel-tests
if [[ -n ${TEST_THREADS:-} ]]; then
TESTS_THREAD_COUNT="-DtestsThreadCount=$TEST_THREADS"
fi
fi
} }
## @description Locate the pom.xml file for a given directory ## @description Locate the pom.xml file for a given directory
@ -2239,13 +2255,22 @@ function check_unittests
test_logfile=${PATCH_DIR}/testrun_${module_suffix}.txt test_logfile=${PATCH_DIR}/testrun_${module_suffix}.txt
echo " Running tests in ${module_suffix}" echo " Running tests in ${module_suffix}"
echo_and_redirect "${test_logfile}" "${MVN}" "${MAVEN_ARGS[@]}" clean install -fae ${NATIVE_PROFILE} ${REQUIRE_TEST_LIB_HADOOP} -D${PROJECT_NAME}PatchProcess # Temporary hack to run the parallel tests profile only for hadoop-common.
# This code will be removed once hadoop-hdfs is ready for parallel test
# execution.
if [[ ${module} == "hadoop-common-project/hadoop-common" ]] ; then
OPTIONAL_PARALLEL_TESTS_PROFILE=${PARALLEL_TESTS_PROFILE}
else
unset OPTIONAL_PARALLEL_TESTS_PROFILE
fi
# shellcheck disable=2086
echo_and_redirect "${test_logfile}" "${MVN}" "${MAVEN_ARGS[@]}" clean install -fae ${NATIVE_PROFILE} ${REQUIRE_TEST_LIB_HADOOP} ${OPTIONAL_PARALLEL_TESTS_PROFILE} ${TESTS_THREAD_COUNT} -D${PROJECT_NAME}PatchProcess
test_build_result=$? test_build_result=$?
add_jira_footer "${module_suffix} test log" "@@BASE@@/testrun_${module_suffix}.txt" add_jira_footer "${module_suffix} test log" "@@BASE@@/testrun_${module_suffix}.txt"
# shellcheck disable=2016 # shellcheck disable=2016
module_test_timeouts=$(${AWK} '/^Running / { if (last) { print last } last=$2 } /^Tests run: / { last="" }' "${test_logfile}") module_test_timeouts=$(${AWK} '/^Running / { array[$NF] = 1 } /^Tests run: .* in / { delete array[$NF] } END { for (x in array) { print x } }' "${test_logfile}")
if [[ -n "${module_test_timeouts}" ]] ; then if [[ -n "${module_test_timeouts}" ]] ; then
test_timeouts="${test_timeouts} ${module_test_timeouts}" test_timeouts="${test_timeouts} ${module_test_timeouts}"
result=1 result=1

View File

@ -314,6 +314,9 @@ Release 2.8.0 - UNRELEASED
HADOOP-11878. FileContext#fixRelativePart should check for not null for a HADOOP-11878. FileContext#fixRelativePart should check for not null for a
more informative exception. (Brahma Reddy Battula via kasha) more informative exception. (Brahma Reddy Battula via kasha)
HADOOP-11984. Enable parallel JUnit tests in pre-commit.
(Chris Nauroth via vinayakumarb)
BUG FIXES BUG FIXES
HADOOP-12374. Updated expunge command description. HADOOP-12374. Updated expunge command description.

View File

@ -757,12 +757,53 @@
<id>parallel-tests</id> <id>parallel-tests</id>
<build> <build>
<plugins> <plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>create-parallel-tests-dirs</id>
<phase>test-compile</phase>
<configuration>
<target>
<script language="javascript"><![CDATA[
var baseDirs = [
"${test.build.data}",
"${test.build.dir}",
"${hadoop.tmp.dir}" ];
for (var i in baseDirs) {
for (var j = 1; j <= ${testsThreadCount}; ++j) {
var mkdir = project.createTask("mkdir");
mkdir.setDir(new java.io.File(baseDirs[i], j));
mkdir.perform();
}
}
]]></script>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
<forkCount>${testsThreadCount}</forkCount> <forkCount>${testsThreadCount}</forkCount>
<argLine>-Xmx1024m -XX:+HeapDumpOnOutOfMemoryError -DminiClusterDedicatedDirs=true</argLine> <reuseForks>false</reuseForks>
<argLine>${maven-surefire-plugin.argLine} -DminiClusterDedicatedDirs=true</argLine>
<systemPropertyVariables>
<test.build.data>${test.build.data}/${surefire.forkNumber}</test.build.data>
<test.build.dir>${test.build.dir}/${surefire.forkNumber}</test.build.dir>
<hadoop.tmp.dir>${hadoop.tmp.dir}/${surefire.forkNumber}</hadoop.tmp.dir>
<!-- Due to a Maven quirk, setting this to just -->
<!-- surefire.forkNumber won't do the parameter substitution. -->
<!-- Putting a prefix in front of it like "fork-" makes it -->
<!-- work. -->
<test.unique.fork.id>fork-${surefire.forkNumber}</test.unique.fork.id>
</systemPropertyVariables>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

View File

@ -1335,7 +1335,7 @@ public class TestConfiguration extends TestCase {
@Override @Override
public void run() { public void run() {
for (int i = 0; i < 100000; i++) { for (int i = 0; i < 10000; i++) {
config.set("some.config.value-" + prefix + i, "value"); config.set("some.config.value-" + prefix + i, "value");
} }
} }

View File

@ -23,10 +23,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.Socket; import java.net.Socket;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -34,8 +31,8 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import org.apache.hadoop.net.ServerSocketUtil;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.apache.zookeeper.PortAssignment;
import org.apache.zookeeper.TestableZooKeeper; import org.apache.zookeeper.TestableZooKeeper;
import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher; import org.apache.zookeeper.Watcher;
@ -167,10 +164,6 @@ public abstract class ClientBaseWithFixes extends ZKTestCase {
private LinkedList<ZooKeeper> allClients; private LinkedList<ZooKeeper> allClients;
private boolean allClientsSetup = false; private boolean allClientsSetup = false;
private RandomAccessFile portNumLockFile;
private File portNumFile;
protected TestableZooKeeper createClient(CountdownWatcher watcher, String hp) protected TestableZooKeeper createClient(CountdownWatcher watcher, String hp)
throws IOException, InterruptedException throws IOException, InterruptedException
{ {
@ -413,30 +406,12 @@ public abstract class ClientBaseWithFixes extends ZKTestCase {
private String initHostPort() { private String initHostPort() {
BASETEST.mkdirs(); BASETEST.mkdirs();
int port; int port = 0;
for (;;) {
port = PortAssignment.unique();
FileLock lock = null;
portNumLockFile = null;
try { try {
try { port = ServerSocketUtil.getPort(port, 100);
portNumFile = new File(BASETEST, port + ".lock");
portNumLockFile = new RandomAccessFile(portNumFile, "rw");
try {
lock = portNumLockFile.getChannel().tryLock();
} catch (OverlappingFileLockException e) {
continue;
}
} finally {
if (lock != null)
break;
if (portNumLockFile != null)
portNumLockFile.close();
}
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}
return "127.0.0.1:" + port; return "127.0.0.1:" + port;
} }
@ -480,9 +455,6 @@ public abstract class ClientBaseWithFixes extends ZKTestCase {
stopServer(); stopServer();
portNumLockFile.close();
portNumFile.delete();
if (tmpDir != null) { if (tmpDir != null) {
Assert.assertTrue("delete " + tmpDir.toString(), recursiveDelete(tmpDir)); Assert.assertTrue("delete " + tmpDir.toString(), recursiveDelete(tmpDir));
} }

View File

@ -113,10 +113,7 @@ public class TestAuthenticationSessionCookie {
sslConfDir = KeyStoreTestUtil.getClasspathDir(TestSSLHttpServer.class); sslConfDir = KeyStoreTestUtil.getClasspathDir(TestSSLHttpServer.class);
KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false); KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false);
Configuration sslConf = new Configuration(false); Configuration sslConf = KeyStoreTestUtil.getSslConfig();
sslConf.addResource("ssl-server.xml");
sslConf.addResource("ssl-client.xml");
server = new HttpServer2.Builder() server = new HttpServer2.Builder()
.setName("test") .setName("test")

View File

@ -17,7 +17,6 @@ import org.junit.Assert;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.authentication.client.AuthenticatedURL;
import org.apache.hadoop.security.authentication.server.AuthenticationFilter; import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
import org.apache.hadoop.security.ssl.KeyStoreTestUtil; import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
import org.apache.hadoop.security.ssl.SSLFactory; import org.apache.hadoop.security.ssl.SSLFactory;
@ -27,12 +26,10 @@ import org.junit.Test;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import javax.servlet.*; import javax.servlet.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
@ -89,9 +86,7 @@ public class TestHttpCookieFlag {
sslConfDir = KeyStoreTestUtil.getClasspathDir(TestSSLHttpServer.class); sslConfDir = KeyStoreTestUtil.getClasspathDir(TestSSLHttpServer.class);
KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false); KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false);
Configuration sslConf = new Configuration(false); Configuration sslConf = KeyStoreTestUtil.getSslConfig();
sslConf.addResource("ssl-server.xml");
sslConf.addResource("ssl-client.xml");
clientSslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, sslConf); clientSslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, sslConf);
clientSslFactory.init(); clientSslFactory.init();

View File

@ -65,9 +65,7 @@ public class TestSSLHttpServer extends HttpServerFunctionalTest {
sslConfDir = KeyStoreTestUtil.getClasspathDir(TestSSLHttpServer.class); sslConfDir = KeyStoreTestUtil.getClasspathDir(TestSSLHttpServer.class);
KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false); KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false);
Configuration sslConf = new Configuration(false); Configuration sslConf = KeyStoreTestUtil.getSslConfig();
sslConf.addResource("ssl-server.xml");
sslConf.addResource("ssl-client.xml");
clientSslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, sslConf); clientSslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, sslConf);
clientSslFactory.init(); clientSslFactory.init();

View File

@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;
public class ServerSocketUtil { public class ServerSocketUtil {
private static final Log LOG = LogFactory.getLog(ServerSocketUtil.class); private static final Log LOG = LogFactory.getLog(ServerSocketUtil.class);
private static Random rand = new Random();
/** /**
* Port scan & allocate is how most other apps find ports * Port scan & allocate is how most other apps find ports
@ -38,13 +39,15 @@ public class ServerSocketUtil {
* @throws IOException * @throws IOException
*/ */
public static int getPort(int port, int retries) throws IOException { public static int getPort(int port, int retries) throws IOException {
Random rand = new Random();
int tryPort = port; int tryPort = port;
int tries = 0; int tries = 0;
while (true) { while (true) {
if (tries > 0) { if (tries > 0 || tryPort == 0) {
tryPort = port + rand.nextInt(65535 - port); tryPort = port + rand.nextInt(65535 - port);
} }
if (tryPort == 0) {
continue;
}
LOG.info("Using port " + tryPort); LOG.info("Using port " + tryPort);
try (ServerSocket s = new ServerSocket(tryPort)) { try (ServerSocket s = new ServerSocket(tryPort)) {
return tryPort; return tryPort;

View File

@ -37,7 +37,6 @@ import java.security.KeyPair;
import java.security.KeyPairGenerator; import java.security.KeyPairGenerator;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.cert.Certificate; import java.security.cert.Certificate;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
@ -49,8 +48,6 @@ import java.security.InvalidKeyException;
import java.security.NoSuchProviderException; import java.security.NoSuchProviderException;
import java.security.SignatureException; import java.security.SignatureException;
import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import javax.security.auth.x500.X500Principal; import javax.security.auth.x500.X500Principal;
import org.bouncycastle.x509.X509V1CertificateGenerator; import org.bouncycastle.x509.X509V1CertificateGenerator;
@ -233,8 +230,8 @@ public class KeyStoreTestUtil {
String trustKS = null; String trustKS = null;
String trustPassword = "trustP"; String trustPassword = "trustP";
File sslClientConfFile = new File(sslConfDir + "/ssl-client.xml"); File sslClientConfFile = new File(sslConfDir, getClientSSLConfigFileName());
File sslServerConfFile = new File(sslConfDir + "/ssl-server.xml"); File sslServerConfFile = new File(sslConfDir, getServerSSLConfigFileName());
Map<String, X509Certificate> certs = new HashMap<String, X509Certificate>(); Map<String, X509Certificate> certs = new HashMap<String, X509Certificate>();
@ -311,6 +308,42 @@ public class KeyStoreTestUtil {
return serverSSLConf; return serverSSLConf;
} }
/**
* Returns the client SSL configuration file name. Under parallel test
* execution, this file name is parameterized by a unique ID to ensure that
* concurrent tests don't collide on an SSL configuration file.
*
* @return client SSL configuration file name
*/
public static String getClientSSLConfigFileName() {
return getSSLConfigFileName("ssl-client");
}
/**
* Returns the server SSL configuration file name. Under parallel test
* execution, this file name is parameterized by a unique ID to ensure that
* concurrent tests don't collide on an SSL configuration file.
*
* @return client SSL configuration file name
*/
public static String getServerSSLConfigFileName() {
return getSSLConfigFileName("ssl-server");
}
/**
* Returns an SSL configuration file name. Under parallel test
* execution, this file name is parameterized by a unique ID to ensure that
* concurrent tests don't collide on an SSL configuration file.
*
* @param base the base of the file name
* @return SSL configuration file name for base
*/
private static String getSSLConfigFileName(String base) {
String testUniqueForkId = System.getProperty("test.unique.fork.id");
String fileSuffix = testUniqueForkId != null ? "-" + testUniqueForkId : "";
return base + fileSuffix + ".xml";
}
/** /**
* Creates SSL configuration. * Creates SSL configuration.
* *
@ -410,4 +443,19 @@ public class KeyStoreTestUtil {
throw e; throw e;
} }
} }
/**
* Get the SSL configuration
* @return {@link Configuration} instance with ssl configs loaded
*/
public static Configuration getSslConfig(){
Configuration sslConf = new Configuration(false);
String sslServerConfFile = KeyStoreTestUtil.getServerSSLConfigFileName();
String sslClientConfFile = KeyStoreTestUtil.getClientSSLConfigFileName();
sslConf.addResource(sslServerConfFile);
sslConf.addResource(sslClientConfFile);
sslConf.set(SSLFactory.SSL_SERVER_CONF_KEY, sslServerConfFile);
sslConf.set(SSLFactory.SSL_CLIENT_CONF_KEY, sslClientConfFile);
return sslConf;
}
} }

View File

@ -90,7 +90,7 @@
<enforced.maven.version>[3.0.2,)</enforced.maven.version> <enforced.maven.version>[3.0.2,)</enforced.maven.version>
<!-- Plugin versions and config --> <!-- Plugin versions and config -->
<maven-surefire-plugin.argLine>-Xmx4096m -XX:MaxPermSize=768m -XX:+HeapDumpOnOutOfMemoryError</maven-surefire-plugin.argLine> <maven-surefire-plugin.argLine>-Xmx2048m -XX:MaxPermSize=768m -XX:+HeapDumpOnOutOfMemoryError</maven-surefire-plugin.argLine>
<maven-surefire-plugin.version>2.17</maven-surefire-plugin.version> <maven-surefire-plugin.version>2.17</maven-surefire-plugin.version>
<maven-surefire-report-plugin.version>${maven-surefire-plugin.version}</maven-surefire-report-plugin.version> <maven-surefire-report-plugin.version>${maven-surefire-plugin.version}</maven-surefire-report-plugin.version>
<maven-failsafe-plugin.version>${maven-surefire-plugin.version}</maven-failsafe-plugin.version> <maven-failsafe-plugin.version>${maven-surefire-plugin.version}</maven-failsafe-plugin.version>