Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test on Java 21 #1326

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions .evergreen/.evg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,10 @@ axes:
- id: jdk
display_name: JDK
values:
- id: "jdk21"
display_name: JDK21
variables:
JAVA_VERSION: "21"
- id: "jdk17"
display_name: JDK17
variables:
Expand Down Expand Up @@ -2037,7 +2041,8 @@ buildvariants:
- name: "test"

- matrix_name: "tests-jdk-secure"
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" ],
matrix_spec: { auth: "auth", ssl: "ssl", jdk: [ "jdk8", "jdk17", "jdk21"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of MongoDBs green sustainability drive we should review how much resources the matrix takes up and if we can keep coverage without duplicating testing. I'll open a ticket.

version: [ "3.6", "4.0", "4.2", "4.4", "5.0", "6.0", "7.0", "latest" ],
topology: "*", os: "linux" }
display_name: "${version} ${topology} ${auth} ${ssl} ${jdk} ${os} "
tags: ["tests-variant"]
Expand All @@ -2052,26 +2057,28 @@ buildvariants:
- name: "test"

- matrix_name: "tests-require-api-version"
matrix_spec: { api-version: "required", auth: "auth", ssl: "nossl", jdk: ["jdk17"], version: ["5.0", "6.0", "7.0", "latest"], topology: "standalone", os: "linux" }
matrix_spec: { api-version: "required", auth: "auth", ssl: "nossl", jdk: ["jdk21"], version: ["5.0", "6.0", "7.0", "latest"],
topology: "standalone", os: "linux" }
display_name: "${version} ${topology} ${api-version} "
tags: ["tests-variant"]
tasks:
- name: "test"

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

- matrix_name: "tests-serverless"
matrix_spec: { jdk: ["jdk17"], os: "ubuntu" }
matrix_spec: { jdk: ["jdk21"], os: "ubuntu" }
display_name: "Serverless"
tasks:
- name: "serverless-test"

- matrix_name: "tests-slow"
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: "jdk17", version: ["7.0"], topology: "standalone", os: "linux" }
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: "jdk21", version: ["7.0"], topology: "standalone", os: "linux" }
display_name: "Slow: ${version} ${topology} ${ssl} ${jdk} ${os} "
tags: ["tests-slow-variant"]
tasks:
Expand Down Expand Up @@ -2113,7 +2120,7 @@ buildvariants:
- name: "socket-test"

- matrix_name: "test-gssapi"
matrix_spec: { jdk: ["jdk8", "jdk17"], os: "linux", gssapi-login-context-name: "*"}
matrix_spec: { jdk: ["jdk8", "jdk17", "jdk21"], os: "linux", gssapi-login-context-name: "*"}
display_name: "GSSAPI (Kerberos) Auth test ${jdk} ${os} ${gssapi-login-context-name}"
tags: ["test-gssapi-variant"]
tasks:
Expand Down Expand Up @@ -2145,15 +2152,15 @@ buildvariants:
- name: "test_atlas_task_group_search_indexes"

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

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

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

- matrix_name: "ocsp-test"
matrix_spec: { auth: "noauth", ssl: "ssl", jdk: "jdk17", version: ["4.4", "5.0", "6.0", "7.0", "latest"], os: "ubuntu" }
matrix_spec: { auth: "noauth", ssl: "ssl", jdk: "jdk21", version: ["4.4", "5.0", "6.0", "7.0", "latest"], os: "ubuntu" }
display_name: "OCSP test ${version} ${os}"
tasks:
- name: ".ocsp"
Expand Down Expand Up @@ -2201,14 +2208,15 @@ buildvariants:
- name: "reactive-streams-tck-test"

- matrix_name: "scala-tests"
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: "jdk17", version: ["7.0"], topology: "replicaset", scala: "*", os: "ubuntu" }
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: ["jdk8", "jdk17", "jdk21"], version: ["7.0"], topology: "replicaset",
scala: "*", os: "ubuntu" }
display_name: "${scala} ${version} ${topology} ${os}"
tags: ["test-scala-variant"]
tasks:
- name: "scala-tests"

- matrix_name: "kotlin-tests"
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: ["jdk8", "jdk17"], version: ["7.0"], topology: "replicaset", os: "ubuntu" }
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: ["jdk8", "jdk17", "jdk21"], version: ["7.0"], topology: "replicaset", os: "ubuntu" }
display_name: "Kotlin: ${jdk} ${version} ${topology} ${os}"
tags: ["test-kotlin-variant"]
tasks:
Expand Down
1 change: 1 addition & 0 deletions .evergreen/javaConfig.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export JDK8="/opt/java/jdk8"
export JDK11="/opt/java/jdk11"
export JDK17="/opt/java/jdk17"
export JDK21="/opt/java/jdk21"

if [ -d "$JDK17" ]; then
export JAVA_HOME=$JDK17
Expand Down
3 changes: 2 additions & 1 deletion .evergreen/run-scala-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ fi
echo "Running scala tests with Scala $SCALA"

./gradlew -version
./gradlew -PscalaVersion=$SCALA --stacktrace --info scalaCheck -Dorg.mongodb.test.uri=${MONGODB_URI} ${MULTI_MONGOS_URI_SYSTEM_PROPERTY}
./gradlew -PjavaVersion=${JAVA_VERSION} -PscalaVersion=$SCALA --stacktrace --info scalaCheck \
-Dorg.mongodb.test.uri=${MONGODB_URI} ${MULTI_MONGOS_URI_SYSTEM_PROPERTY}
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,12 @@ configure(javaCodeCheckedProjects) {
testImplementation platform('org.spockframework:spock-bom:2.1-groovy-3.0')
testImplementation 'org.spockframework:spock-core'
testImplementation 'org.spockframework:spock-junit4'
testImplementation("org.mockito:mockito-core:3.8.0")
testImplementation("org.mockito:mockito-inline:3.8.0")
if ('8'.equals(findProperty("javaVersion"))) {
testImplementation("org.mockito:mockito-core:4.6.1")
testImplementation("org.mockito:mockito-inline:4.6.1")
jyemin marked this conversation as resolved.
Show resolved Hide resolved
} else {
testImplementation("org.mockito:mockito-core:5.11.0")
}
testImplementation 'cglib:cglib-nodep:2.2.2'
testImplementation 'org.objenesis:objenesis:1.3'
testImplementation 'org.hamcrest:hamcrest-all:1.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ class SocketStreamHelperSpecification extends Specification {

// If the Java 11+ extended socket options for keep alive probes are available, check those values.
if (Arrays.stream(ExtendedSocketOptions.getDeclaredFields()).anyMatch{ f -> f.getName().equals('TCP_KEEPCOUNT') }) {
Method getOptionMethod = Socket.getMethod('getOption', SocketOption)
getOptionMethod.invoke(socket, ExtendedSocketOptions.getDeclaredField('TCP_KEEPCOUNT').get(null)) == 9
getOptionMethod.invoke(socket, ExtendedSocketOptions.getDeclaredField('TCP_KEEPIDLE').get(null)) == 120
getOptionMethod.invoke(socket, ExtendedSocketOptions.getDeclaredField('TCP_KEEPINTERVAL').get(null)) == 10
Method getOptionMethod
try {
getOptionMethod = Socket.getMethod('getOption', SocketOption)
} catch (NoSuchMethodException e) {
// ignore, the `Socket.getOption` method was added in Java SE 9 and does not exist in Java SE 8
getOptionMethod = null
}
Comment on lines 56 to +64
Copy link
Member Author

@stIncMale stIncMale Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code assumed that if ExtendedSocketOptions.TCP_KEEPCOUNT is available, then so is Socket.getOption. That's not actually the case:

  1. ExtendedSocketOptions.TCP_KEEPCOUNT (not part of the Java SE) was added in Oracle JDK 81 (this is not part of the Java SE API, so it does not have to be in all JDKs): https://docs.oracle.com/javase/8/docs/jre/api/net/socketoptions/spec/jdk/net/ExtendedSocketOptions.html#TCP_KEEPCOUNT
  2. Socket.getOption was added in the Java SE 9.
  3. So when I run sdk use java 17.0.10-librca && ./gradlew -PjavaVersion=8 clean :driver-core:test locally, ExtendedSocketOptions.TCP_KEEPCOUNT is present, while Socket.getOption is not, which leads to a failure.
  4. Why is this not a problem in Evergreen? My guess is that the JDK 8 it uses does not have ExtendedSocketOptions.TCP_KEEPCOUNT.

1 Currently, Oracle mistakenly documents it as added in JDK 11, see https://docs.oracle.com/en/java/javase/21/docs/api/jdk.net/jdk/net/ExtendedSocketOptions.html#TCP_KEEPCOUNT.

if (getOptionMethod != null) {
getOptionMethod.invoke(socket, ExtendedSocketOptions.getDeclaredField('TCP_KEEPCOUNT').get(null)) == 9
getOptionMethod.invoke(socket, ExtendedSocketOptions.getDeclaredField('TCP_KEEPIDLE').get(null)) == 120
getOptionMethod.invoke(socket, ExtendedSocketOptions.getDeclaredField('TCP_KEEPINTERVAL').get(null)) == 10
}
}

cleanup:
Expand Down
7 changes: 6 additions & 1 deletion driver-reactive-streams/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ dependencies {
testImplementation project(':driver-core').sourceSets.test.output
testImplementation 'org.reactivestreams:reactive-streams-tck:1.0.4'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.mockito:mockito-junit-jupiter:3.5.13'
if ('8'.equals(findProperty("javaVersion"))) {
testImplementation 'org.mockito:mockito-junit-jupiter:4.6.1'
} else {
testImplementation 'org.mockito:mockito-junit-jupiter:5.11.0'
}

testRuntimeOnly project(path: ':driver-core', configuration: 'consumableTestRuntimeOnly')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object TestMongoClientHelper {

val mongoClientURI: String = {
val uri = Properties.propOrElse(MONGODB_URI_SYSTEM_PROPERTY_NAME, DEFAULT_URI)
if (!uri.isBlank) uri else DEFAULT_URI
if (!uri.codePoints().allMatch((cp: Int) => Character.isWhitespace(cp))) uri else DEFAULT_URI
Copy link
Member Author

@stIncMale stIncMale Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String.isBlank was added in Java SE 11, so when I run sdk use java 17.0.10-librca && ./gradlew -PjavaVersion=8 clean :driver-scala:integrationTest locally, it fails.

The are two reasons this hasn't been a problem in Evergreen:

  1. run-tests.sh did not run the integrationTest task (the test task does not depend on integrationTest). Update: I still does not run the integrationTest task because I rolled the related change back: the tests weren't running correctly when run by run-tests.sh, and on top of that @jyemin suggested to roll the change back.
  2. run-scala-tests.sh did not use JAVA_VERSION. So, despite this script running integrationTest implicitly, it was using the same JDK Gradle is run by.

}
val connectionString: ConnectionString = ConnectionString(mongoClientURI)

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ scalaVersions=2.11.12,2.12.15,2.13.6
defaultScalaVersions=2.13.6
runOnceTasks=clean,release
org.gradle.java.installations.auto-download=false
org.gradle.java.installations.fromEnv=JDK8,JDK11,JDK17
org.gradle.java.installations.fromEnv=JDK8,JDK11,JDK17,JDK21