forked from apache/geode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEODE-3071: Provide capability to parallelize distributedTests
Herewith the ability to leverage Gradle's parallel test execution capability to run dunits in parallel. This is combined with launching tests in Docker containers to provide process, network and filesystem isolation. Depending on the size of your system, this can speed up running the distributedTest task 2-5 times. The capability is enabled by launching gradle with '-PparallelDunit' Tunables, enabled as gradle parametrs (-P option) are: - dunitDockerImage: The docker image which will be used to launch tests. The image must have the JAVA_HOME environment variable set. The image must be pulled locally before starting the tests. - dunitParallelForks: The number of parallel docker containers to be launched. - dunitDockerUser: The docker user which will run the tests. Because of the way that the containers map the build directory into them, the test artifacts, will be written with this user id. By default this is 'root'.
- Loading branch information
1 parent
a4d790c
commit 588c3ed
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Configuration for running (dunit) tests in parallel in Docker containers. | ||
* The container used must hava JAVA_HOME set in it's environment and must | ||
* have 'java' defined on the path. For example, the relevant Dockerfile | ||
* content could be: | ||
* | ||
* ENV JAVA_HOME=/opt/jdk1.8.0_u101 | ||
* ENV PATH=$PATH:$JAVA_HOME/bin | ||
* | ||
* In addition, the container must have docker installed. | ||
* | ||
* The plugin can be activated with the Gradle property 'parallelDunit'. | ||
* Additional properties that can be set are: | ||
* | ||
* dunitDockerImage - The docker image used for running parallel dunits. The | ||
* default image is 'openjdk:8'. The image is required to | ||
* have 'JAVA_HOME' set as an environment variable. | ||
* dunitParallelForks - The number of parallel containers that will be | ||
* launched. The default is 8. | ||
* dunitDockerUser - The user used within the docker container to run tests. | ||
* The default is 'root'. | ||
*/ | ||
|
||
def dockerConfig = { | ||
maxParallelForks = dunitParallelForks.toInteger() | ||
|
||
docker { | ||
// base image for creating docker containers that execute the tests | ||
image = dunitDockerImage | ||
|
||
// volumes mounted to the containers | ||
// in a form: host_dir : container_dir | ||
def pwd = System.getenv('PWD') | ||
def gradleHome = System.getenv('GRADLE_USER_HOME') ?: "${System.getenv('HOME')}/.gradle" | ||
volumes = ["${gradleHome}":gradleHome] | ||
|
||
volumes << ["${pwd}":pwd] | ||
|
||
// specify the user for starting Gradle test worker within the container. | ||
user = dunitDockerUser | ||
|
||
argsInspect = { List args -> | ||
def javaHomeIdx = 0 | ||
def i = args.iterator() | ||
def j = 0 | ||
while (i.hasNext()) { | ||
if (i.next() == '-e') { | ||
def x = i.next() | ||
j++ | ||
if (x.startsWith('JAVA_HOME')) { | ||
javaHomeIdx = j | ||
} | ||
} | ||
j++ | ||
} | ||
|
||
// Remove JAVA_HOME env variable - it might not be the same as the container needs | ||
if (javaHomeIdx > 0) { | ||
args.removeAt(javaHomeIdx-1) | ||
args.removeAt(javaHomeIdx-1) | ||
} | ||
|
||
// Infer the index of this invocation | ||
def matcher = (args[args.size - 1] =~ /.*Executor (\d*).*/) | ||
|
||
args[3] = args[3] + matcher[0][1] | ||
def workdir = new File(args[3]) | ||
println "dockerize: making ${workdir}" | ||
workdir.mkdirs() | ||
// println args | ||
|
||
args | ||
} | ||
} | ||
} | ||
|
||
subprojects { | ||
apply plugin: 'com.github.pedjak.dockerized-test' | ||
|
||
if (project.hasProperty('parallelDunit')) { | ||
distributedTest.configure(dockerConfig) | ||
} | ||
} |