Skip to content

Commit 1bb721d

Browse files
committed
JAVA-3042: Support testing against Java17
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
1 parent cd5af3a commit 1bb721d

File tree

6 files changed

+100
-25
lines changed

6 files changed

+100
-25
lines changed

Jenkinsfile

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,40 @@ def initializeEnvironment() {
1818

1919
env.MAVEN_HOME = "${env.HOME}/.mvn/apache-maven-3.3.9"
2020
env.PATH = "${env.MAVEN_HOME}/bin:${env.PATH}"
21+
22+
/*
23+
* As of JAVA-3042 JAVA_HOME is always set to JDK8 and this is currently necessary for mvn compile and DSE Search/Graph.
24+
* To facilitate testing with JDK11/17 we feed the appropriate JAVA_HOME into the maven build via commandline.
25+
*
26+
* Maven command-line flags:
27+
* - -DtestJavaHome=/path/to/java/home: overrides JAVA_HOME for surefire/failsafe tests, defaults to environment JAVA_HOME.
28+
* - -Ptest-jdk-N: enables profile for running tests with a specific JDK version (substitute N for 8/11/17).
29+
*
30+
* Note test-jdk-N is also automatically loaded based off JAVA_HOME SDK version so testing with an older SDK is not supported.
31+
*
32+
* Environment variables:
33+
* - JAVA_HOME: Path to JDK used for mvn (all steps except surefire/failsafe), Cassandra, DSE.
34+
* - JAVA8_HOME: Path to JDK8 used for Cassandra/DSE if ccm determines JAVA_HOME is not compatible with the chosen backend.
35+
* - TEST_JAVA_HOME: PATH to JDK used for surefire/failsafe testing.
36+
* - TEST_JAVA_VERSION: TEST_JAVA_HOME SDK version number [8/11/17], used to configure test-jdk-N profile in maven (see above)
37+
*/
38+
2139
env.JAVA_HOME = sh(label: 'Get JAVA_HOME',script: '''#!/bin/bash -le
2240
. ${JABBA_SHELL}
2341
jabba which ${JABBA_VERSION}''', returnStdout: true).trim()
2442
env.JAVA8_HOME = sh(label: 'Get JAVA8_HOME',script: '''#!/bin/bash -le
2543
. ${JABBA_SHELL}
2644
jabba which 1.8''', returnStdout: true).trim()
2745

46+
env.TEST_JAVA_HOME = sh(label: 'Get TEST_JAVA_HOME',script: '''#!/bin/bash -le
47+
. ${JABBA_SHELL}
48+
jabba which ${JABBA_VERSION}''', returnStdout: true).trim()
49+
env.TEST_JAVA_VERSION = sh(label: 'Get TEST_JAVA_VERSION',script: '''#!/bin/bash -le
50+
echo "${JABBA_VERSION##*.}"''', returnStdout: true).trim()
51+
2852
sh label: 'Download Apache CassandraⓇ or DataStax Enterprise',script: '''#!/bin/bash -le
2953
. ${JABBA_SHELL}
30-
jabba use ${JABBA_VERSION}
54+
jabba use 1.8
3155
. ${CCM_ENVIRONMENT_SHELL} ${SERVER_VERSION}
3256
'''
3357

@@ -53,7 +77,7 @@ ENVIRONMENT_EOF
5377
set +o allexport
5478
5579
. ${JABBA_SHELL}
56-
jabba use ${JABBA_VERSION}
80+
jabba use 1.8
5781
5882
java -version
5983
mvn -v
@@ -80,7 +104,7 @@ def executeTests() {
80104
set +o allexport
81105
82106
. ${JABBA_SHELL}
83-
jabba use ${JABBA_VERSION}
107+
jabba use 1.8
84108
85109
if [ "${JABBA_VERSION}" != "1.8" ]; then
86110
SKIP_JAVADOCS=true
@@ -94,7 +118,9 @@ def executeTests() {
94118
fi
95119
printenv | sort
96120
97-
mvn -B -V ${INTEGRATION_TESTS_FILTER_ARGUMENT} verify \
121+
mvn -B -V ${INTEGRATION_TESTS_FILTER_ARGUMENT} -T 1 verify \
122+
-Ptest-jdk-${TEST_JAVA_VERSION} \
123+
-DtestJavaHome=${TEST_JAVA_HOME} \
98124
-DfailIfNoTests=false \
99125
-Dmaven.test.failure.ignore=true \
100126
-Dmaven.javadoc.skip=${SKIP_JAVADOCS} \
@@ -403,15 +429,17 @@ pipeline {
403429
'4.0', // Development Apache CassandraⓇ
404430
'dse-6.8.30' // Current DataStax Enterprise
405431
}
432+
axis {
433+
name 'JABBA_VERSION'
434+
values '1.8', // jdk8
435+
'[email protected]', // jdk11
436+
'[email protected]' // jdk17
437+
}
406438
}
407439

408440
agent {
409441
label "${OS_VERSION}"
410442
}
411-
environment {
412-
// Per-commit builds are only going to run against JDK8
413-
JABBA_VERSION = '1.8'
414-
}
415443

416444
stages {
417445
stage('Initialize-Environment') {
@@ -431,7 +459,7 @@ pipeline {
431459
}
432460
stage('Build-Driver') {
433461
steps {
434-
buildDriver(env.JABBA_VERSION)
462+
buildDriver('default')
435463
}
436464
}
437465
stage('Execute-Tests') {

core/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@
248248
<plugin>
249249
<artifactId>maven-surefire-plugin</artifactId>
250250
<configuration>
251+
<jvm>${testing.jvm}/bin/java</jvm>
252+
<argLine>${mockitoopens.argline}</argLine>
251253
<threadCount>1</threadCount>
252254
<properties>
253255
<property>

integration-tests/pom.xml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
<goal>integration-test</goal>
230230
</goals>
231231
<configuration>
232+
<jvm>${testing.jvm}/bin/java</jvm>
232233
<groups>com.datastax.oss.driver.categories.ParallelizableTests</groups>
233234
<parallel>classes</parallel>
234235
<threadCountClasses>8</threadCountClasses>
@@ -245,6 +246,7 @@
245246
<excludedGroups>com.datastax.oss.driver.categories.ParallelizableTests, com.datastax.oss.driver.categories.IsolatedTests</excludedGroups>
246247
<summaryFile>${project.build.directory}/failsafe-reports/failsafe-summary-serial.xml</summaryFile>
247248
<skipITs>${skipSerialITs}</skipITs>
249+
<jvm>${testing.jvm}/bin/java</jvm>
248250
</configuration>
249251
</execution>
250252
<execution>
@@ -260,6 +262,7 @@
260262
<summaryFile>${project.build.directory}/failsafe-reports/failsafe-summary-isolated.xml</summaryFile>
261263
<skipITs>${skipIsolatedITs}</skipITs>
262264
<argLine>${blockhound.argline}</argLine>
265+
<jvm>${testing.jvm}/bin/java</jvm>
263266
</configuration>
264267
</execution>
265268
<execution>
@@ -322,16 +325,4 @@
322325
</plugin>
323326
</plugins>
324327
</build>
325-
<profiles>
326-
<profile>
327-
<id>jdk 13+</id>
328-
<activation>
329-
<jdk>[13,)</jdk>
330-
</activation>
331-
<properties>
332-
<!-- for DriverBlockHoundIntegrationIT when using JDK 13+, see https://github.com/reactor/BlockHound/issues/33 -->
333-
<blockhound.argline>-XX:+AllowRedefinitionToAddDeleteMethods</blockhound.argline>
334-
</properties>
335-
</profile>
336-
</profiles>
337328
</project>

mapper-runtime/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
<plugin>
123123
<artifactId>maven-surefire-plugin</artifactId>
124124
<configuration>
125+
<jvm>${testing.jvm}/bin/java</jvm>
125126
<threadCount>1</threadCount>
126127
<properties>
127128
<!-- tell TestNG not to run jUnit tests -->

osgi-tests/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
<plugin>
221221
<artifactId>maven-surefire-plugin</artifactId>
222222
<configuration>
223+
<jvm>${testing.jvm}/bin/java</jvm>
223224
<systemPropertyVariables>
224225
<logback.configurationFile>${project.basedir}/src/test/resources/logback-test.xml</logback.configurationFile>
225226
</systemPropertyVariables>
@@ -237,6 +238,7 @@
237238
</execution>
238239
</executions>
239240
<configuration>
241+
<jvm>${testing.jvm}/bin/java</jvm>
240242
<systemPropertyVariables>
241243
<logback.configurationFile>${project.basedir}/src/test/resources/logback-test.xml</logback.configurationFile>
242244
</systemPropertyVariables>

pom.xml

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,12 @@
433433
<dependency>
434434
<groupId>io.projectreactor.tools</groupId>
435435
<artifactId>blockhound</artifactId>
436-
<version>1.0.4.RELEASE</version>
436+
<version>1.0.8.RELEASE</version>
437437
</dependency>
438438
<dependency>
439439
<groupId>io.projectreactor.tools</groupId>
440440
<artifactId>blockhound-junit-platform</artifactId>
441-
<version>1.0.4.RELEASE</version>
441+
<version>1.0.8.RELEASE</version>
442442
</dependency>
443443
</dependencies>
444444
</dependencyManagement>
@@ -533,12 +533,12 @@
533533
<plugin>
534534
<groupId>org.jacoco</groupId>
535535
<artifactId>jacoco-maven-plugin</artifactId>
536-
<version>0.8.5</version>
536+
<version>0.8.10</version>
537537
</plugin>
538538
<plugin>
539539
<groupId>org.apache.felix</groupId>
540540
<artifactId>maven-bundle-plugin</artifactId>
541-
<version>4.2.1</version>
541+
<version>5.1.1</version>
542542
</plugin>
543543
<plugin>
544544
<groupId>org.revapi</groupId>
@@ -936,6 +936,57 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
936936
<revapi.skip>true</revapi.skip>
937937
</properties>
938938
</profile>
939+
<!-- Use $JAVA_HOME as the default JDK to run surefire/failsafe to maintain portability -->
940+
<profile>
941+
<id>test-jdk-environment</id>
942+
<activation>
943+
<property>
944+
<name>!testJavaHome</name>
945+
</property>
946+
</activation>
947+
<properties>
948+
<testing.jvm>${env.JAVA_HOME}</testing.jvm>
949+
</properties>
950+
</profile>
951+
<!-- set -DtestJavaHome=/path/to/jdk/home to use a different JDK for surefire/failsafe -->
952+
<profile>
953+
<id>test-jdk-specified</id>
954+
<activation>
955+
<property>
956+
<name>testJavaHome</name>
957+
</property>
958+
</activation>
959+
<properties>
960+
<testing.jvm>${testJavaHome}</testing.jvm>
961+
</properties>
962+
</profile>
963+
<profile>
964+
<!-- workarounds for running tests with JDK1.8 -->
965+
<id>test-jdk-8</id>
966+
<activation>
967+
<jdk>[8,)</jdk>
968+
</activation>
969+
</profile>
970+
<profile>
971+
<!-- workarounds for running tests with JDK11 -->
972+
<id>test-jdk-11</id>
973+
<activation>
974+
<jdk>[11,)</jdk>
975+
</activation>
976+
</profile>
977+
<profile>
978+
<!-- workarounds for running tests with JDK17 -->
979+
<id>test-jdk-17</id>
980+
<activation>
981+
<jdk>[17,)</jdk>
982+
</activation>
983+
<properties>
984+
<!-- for DriverBlockHoundIntegrationIT when using JDK 13+, see https://github.com/reactor/BlockHound/issues/33 -->
985+
<blockhound.argline>-XX:+AllowRedefinitionToAddDeleteMethods</blockhound.argline>
986+
<!-- allow deep reflection for mockito when using JDK 17+, see https://stackoverflow.com/questions/70993863/mockito-can-not-mock-random-in-java-17 -->
987+
<mockitoopens.argline>--add-opens java.base/jdk.internal.util.random=ALL-UNNAMED</mockitoopens.argline>
988+
</properties>
989+
</profile>
939990
</profiles>
940991
<distributionManagement>
941992
<repository>

0 commit comments

Comments
 (0)