Skip to content

Commit

Permalink
JAVA-3042: Support testing against Java17
Browse files Browse the repository at this point in the history
Add property 'testJavaHome' to specify a different JDK for surefire/failsafe to run tests to facilitate testing with different JDKs.

pom.xml:
- Add '--add-opens java.base/jdk.internal.util.random=ALL-UNNAMED' as maven-surefire-plugin argLine to support deep reflection for mockito, only loaded for JDK17

Dependency updates:
- jacoco-maven-plugin -> 0.8.10, resolves "Error while instrumenting path/to/class" with JDK17
- maven-bundle-plugin -> 5.1.1, resolves java.util.ConcurrentModificationException [FELIX-6259] with JDK17
- blockhound-junit-platform -> 1.0.8.RELEASE, earlier version did not pick up -XX:+AllowRedefinitionToAddDeleteMethods properly

Jenkinsfile:
- Add matrix axis for JABBER_VERSION for each of JDK8, JDK11, JDK17
- Always run maven with JDK8, use testJavaHome to set JDK version for testing
  • Loading branch information
hhughes committed Jun 30, 2023
1 parent cd5af3a commit 1bb721d
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 25 deletions.
46 changes: 37 additions & 9 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,40 @@ def initializeEnvironment() {

env.MAVEN_HOME = "${env.HOME}/.mvn/apache-maven-3.3.9"
env.PATH = "${env.MAVEN_HOME}/bin:${env.PATH}"

/*
* As of JAVA-3042 JAVA_HOME is always set to JDK8 and this is currently necessary for mvn compile and DSE Search/Graph.
* To facilitate testing with JDK11/17 we feed the appropriate JAVA_HOME into the maven build via commandline.
*
* Maven command-line flags:
* - -DtestJavaHome=/path/to/java/home: overrides JAVA_HOME for surefire/failsafe tests, defaults to environment JAVA_HOME.
* - -Ptest-jdk-N: enables profile for running tests with a specific JDK version (substitute N for 8/11/17).
*
* Note test-jdk-N is also automatically loaded based off JAVA_HOME SDK version so testing with an older SDK is not supported.
*
* Environment variables:
* - JAVA_HOME: Path to JDK used for mvn (all steps except surefire/failsafe), Cassandra, DSE.
* - JAVA8_HOME: Path to JDK8 used for Cassandra/DSE if ccm determines JAVA_HOME is not compatible with the chosen backend.
* - TEST_JAVA_HOME: PATH to JDK used for surefire/failsafe testing.
* - TEST_JAVA_VERSION: TEST_JAVA_HOME SDK version number [8/11/17], used to configure test-jdk-N profile in maven (see above)
*/

env.JAVA_HOME = sh(label: 'Get JAVA_HOME',script: '''#!/bin/bash -le
. ${JABBA_SHELL}
jabba which ${JABBA_VERSION}''', returnStdout: true).trim()
env.JAVA8_HOME = sh(label: 'Get JAVA8_HOME',script: '''#!/bin/bash -le
. ${JABBA_SHELL}
jabba which 1.8''', returnStdout: true).trim()

env.TEST_JAVA_HOME = sh(label: 'Get TEST_JAVA_HOME',script: '''#!/bin/bash -le
. ${JABBA_SHELL}
jabba which ${JABBA_VERSION}''', returnStdout: true).trim()
env.TEST_JAVA_VERSION = sh(label: 'Get TEST_JAVA_VERSION',script: '''#!/bin/bash -le
echo "${JABBA_VERSION##*.}"''', returnStdout: true).trim()

sh label: 'Download Apache CassandraⓇ or DataStax Enterprise',script: '''#!/bin/bash -le
. ${JABBA_SHELL}
jabba use ${JABBA_VERSION}
jabba use 1.8
. ${CCM_ENVIRONMENT_SHELL} ${SERVER_VERSION}
'''

Expand All @@ -53,7 +77,7 @@ ENVIRONMENT_EOF
set +o allexport
. ${JABBA_SHELL}
jabba use ${JABBA_VERSION}
jabba use 1.8
java -version
mvn -v
Expand All @@ -80,7 +104,7 @@ def executeTests() {
set +o allexport
. ${JABBA_SHELL}
jabba use ${JABBA_VERSION}
jabba use 1.8
if [ "${JABBA_VERSION}" != "1.8" ]; then
SKIP_JAVADOCS=true
Expand All @@ -94,7 +118,9 @@ def executeTests() {
fi
printenv | sort
mvn -B -V ${INTEGRATION_TESTS_FILTER_ARGUMENT} verify \
mvn -B -V ${INTEGRATION_TESTS_FILTER_ARGUMENT} -T 1 verify \
-Ptest-jdk-${TEST_JAVA_VERSION} \
-DtestJavaHome=${TEST_JAVA_HOME} \
-DfailIfNoTests=false \
-Dmaven.test.failure.ignore=true \
-Dmaven.javadoc.skip=${SKIP_JAVADOCS} \
Expand Down Expand Up @@ -403,15 +429,17 @@ pipeline {
'4.0', // Development Apache CassandraⓇ
'dse-6.8.30' // Current DataStax Enterprise
}
axis {
name 'JABBA_VERSION'
values '1.8', // jdk8
'openjdk@1.11', // jdk11
'openjdk@1.17' // jdk17
}
}

agent {
label "${OS_VERSION}"
}
environment {
// Per-commit builds are only going to run against JDK8
JABBA_VERSION = '1.8'
}

stages {
stage('Initialize-Environment') {
Expand All @@ -431,7 +459,7 @@ pipeline {
}
stage('Build-Driver') {
steps {
buildDriver(env.JABBA_VERSION)
buildDriver('default')
}
}
stage('Execute-Tests') {
Expand Down
2 changes: 2 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<jvm>${testing.jvm}/bin/java</jvm>
<argLine>${mockitoopens.argline}</argLine>
<threadCount>1</threadCount>
<properties>
<property>
Expand Down
15 changes: 3 additions & 12 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
<goal>integration-test</goal>
</goals>
<configuration>
<jvm>${testing.jvm}/bin/java</jvm>
<groups>com.datastax.oss.driver.categories.ParallelizableTests</groups>
<parallel>classes</parallel>
<threadCountClasses>8</threadCountClasses>
Expand All @@ -245,6 +246,7 @@
<excludedGroups>com.datastax.oss.driver.categories.ParallelizableTests, com.datastax.oss.driver.categories.IsolatedTests</excludedGroups>
<summaryFile>${project.build.directory}/failsafe-reports/failsafe-summary-serial.xml</summaryFile>
<skipITs>${skipSerialITs}</skipITs>
<jvm>${testing.jvm}/bin/java</jvm>
</configuration>
</execution>
<execution>
Expand All @@ -260,6 +262,7 @@
<summaryFile>${project.build.directory}/failsafe-reports/failsafe-summary-isolated.xml</summaryFile>
<skipITs>${skipIsolatedITs}</skipITs>
<argLine>${blockhound.argline}</argLine>
<jvm>${testing.jvm}/bin/java</jvm>
</configuration>
</execution>
<execution>
Expand Down Expand Up @@ -322,16 +325,4 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jdk 13+</id>
<activation>
<jdk>[13,)</jdk>
</activation>
<properties>
<!-- for DriverBlockHoundIntegrationIT when using JDK 13+, see https://github.com/reactor/BlockHound/issues/33 -->
<blockhound.argline>-XX:+AllowRedefinitionToAddDeleteMethods</blockhound.argline>
</properties>
</profile>
</profiles>
</project>
1 change: 1 addition & 0 deletions mapper-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<jvm>${testing.jvm}/bin/java</jvm>
<threadCount>1</threadCount>
<properties>
<!-- tell TestNG not to run jUnit tests -->
Expand Down
2 changes: 2 additions & 0 deletions osgi-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<jvm>${testing.jvm}/bin/java</jvm>
<systemPropertyVariables>
<logback.configurationFile>${project.basedir}/src/test/resources/logback-test.xml</logback.configurationFile>
</systemPropertyVariables>
Expand All @@ -237,6 +238,7 @@
</execution>
</executions>
<configuration>
<jvm>${testing.jvm}/bin/java</jvm>
<systemPropertyVariables>
<logback.configurationFile>${project.basedir}/src/test/resources/logback-test.xml</logback.configurationFile>
</systemPropertyVariables>
Expand Down
59 changes: 55 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,12 @@
<dependency>
<groupId>io.projectreactor.tools</groupId>
<artifactId>blockhound</artifactId>
<version>1.0.4.RELEASE</version>
<version>1.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>io.projectreactor.tools</groupId>
<artifactId>blockhound-junit-platform</artifactId>
<version>1.0.4.RELEASE</version>
<version>1.0.8.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down Expand Up @@ -533,12 +533,12 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<version>0.8.10</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>4.2.1</version>
<version>5.1.1</version>
</plugin>
<plugin>
<groupId>org.revapi</groupId>
Expand Down Expand Up @@ -936,6 +936,57 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<revapi.skip>true</revapi.skip>
</properties>
</profile>
<!-- Use $JAVA_HOME as the default JDK to run surefire/failsafe to maintain portability -->
<profile>
<id>test-jdk-environment</id>
<activation>
<property>
<name>!testJavaHome</name>
</property>
</activation>
<properties>
<testing.jvm>${env.JAVA_HOME}</testing.jvm>
</properties>
</profile>
<!-- set -DtestJavaHome=/path/to/jdk/home to use a different JDK for surefire/failsafe -->
<profile>
<id>test-jdk-specified</id>
<activation>
<property>
<name>testJavaHome</name>
</property>
</activation>
<properties>
<testing.jvm>${testJavaHome}</testing.jvm>
</properties>
</profile>
<profile>
<!-- workarounds for running tests with JDK1.8 -->
<id>test-jdk-8</id>
<activation>
<jdk>[8,)</jdk>
</activation>
</profile>
<profile>
<!-- workarounds for running tests with JDK11 -->
<id>test-jdk-11</id>
<activation>
<jdk>[11,)</jdk>
</activation>
</profile>
<profile>
<!-- workarounds for running tests with JDK17 -->
<id>test-jdk-17</id>
<activation>
<jdk>[17,)</jdk>
</activation>
<properties>
<!-- for DriverBlockHoundIntegrationIT when using JDK 13+, see https://github.com/reactor/BlockHound/issues/33 -->
<blockhound.argline>-XX:+AllowRedefinitionToAddDeleteMethods</blockhound.argline>
<!-- allow deep reflection for mockito when using JDK 17+, see https://stackoverflow.com/questions/70993863/mockito-can-not-mock-random-in-java-17 -->
<mockitoopens.argline>--add-opens java.base/jdk.internal.util.random=ALL-UNNAMED</mockitoopens.argline>
</properties>
</profile>
</profiles>
<distributionManagement>
<repository>
Expand Down

0 comments on commit 1bb721d

Please sign in to comment.