Skip to content

Commit 0608f86

Browse files
stIncMalejyemin
andauthored
Test on Java 21 (#1326)
* Add JDK 21 to Gradle configuration * Add JDK 21 to the test matrix * Replace JDK 17 with JDK 21 for tasks that are ony run using latest JDK * Update dependencies (some now have to be conditional) * Update `run-scala-tests.sh` to use `JAVA_VERSION` * Run the `scala-tests` task with JDK 8, 17, 21 similarly to `kotlin-tests` * Fix test code that assumed Java SE 9+ JAVA-5164 --------- Co-authored-by: Jeff Yemin <[email protected]>
1 parent 4120e6b commit 0608f86

File tree

8 files changed

+49
-22
lines changed

8 files changed

+49
-22
lines changed

.evergreen/.evg.yml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,10 @@ axes:
17891789
- id: jdk
17901790
display_name: JDK
17911791
values:
1792+
- id: "jdk21"
1793+
display_name: JDK21
1794+
variables:
1795+
JAVA_VERSION: "21"
17921796
- id: "jdk17"
17931797
display_name: JDK17
17941798
variables:
@@ -2037,7 +2041,8 @@ buildvariants:
20372041
- name: "test"
20382042

20392043
- matrix_name: "tests-jdk-secure"
2040-
matrix_spec: { auth: "auth", ssl: "ssl", jdk: [ "jdk8", "jdk17" ], version: [ "3.6", "4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "latest" ],
2044+
matrix_spec: { auth: "auth", ssl: "ssl", jdk: [ "jdk8", "jdk17", "jdk21"],
2045+
version: [ "3.6", "4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "latest" ],
20412046
topology: "*", os: "linux" }
20422047
display_name: "${version} ${topology} ${auth} ${ssl} ${jdk} ${os} "
20432048
tags: ["tests-variant"]
@@ -2052,26 +2057,28 @@ buildvariants:
20522057
- name: "test"
20532058

20542059
- matrix_name: "tests-require-api-version"
2055-
matrix_spec: { api-version: "required", auth: "auth", ssl: "nossl", jdk: ["jdk17"], version: ["5.0", "6.0", "7.0", "latest"], topology: "standalone", os: "linux" }
2060+
matrix_spec: { api-version: "required", auth: "auth", ssl: "nossl", jdk: ["jdk21"], version: ["5.0", "6.0", "7.0", "latest"],
2061+
topology: "standalone", os: "linux" }
20562062
display_name: "${version} ${topology} ${api-version} "
20572063
tags: ["tests-variant"]
20582064
tasks:
20592065
- name: "test"
20602066

20612067
- matrix_name: "tests-load-balancer-secure"
2062-
matrix_spec: { auth: "auth", ssl: "ssl", jdk: ["jdk17"], version: ["5.0", "6.0", "7.0", "latest"], topology: "sharded-cluster", os: "ubuntu" }
2068+
matrix_spec: { auth: "auth", ssl: "ssl", jdk: ["jdk21"], version: ["5.0", "6.0", "7.0", "latest"], topology: "sharded-cluster",
2069+
os: "ubuntu" }
20632070
display_name: "Load Balancer ${version} ${auth} ${ssl} ${jdk} ${os}"
20642071
tasks:
20652072
- name: "load-balancer-test"
20662073

20672074
- matrix_name: "tests-serverless"
2068-
matrix_spec: { jdk: ["jdk17"], os: "ubuntu" }
2075+
matrix_spec: { jdk: ["jdk21"], os: "ubuntu" }
20692076
display_name: "Serverless"
20702077
tasks:
20712078
- name: "serverless-test"
20722079

20732080
- matrix_name: "tests-slow"
2074-
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: "jdk17", version: ["7.0"], topology: "standalone", os: "linux" }
2081+
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: "jdk21", version: ["7.0"], topology: "standalone", os: "linux" }
20752082
display_name: "Slow: ${version} ${topology} ${ssl} ${jdk} ${os} "
20762083
tags: ["tests-slow-variant"]
20772084
tasks:
@@ -2113,7 +2120,7 @@ buildvariants:
21132120
- name: "socket-test"
21142121

21152122
- matrix_name: "test-gssapi"
2116-
matrix_spec: { jdk: ["jdk8", "jdk17"], os: "linux", gssapi-login-context-name: "*"}
2123+
matrix_spec: { jdk: ["jdk8", "jdk17", "jdk21"], os: "linux", gssapi-login-context-name: "*"}
21172124
display_name: "GSSAPI (Kerberos) Auth test ${jdk} ${os} ${gssapi-login-context-name}"
21182125
tags: ["test-gssapi-variant"]
21192126
tasks:
@@ -2145,15 +2152,15 @@ buildvariants:
21452152
- name: "test_atlas_task_group_search_indexes"
21462153

21472154
- matrix_name: "aws-auth-test"
2148-
matrix_spec: { ssl: "nossl", jdk: ["jdk8", "jdk17"], version: ["4.4", "5.0", "6.0", "7.0", "latest"], os: "ubuntu",
2155+
matrix_spec: { ssl: "nossl", jdk: ["jdk8", "jdk17", "jdk21"], version: ["4.4", "5.0", "6.0", "7.0", "latest"], os: "ubuntu",
21492156
aws-credential-provider: "*" }
21502157
display_name: "MONGODB-AWS Basic Auth test ${version} ${jdk} ${aws-credential-provider}"
21512158
run_on: ubuntu2004-small
21522159
tasks:
21532160
- name: "aws-auth-test-with-regular-aws-credentials"
21542161

21552162
- matrix_name: "aws-ec2-auth-test"
2156-
matrix_spec: { ssl: "nossl", jdk: ["jdk17"], version: ["7.0"], os: "ubuntu", aws-credential-provider: "*" }
2163+
matrix_spec: { ssl: "nossl", jdk: ["jdk21"], version: ["7.0"], os: "ubuntu", aws-credential-provider: "*" }
21572164
display_name: "MONGODB-AWS Advanced Auth test ${version} ${jdk} ${aws-credential-provider}"
21582165
run_on: ubuntu2004-small
21592166
tasks:
@@ -2164,14 +2171,14 @@ buildvariants:
21642171
- name: "aws-auth-test-with-web-identity-credentials"
21652172

21662173
- matrix_name: "accept-api-version-2-test"
2167-
matrix_spec: { ssl: "nossl", auth: "noauth", jdk: "jdk17", version: ["5.0", "6.0", "7.0", "latest"], topology: "standalone", os: "linux" }
2174+
matrix_spec: { ssl: "nossl", auth: "noauth", jdk: "jdk21", version: ["5.0", "6.0", "7.0", "latest"], topology: "standalone", os: "linux" }
21682175
display_name: "Accept API Version 2 ${version}"
21692176
run_on: ubuntu2004-small
21702177
tasks:
21712178
- name: "accept-api-version-2-test"
21722179

21732180
- matrix_name: "ocsp-test"
2174-
matrix_spec: { auth: "noauth", ssl: "ssl", jdk: "jdk17", version: ["4.4", "5.0", "6.0", "7.0", "latest"], os: "ubuntu" }
2181+
matrix_spec: { auth: "noauth", ssl: "ssl", jdk: "jdk21", version: ["4.4", "5.0", "6.0", "7.0", "latest"], os: "ubuntu" }
21752182
display_name: "OCSP test ${version} ${os}"
21762183
tasks:
21772184
- name: ".ocsp"
@@ -2201,14 +2208,15 @@ buildvariants:
22012208
- name: "reactive-streams-tck-test"
22022209

22032210
- matrix_name: "scala-tests"
2204-
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: "jdk17", version: ["7.0"], topology: "replicaset", scala: "*", os: "ubuntu" }
2211+
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: ["jdk8", "jdk17", "jdk21"], version: ["7.0"], topology: "replicaset",
2212+
scala: "*", os: "ubuntu" }
22052213
display_name: "${scala} ${version} ${topology} ${os}"
22062214
tags: ["test-scala-variant"]
22072215
tasks:
22082216
- name: "scala-tests"
22092217

22102218
- matrix_name: "kotlin-tests"
2211-
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: ["jdk8", "jdk17"], version: ["7.0"], topology: "replicaset", os: "ubuntu" }
2219+
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: ["jdk8", "jdk17", "jdk21"], version: ["7.0"], topology: "replicaset", os: "ubuntu" }
22122220
display_name: "Kotlin: ${jdk} ${version} ${topology} ${os}"
22132221
tags: ["test-kotlin-variant"]
22142222
tasks:

.evergreen/javaConfig.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export JDK8="/opt/java/jdk8"
44
export JDK11="/opt/java/jdk11"
55
export JDK17="/opt/java/jdk17"
6+
export JDK21="/opt/java/jdk21"
67

78
if [ -d "$JDK17" ]; then
89
export JAVA_HOME=$JDK17

.evergreen/run-scala-tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ fi
3434
echo "Running scala tests with Scala $SCALA"
3535

3636
./gradlew -version
37-
./gradlew -PscalaVersion=$SCALA --stacktrace --info scalaCheck -Dorg.mongodb.test.uri=${MONGODB_URI} ${MULTI_MONGOS_URI_SYSTEM_PROPERTY}
37+
./gradlew -PjavaVersion=${JAVA_VERSION} -PscalaVersion=$SCALA --stacktrace --info scalaCheck \
38+
-Dorg.mongodb.test.uri=${MONGODB_URI} ${MULTI_MONGOS_URI_SYSTEM_PROPERTY}

build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,12 @@ configure(javaCodeCheckedProjects) {
256256
testImplementation platform('org.spockframework:spock-bom:2.1-groovy-3.0')
257257
testImplementation 'org.spockframework:spock-core'
258258
testImplementation 'org.spockframework:spock-junit4'
259-
testImplementation("org.mockito:mockito-core:3.8.0")
260-
testImplementation("org.mockito:mockito-inline:3.8.0")
259+
if ('8'.equals(findProperty("javaVersion"))) {
260+
testImplementation("org.mockito:mockito-core:4.6.1")
261+
testImplementation("org.mockito:mockito-inline:4.6.1")
262+
} else {
263+
testImplementation("org.mockito:mockito-core:5.11.0")
264+
}
261265
testImplementation 'cglib:cglib-nodep:2.2.2'
262266
testImplementation 'org.objenesis:objenesis:1.3'
263267
testImplementation 'org.hamcrest:hamcrest-all:1.3'

driver-core/src/test/functional/com/mongodb/internal/connection/SocketStreamHelperSpecification.groovy

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,18 @@ class SocketStreamHelperSpecification extends Specification {
5555
5656
// If the Java 11+ extended socket options for keep alive probes are available, check those values.
5757
if (Arrays.stream(ExtendedSocketOptions.getDeclaredFields()).anyMatch{ f -> f.getName().equals('TCP_KEEPCOUNT') }) {
58-
Method getOptionMethod = Socket.getMethod('getOption', SocketOption)
59-
getOptionMethod.invoke(socket, ExtendedSocketOptions.getDeclaredField('TCP_KEEPCOUNT').get(null)) == 9
60-
getOptionMethod.invoke(socket, ExtendedSocketOptions.getDeclaredField('TCP_KEEPIDLE').get(null)) == 120
61-
getOptionMethod.invoke(socket, ExtendedSocketOptions.getDeclaredField('TCP_KEEPINTERVAL').get(null)) == 10
58+
Method getOptionMethod
59+
try {
60+
getOptionMethod = Socket.getMethod('getOption', SocketOption)
61+
} catch (NoSuchMethodException e) {
62+
// ignore, the `Socket.getOption` method was added in Java SE 9 and does not exist in Java SE 8
63+
getOptionMethod = null
64+
}
65+
if (getOptionMethod != null) {
66+
getOptionMethod.invoke(socket, ExtendedSocketOptions.getDeclaredField('TCP_KEEPCOUNT').get(null)) == 9
67+
getOptionMethod.invoke(socket, ExtendedSocketOptions.getDeclaredField('TCP_KEEPIDLE').get(null)) == 120
68+
getOptionMethod.invoke(socket, ExtendedSocketOptions.getDeclaredField('TCP_KEEPINTERVAL').get(null)) == 10
69+
}
6270
}
6371
6472
cleanup:

driver-reactive-streams/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ dependencies {
3131
testImplementation project(':driver-core').sourceSets.test.output
3232
testImplementation 'org.reactivestreams:reactive-streams-tck:1.0.4'
3333
testImplementation 'io.projectreactor:reactor-test'
34-
testImplementation 'org.mockito:mockito-junit-jupiter:3.5.13'
34+
if ('8'.equals(findProperty("javaVersion"))) {
35+
testImplementation 'org.mockito:mockito-junit-jupiter:4.6.1'
36+
} else {
37+
testImplementation 'org.mockito:mockito-junit-jupiter:5.11.0'
38+
}
39+
3540
testRuntimeOnly project(path: ':driver-core', configuration: 'consumableTestRuntimeOnly')
3641
}
3742

driver-scala/src/integration/scala/org/mongodb/scala/TestMongoClientHelper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ object TestMongoClientHelper {
2929

3030
val mongoClientURI: String = {
3131
val uri = Properties.propOrElse(MONGODB_URI_SYSTEM_PROPERTY_NAME, DEFAULT_URI)
32-
if (!uri.isBlank) uri else DEFAULT_URI
32+
if (!uri.codePoints().allMatch((cp: Int) => Character.isWhitespace(cp))) uri else DEFAULT_URI
3333
}
3434
val connectionString: ConnectionString = ConnectionString(mongoClientURI)
3535

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ scalaVersions=2.11.12,2.12.15,2.13.6
2020
defaultScalaVersions=2.13.6
2121
runOnceTasks=clean,release
2222
org.gradle.java.installations.auto-download=false
23-
org.gradle.java.installations.fromEnv=JDK8,JDK11,JDK17
23+
org.gradle.java.installations.fromEnv=JDK8,JDK11,JDK17,JDK21

0 commit comments

Comments
 (0)