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

Test on Java 21 #1326

merged 2 commits into from
Mar 5, 2024

Conversation

stIncMale
Copy link
Member

@stIncMale stIncMale commented Mar 4, 2024

This PR builds up on #1242.

  • 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

@stIncMale stIncMale self-assigned this Mar 4, 2024
@stIncMale stIncMale force-pushed the JAVA-5164 branch 2 times, most recently from 25961ac to b03aadd Compare March 4, 2024 22:14
@stIncMale stIncMale requested review from rozza and jyemin March 4, 2024 22:15
Comment on lines 56 to +64
// 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
}
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.

@@ -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.

* 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`
* Update `run-tests.sh` to run the `integrationTest` task (some Scala tests, like `ClientSideEncryptionBypassAutoEncryptionSpec` were not run by it)
* Fix test code that assumed Java SE 9+

JAVA-5164

---------

Co-authored-by: Jeff Yemin <jeff.yemin@mongodb.com>
.evergreen/run-tests.sh Outdated Show resolved Hide resolved
build.gradle Show resolved Hide resolved
@stIncMale stIncMale marked this pull request as ready for review March 4, 2024 23:41
@stIncMale stIncMale requested a review from jyemin March 4, 2024 23:41
Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -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.

@stIncMale stIncMale merged commit 0608f86 into mongodb:master Mar 5, 2024
239 checks passed
@stIncMale stIncMale deleted the JAVA-5164 branch March 5, 2024 16:03
@rozza rozza mentioned this pull request Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants