Rework the way multi-jvm tests work

To allow some JVMs runs only subset of tests
This commit is contained in:
Nikolay Martynov 2018-09-28 18:22:29 -04:00
parent 854866df57
commit f71192266c
25 changed files with 270 additions and 108 deletions

View File

@ -13,12 +13,9 @@ cache_keys: &cache_keys
- dd-trace-java-{{ checksum "dd-trace-java.gradle" }}-{{ .Branch }}
- dd-trace-java-{{ checksum "dd-trace-java.gradle" }}
jobs:
build:
<<: *defaults
docker:
- image: circleci/openjdk:8-jdk
steps:
- checkout
@ -28,7 +25,7 @@ jobs:
- run:
name: Build Project
command: GRADLE_OPTS="-Dorg.gradle.jvmargs=-Xmx1G -Xms64M" ./gradlew clean :dd-java-agent:shadowJar compileTestGroovy compileTestScala compileTestJava check -x test -x latestDepTest -x traceAgentTest --build-cache --parallel --stacktrace --no-daemon --max-workers=4
command: GRADLE_OPTS="-Dorg.gradle.jvmargs=-Xmx1G -Xms64M" ./gradlew clean :dd-java-agent:shadowJar compileTestGroovy compileTestScala compileTestJava --build-cache --parallel --stacktrace --no-daemon --max-workers=4
- run:
name: Collect Libs
@ -38,14 +35,6 @@ jobs:
- store_artifacts:
path: ./libs
- run:
name: Collect Reports
when: always
command: .circleci/collect_reports.sh
- store_artifacts:
path: ./reports
- persist_to_workspace:
root: .
paths:
@ -54,7 +43,6 @@ jobs:
- save_cache:
key: dd-trace-java-{{ checksum "dd-trace-java.gradle" }}-{{ .Branch }}-{{ .Revision }}
paths: ~/.gradle
background: true
default_test_job: &default_test_job
@ -111,7 +99,7 @@ jobs:
test_7:
<<: *default_test_job
environment:
- JAVA7_HOME: /usr/lib/jvm/zulu-7-amd64
- JAVA_7_HOME: /usr/lib/jvm/zulu-7-amd64
- TEST_TASK: testJava7
- INSTALL_ZULU: zulu-7
@ -124,28 +112,28 @@ jobs:
test_9:
<<: *default_test_job
environment:
- JAVA9_HOME: /usr/lib/jvm/zulu-9-amd64
- TEST_TASK: testJava9 latestDepTestJava9
- JAVA_9_HOME: /usr/lib/jvm/zulu-9-amd64
- TEST_TASK: testJava9
- INSTALL_ZULU: zulu-9
test_10:
<<: *default_test_job
environment:
- JAVA10_HOME: /usr/lib/jvm/zulu-10-amd64
- TEST_TASK: testJava10 latestDepTestJava10
- JAVA_10_HOME: /usr/lib/jvm/zulu-10-amd64
- TEST_TASK: testJava10
- INSTALL_ZULU: zulu-10
test_11:
<<: *default_test_job
environment:
- JAVA11_HOME: /usr/lib/jvm/jdk-11
- TEST_TASK: testJava11 latestDepTestJava11
- JAVA_11_HOME: /usr/lib/jvm/jdk-11
- TEST_TASK: testJava11
- INSTALL_OPENJDK: https://download.java.net/java/ga/jdk11/openjdk-11_linux-x64_bin.tar.gz
agent_integration_tests:
<<: *defaults
docker:
- image: circleci/openjdk:8-jdk
- image: *default_container
- image: datadog/docker-dd-agent
environment:
- DD_APM_ENABLED=true
@ -158,11 +146,7 @@ jobs:
at: .
- restore_cache:
# Reset the cache approx every release
keys:
- dd-trace-java-{{ checksum "dd-trace-java.gradle" }}-{{ .Branch }}-{{ .Revision }}
- dd-trace-java-{{ checksum "dd-trace-java.gradle" }}-{{ .Branch }}
- dd-trace-java-{{ checksum "dd-trace-java.gradle" }}
<<: *cache_keys
- run:
name: Run Trace Agent Tests
@ -184,6 +168,30 @@ jobs:
- store_test_results:
path: ./results
check:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: .
- restore_cache:
<<: *cache_keys
- run:
name: Build Project
command: GRADLE_OPTS="-Dorg.gradle.jvmargs=-Xmx1G -Xms64M" ./gradlew check -PskipTests --build-cache --parallel --stacktrace --no-daemon --max-workers=4
- run:
name: Collect Reports
when: always
command: .circleci/collect_reports.sh
- store_artifacts:
path: ./reports
scan_versions:
<<: *defaults
steps:
@ -280,6 +288,13 @@ workflows:
tags:
only: /.*/
- check:
requires:
- build
filters:
tags:
only: /.*/
- scan_versions:
requires:
- build
@ -295,6 +310,7 @@ workflows:
- test_10
- test_11
- agent_integration_tests
- check
filters:
branches:
only: master
@ -309,6 +325,7 @@ workflows:
- test_10
- test_11
- agent_integration_tests
- check
filters:
branches:
ignore: /.*/

View File

@ -1,3 +1,9 @@
// Set properties before any plugins get loaded
project.ext {
// Execute tests on all JVMs, even rare and outdated ones
integrationTests = true
}
apply from: "${rootDir}/gradle/java.gradle"
description = 'dd-java-agent-ittests'

View File

@ -1,3 +1,8 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
}
apply from: "${rootDir}/gradle/java.gradle"
apply from: "${rootDir}/gradle/test-with-scala.gradle"
@ -58,4 +63,3 @@ dependencies {
}
test.dependsOn lagomTest
testJava8Minimum += '*Test*.class'

View File

@ -170,7 +170,6 @@ class AkkaHttpClientInstrumentationTest extends AgentTestRunner {
}
def "#route pool request trace"() {
setup:
def url = server.address.resolve("/" + route).toURL()

View File

@ -1,3 +1,8 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
}
apply from: "${rootDir}/gradle/java.gradle"
apply plugin: 'org.unbroken-dome.test-sets'
@ -44,5 +49,3 @@ dependencies {
latestDepTestCompile group: 'com.couchbase.client', name: 'java-client', version: '2.6+'
latestDepTestCompile group: 'com.couchbase.client', name: 'encryption', version: '+'
}
testJava8Minimum += "**/*.class"

View File

@ -1,3 +1,10 @@
// Set properties before any plugins get loaded
ext {
// Test use Cassandra 3 which requires Java 8. (Currently incompatible with Java 9.)
minJavaVersionForTests = JavaVersion.VERSION_1_8
maxJavaVersionForTests = JavaVersion.VERSION_1_8
}
muzzle {
pass {
group = "com.datastax.cassandra"
@ -8,9 +15,6 @@ muzzle {
apply from: "${rootDir}/gradle/java.gradle"
// These classes use Cassandra 3 which requires Java 8. (Currently incompatible with Java 9.)
testJava8Only += '**/CassandraClientTest.class'
apply plugin: 'org.unbroken-dome.test-sets'
testSets {

View File

@ -1,3 +1,8 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
}
muzzle {
pass {
group = "org.elasticsearch.client"
@ -9,8 +14,6 @@ muzzle {
apply from: "${rootDir}/gradle/java.gradle"
testJava8Minimum += '**/*Test.class'
apply plugin: 'org.unbroken-dome.test-sets'
testSets {

View File

@ -1,3 +1,9 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
maxJavaVersionForTests = JavaVersion.VERSION_1_8
}
muzzle {
pass {
group = "org.elasticsearch"
@ -9,8 +15,6 @@ muzzle {
apply from: "${rootDir}/gradle/java.gradle"
testJava8Only += '**/*Test.class'
apply plugin: 'org.unbroken-dome.test-sets'
testSets {

View File

@ -1,3 +1,8 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
}
muzzle {
pass {
group = "org.elasticsearch.client"
@ -15,8 +20,6 @@ muzzle {
apply from: "${rootDir}/gradle/java.gradle"
testJava8Minimum += '**/*Test.class'
apply plugin: 'org.unbroken-dome.test-sets'
testSets {

View File

@ -1,3 +1,8 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
}
muzzle {
pass {
group = "org.elasticsearch.client"
@ -15,8 +20,6 @@ muzzle {
apply from: "${rootDir}/gradle/java.gradle"
testJava8Minimum += '**/*Test.class'
apply plugin: 'org.unbroken-dome.test-sets'
testSets {

View File

@ -1,3 +1,8 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
}
muzzle {
pass {
group = "org.elasticsearch.client"
@ -15,8 +20,6 @@ muzzle {
apply from: "${rootDir}/gradle/java.gradle"
testJava8Minimum += '**/*Test.class'
apply plugin: 'org.unbroken-dome.test-sets'
testSets {

View File

@ -1,3 +1,9 @@
// Set properties before any plugins get loaded
project.ext {
// Execute tests on all JVMs, even rare and outdated ones
coreJavaInstrumentation = true
}
apply from: "${rootDir}/gradle/java.gradle"
dependencies {
@ -10,5 +16,4 @@ dependencies {
testCompile project(':dd-java-agent:testing')
testCompile group: 'org.springframework', name: 'spring-web', version: '4.3.7.RELEASE'
}

View File

@ -1,3 +1,9 @@
// Set properties before any plugins get loaded
project.ext {
// Execute tests on all JVMs, even rare and outdated ones
coreJavaInstrumentation = true
}
apply from: "${rootDir}/gradle/java.gradle"
apply from: "${rootDir}/gradle/test-with-scala.gradle"

View File

@ -1,3 +1,9 @@
// Set properties before any plugins get loaded
project.ext {
// Execute tests on all JVMs, even rare and outdated ones
coreJavaInstrumentation = true
}
apply from: "${rootDir}/gradle/java.gradle"
apply plugin: 'org.unbroken-dome.test-sets'

View File

@ -1,3 +1,9 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
maxJavaVersionForTests = JavaVersion.VERSION_1_8
}
apply plugin: 'version-scan'
muzzle {
@ -62,7 +68,3 @@ configurations.latestDepTestCompile {
force group: 'io.lettuce', name: 'lettuce-core', version: '+'
}
}
testJava8Only += '**/LettuceAsyncClientTest.class'
testJava8Only += '**/LettuceSyncClientTest.class'
testJava8Only += '**/LettuceReactiveClientTest.class'

View File

@ -1,3 +1,9 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
maxJavaVersionForTests = JavaVersion.VERSION_1_8
}
apply from: "${rootDir}/gradle/java.gradle"
muzzle {
@ -59,4 +65,3 @@ configurations.latestDepTestCompile {
}
}
testJava8Only += '**/*Test.class'

View File

@ -1,3 +1,9 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
maxJavaVersionForTests = JavaVersion.VERSION_1_8
}
apply from: "${rootDir}/gradle/java.gradle"
muzzle {
@ -59,4 +65,3 @@ configurations.latestDepTestCompile {
}
}
testJava8Only += '**/*Test.class'

View File

@ -1,3 +1,8 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
}
apply from: "${rootDir}/gradle/java.gradle"
apply from: "${rootDir}/gradle/test-with-scala.gradle"
@ -48,5 +53,3 @@ compileLatestDepTestGroovy {
classpath = classpath.plus(files(compileLatestDepTestScala.destinationDir))
dependsOn compileLatestDepTestScala
}
testJava8Minimum += '*Play*Test*'

View File

@ -1,3 +1,9 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
maxJavaVersionForTests = JavaVersion.VERSION_1_8
}
apply plugin: 'version-scan'
versionScan {
@ -27,9 +33,11 @@ compileMain_java8Java {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
configurations {
main_java8AnnotationProcessor.extendsFrom lombok
main_java8Implementation.extendsFrom lombok
// Note: ideally lombok plugin would do this for us, but currently it doesn't support custom
// source sets. See https://github.com/franzbecker/gradle-lombok/issues/17.
dependencies {
main_java8CompileOnly "org.projectlombok:lombok:${project.lombok.version}" transitive false
main_java8AnnotationProcessor "org.projectlombok:lombok:${project.lombok.version}" transitive false
}
apply plugin: 'org.unbroken-dome.test-sets'
@ -65,5 +73,3 @@ configurations.latestDepTestCompile {
force group: 'io.ratpack', name: 'ratpack-groovy-test', version: '+'
}
}
testJava8Only += '**/RatpackTest.class'

View File

@ -1,3 +1,8 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
}
// building against 2.3 and testing against 2.4 because JettyHandler is available since 2.4 only
muzzle {
pass {
@ -10,8 +15,6 @@ muzzle {
apply from: "${rootDir}/gradle/java.gradle"
testJava8Minimum += '**/SparkJavaBasedTest.class'
apply plugin: 'org.unbroken-dome.test-sets'
testSets {

View File

@ -1,3 +1,9 @@
// Set properties before any plugins get loaded
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
maxJavaVersionForTests = JavaVersion.VERSION_1_8
}
muzzle {
pass {
group = "org.springframework"
@ -77,6 +83,3 @@ configurations.latestDepTestCompile {
force group: 'org.springframework.boot', name: 'spring-boot-starter-reactor-netty', version: '+'
}
}
testJava8Only += '**/*Test.class'
testJava8Only += '**/*TestApplication.class'

View File

@ -1,19 +1,15 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.franzbecker:gradle-lombok:1.13"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.7.3"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.1"
classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.14"
classpath "org.unbroken-dome.gradle-plugins:gradle-testsets-plugin:1.5.0"
}
}
plugins {
id 'io.franzbecker.gradle-lombok' version '1.13'
id 'com.jfrog.artifactory' version '4.7.5'
id 'com.jfrog.bintray' version '1.8.4'
id 'net.ltgt.errorprone' version '0.0.14'
id 'org.unbroken-dome.test-sets' version '1.5.1'
id 'com.gradle.build-scan' version '1.15.1'
id 'com.github.sherter.google-java-format' version '0.7.1'
// Not applying google java format by default because it gets confused by stray java build
// files in 'workspace' build directory in CI
id 'com.github.sherter.google-java-format' version '0.7.1' apply false
id 'com.dorongold.task-tree' version '1.3'
}

View File

@ -54,7 +54,6 @@ apply plugin: 'com.github.sherter.google-java-format'
googleJavaFormat {
source = sourceSets*.allJava
include '**/*.java'
exclude '**/build/**/*.java'
}

View File

@ -14,7 +14,7 @@ ext {
groovy : groovyVer,
junit : "4.12",
logback : "1.2.3",
lombok : "1.18.0",
lombok : "1.18.2",
bytebuddy : "1.9.0",
]

View File

@ -1,6 +1,10 @@
apply plugin: 'java'
apply plugin: 'groovy'
apply from: "$rootDir/gradle/checkstyle.gradle"
apply from: "$rootDir/gradle/codenarc.gradle"
apply from: "$rootDir/gradle/jacoco.gradle"
sourceCompatibility = 1.7
targetCompatibility = 1.7
@ -136,43 +140,113 @@ if (project.hasProperty("removeJarVersionNumbers") && removeJarVersionNumbers) {
}
}
if (project.parent && project.parent.hasProperty("javaExecutableVersionCache")) {
project.ext.javaExecutableVersionCache = project.parent.ext.javaExecutableVersionCache
} else {
project.ext.javaExecutableVersionCache = [:]
}
def getJavaExecutableVersion(String path) {
def cache = project.ext.javaExecutableVersionCache
project.ext.testJava8Only = []
project.ext.testJava8Minimum = []
tasks.withType(Test) {
if (name.endsWith("Java7") || name.endsWith("Java9") || name.endsWith("Java10") || name.endsWith("Java11")) {
return
if (cache.containsKey(path)) {
return cache.get(path)
}
def cloned = it
[7, 9, 10, 11].each { i ->
def javaHome = System.getenv("JAVA${i}_HOME")
if (javaHome != null) {
def test = task "${cloned.name}Java${i}"(type: cloned.class) {
group = "Verification"
description "Runs $cloned.name under Java ${i}"
executable = "$javaHome/bin/java"
if (i == 7) {
afterEvaluate {
exclude project.testJava8Only
exclude project.testJava8Minimum
}
} else if (i > 8) {
afterEvaluate {
exclude project.testJava8Only
}
}
}
tasks.check.dependsOn test
new ByteArrayOutputStream().withStream { stream ->
exec {
commandLine = [path, "-version"]
errorOutput = stream
}
def matcher = stream.toString() =~ /^(?:java|openjdk) version "([^"]+)"/
if (matcher) {
def version = JavaVersion.toVersion(matcher.group(1))
cache.put(path, version)
return version
} else {
throw new GradleScriptException("Cannot determine java version: ${stream.toString}")
}
}
}
apply from: "$rootDir/gradle/checkstyle.gradle"
apply from: "$rootDir/gradle/codenarc.gradle"
apply from: "$rootDir/gradle/jacoco.gradle"
def isJavaVersionAllowed(JavaVersion version) {
if (project.hasProperty('minJavaVersionForTests') && project.getProperty('minJavaVersionForTests').compareTo(version) > 0) {
return false
}
if (project.hasProperty('maxJavaVersionForTests') && project.getProperty('maxJavaVersionForTests').compareTo(version) < 0) {
return false
}
return true
}
// JVM names we would like to run complete test suite on
// Note: complete test suite is always run on JVM used for compilation
// Note2: apparently there is no way to have a 'global' variable, so instead we have per project
// attribute that has same value in all projects
project.ext.majorSupportedJVMs = ["7", "11"]
def isTestingEnabled(String javaName) {
if (javaName in project.majorSupportedJVMs) {
return true
}
if (project.findProperty("coreJavaInstrumentation") || project.findProperty("integrationTests")) {
return true
}
return false
}
// Disable default test tasks if current JVM doesn't match version requirements
tasks.withType(Test) {
if (name.endsWith("Generated")) {
return
}
// Always run all tests that are runnable on JVM used for compilation
onlyIf { isJavaVersionAllowed(JavaVersion.current()) }
}
// Generate tests tasks for all provided JVMs
for (def env : System.getenv().entrySet()) {
def matcher = env.key =~ /JAVA_([^_]+)_HOME/
if (!matcher) {
continue
}
def javaName = matcher.group(1)
def javaHome = env.value
def javaPath = "$javaHome/bin/java"
def javaVersion = getJavaExecutableVersion(javaPath)
def parentTask = task "testJava${javaName}"() {
group = 'Verification'
description = "Run tests for Java ${javaName}"
}
tasks.check.dependsOn parentTask
tasks.withType(Test) {
if (name.endsWith("Generated")) {
return
}
def clonedTask = it
def newTask = task "${clonedTask.name}Java${javaName}Generated"(type: clonedTask.class) {
description "Runs $clonedTask.name under java ${javaName}"
executable = javaPath
onlyIf { isJavaVersionAllowed(javaVersion) && isTestingEnabled(javaName) }
jacoco {
// Disable jacoco for additional JVM tests to speed things up a bit
enabled = false
}
}
parentTask.dependsOn newTask
}
}
// Disable all tests if skipTests property was specified
if (project.hasProperty("skipTests")) {
tasks.withType(Test) {
onlyIf { false }
}
}
plugins.withType(BasePlugin) {
project.afterEvaluate {