Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit de9f67c

Browse files
authored
Run the integration tests using different Java versions. (#638)
* Run the integration tests using different Java versions. * - Log the pathname of the java executable used for running integration tests. - Use a single environment variable, JAVA_HOMES, containing the home directories of the java installation used for integration tests. - Also test on multiple Java versions on Windows. * Cleanups: comments, install only what's missing, avoid backticks, don't ignore missing java home, grammar fix.
1 parent 83fed9c commit de9f67c

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ matrix:
1212
- jdk: oraclejdk8
1313
env: TASK=BUILD
1414
os: linux
15+
addons:
16+
apt:
17+
packages:
18+
# Install the JREs that are used for integration tests in
19+
# contrib/agent, but are not installed by default.
20+
- openjdk-6-jdk
1521

1622
- env: TASK=CHECK_GIT_HISTORY
1723
os: linux
@@ -49,6 +55,7 @@ script:
4955
export JAVA8_HOME="$(jdk_switcher home oraclejdk8)" ;
5056
case "$TRAVIS_JDK_VERSION" in
5157
"oraclejdk8")
58+
export JAVA_HOMES="$(jdk_switcher home openjdk6)/jre:$(jdk_switcher home openjdk7)/jre:$(jdk_switcher home oraclejdk8)/jre" ;
5259
./gradlew clean assemble --stacktrace ;
5360
./gradlew check :opencensus-all:jacocoTestReport ;;
5461
"openjdk7")

appveyor.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ install:
22
- git submodule update --init --recursive
33

44
build_script:
5+
# The Gradle build script runs the integration tests of contrib/agent using different Java
6+
# versions. %JAVA_HOMES% lists the home directories of the JDK installations used for
7+
# integration testing. Also see https://www.appveyor.com/docs/build-environment/#java.
8+
- set JAVA_HOMES=C:\Program Files\Java\jdk1.6.0\jre;C:\Program Files\Java\jdk1.7.0\jre;C:\Program Files\Java\jdk1.8.0\jre
59
- gradlew.bat clean assemble check --stacktrace

contrib/agent/build.gradle

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,11 @@ jar.finalizedBy shadowJar
126126

127127
// TODO(stschmidt): Proguard-shrink the agent JAR.
128128

129-
// Integration tests. The setup is mostly based on
129+
// Integration tests. The setup was initially based on
130130
// https://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-integration-testing/.
131+
// We run the same suite of integration tests on different Java versions with the agent enabled.
132+
// The JAVA_HOMES environment variable lists the home directories of the Java installations used
133+
// for integration testing.
131134

132135
sourceSets {
133136
integrationTest {
@@ -155,21 +158,42 @@ checkstyleIntegrationTest.enabled = JavaVersion.current().isJava8Compatible()
155158
// Disable findbugs for integration tests, too.
156159
findbugsIntegrationTest.enabled = false
157160

158-
// Run integration tests with the agent enabled.
159-
task integrationTest(type: Test) {
160-
testLogging {
161-
// Let Gradle output the stdout and stderr from tests, too. This is useful for investigating
162-
// test failures on Travis, where we can't view Gradle's test reports.
163-
showStandardStreams = true
161+
def javaExecutables = (System.getenv('JAVA_HOMES') ?: '')
162+
.tokenize(File.pathSeparator)
163+
.plus(System.getProperty('java.home'))
164+
.collect { org.apache.tools.ant.taskdefs.condition.Os.isFamily(
165+
org.apache.tools.ant.taskdefs.condition.Os.FAMILY_WINDOWS)
166+
? "${it}/bin/java.exe"
167+
: "${it}/bin/java" }
168+
.collect { new File(it).getCanonicalPath() }
169+
.unique()
170+
171+
assert javaExecutables.size > 0 :
172+
'No Java executables found for running integration tests'
173+
174+
task integrationTest
175+
176+
javaExecutables.eachWithIndex { javaExecutable, index ->
177+
def perVersionIntegrationTest = task("integrationTest_${index}", type: Test) {
178+
testLogging {
179+
// Let Gradle output the stdout and stderr from tests, too. This is useful for investigating
180+
// test failures on Travis, where we can't view Gradle's test reports.
181+
showStandardStreams = true
182+
183+
// Include the exception message and full stacktrace for failed tests.
184+
exceptionFormat 'full'
185+
}
164186

165-
// Include the exception message and full stacktrace for failed tests.
166-
exceptionFormat 'full'
167-
}
187+
testClassesDirs = sourceSets.integrationTest.output.classesDirs
188+
classpath = sourceSets.integrationTest.runtimeClasspath
168189

169-
testClassesDirs = sourceSets.integrationTest.output.classesDirs
170-
classpath = sourceSets.integrationTest.runtimeClasspath
190+
executable = javaExecutable
191+
jvmArgs "-javaagent:${shadowJar.archivePath}"
192+
193+
doFirst { logger.lifecycle("Running integration tests using ${javaExecutable}.") }
194+
}
171195

172-
jvmArgs "-javaagent:${shadowJar.archivePath}"
196+
integrationTest.dependsOn perVersionIntegrationTest
173197
}
174198

175199
check.dependsOn integrationTest

0 commit comments

Comments
 (0)