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

Initial investigation of Java 21 spring boot 3 #295

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

pricem14pc
Copy link
Contributor

@pricem14pc pricem14pc commented Oct 14, 2024

What and why?

Initial sanity test of upgrading Java and Spring Boot

  • Upgrade to Java 21
  • Upgrade to Spring Boot 3

Outstanding Issues

The app now starts and successfully amd connects to Postgres and Pub/Sub. The app successfully deploys to GCP and acceptance tests all pass successfully.

For current progress/outstanding issues check the TODO: comments throughout for more details. In summary so far.

  • failsafe integration tests currently disabled due to the Spring test server rendering an internal server error HTTP response
{"error":
   {"code":"SYSTEM_ERROR",
    "timestamp":"20241101092339701",
    "message":"Could not write JSON: Class versions V1_5 or less must use F_NEW frames."}
}

We have to update WireMock from the legacy com.github.tomakehurst to the new org.wiremock library. This new hosted package has the original tomakehurst package classes bundled inside it. This means we don't need to update the various imports throughout as they've made usage backward compatible.

However, we see ReflectASM errors with the GoDaddy logging framework (only when using the new org.wiremock package, not the legacy com.github.tomakehurst package).

Class versions V1_5 or less must use F_NEW frames

The RefectASM and GoDaddy logging packages are both very old and no longer supported https://github.com/godaddy/godaddy-logger/blob/main/README.md#whats-included-in-this-library.

The errors themselves maybe because of the way they've bundled the original tomakehurst within the new wiremock library, and the reflection framework is unable to instrument the byte code correctly under Java 21.

we can run integration tests only with the following

mvn clean test-compile failsafe:integration-test -Dfailsafe.skipITs=false

or run unit tests only with the following

mvn clean install -Dfailsafe.skipITs=true -DskipTests=false

How to test?

  • Install Java 21 SDK locally (tested with temurin-21.0.4)
  • switch to Java 21 (add /Library/Java/JavaVirtualMachines/temurin-21.0.4/Contents/Home to local jenv versions and use jenv local 21)

Start Postgres and the Pub/Sub emulator

docker run -d --name pubsub-emulator -p 8681:8681 -e PUBSUB_PROJECT1=ras-rm-dev,test_case_creation_topic:test_case_creation_subscription,test_event_status_topic:test_event_status_subscription eu.gcr.io/ons-rasrmbs-management/pubsub-emulator
docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres -e POSTGRES_DB=ras -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14

Run the app natively with Maven

mvn spring-boot:run

Or just run the jar

java -jar target/case.jar

Build the image with Docker

docker build  --no-cache -t eu.gcr.io/ons-rasrmbs-management/case:java21 -f ./_infra/docker/Dockerfile .

In preparation to run the Docker image, authenticate your Google ADC (it's needed to connect to the Pub/Sub emulator) and ensure your key location is valid and check that your json creds file exists

gcloud auth application-default login
echo $GOOGLE_APPLICATION_CREDENTIALS
cat $GOOGLE_APPLICATION_CREDENTIALS

Test the case service image

docker network create case-network
docker run --name postgres --network=case-network \
     -p 6432:5432 \
     -e POSTGRES_PASSWORD=postgres \
     -e POSTGRES_USER=postgres \
     -e POSTGRES_DB=ras \
     -e POSTGRES_HOST_AUTH_METHOD=trust \
     -d postgres:14
docker run -d --name pubsub-emulator --network=case-network \
     -p 18681:8681 \
     -e PUBSUB_PROJECT1=ras-rm-dev,test_case_creation_topic:test_case_creation_subscription,test_event_status_topic:test_event_status_subscription eu.gcr.io/ons-rasrmbs-management/pubsub-emulator
docker run --name case-java21 --network=case-network \
     -e spring.datasource.url=jdbc:postgresql://postgres:5432/ras \
     -e spring.liquibase.url=jdbc:postgresql://postgres:5432/ras \
     -e GOOGLE_APPLICATION_CREDENTIALS=/tmp/keys/application_default_credentials.json \
     -v $GOOGLE_APPLICATION_CREDENTIALS:/tmp/keys/application_default_credentials.json:ro \
     eu.gcr.io/ons-rasrmbs-management/case:java21

Destroy the network

docker network rm case-network
docker rm -f $(docker ps -aq)
docker volume prune -f

@pricem14pc
Copy link
Contributor Author

/deploy pricem

@ras-rm-pr-bot
Copy link
Collaborator

Deploying to dev cluster with following parameters:

  • namespace: pricem

  • tag: pr-295

  • configBranch: main

  • paramKey: ``

  • paramValue: ``

<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<parameters>true</parameters>
Copy link
Contributor Author

@pricem14pc pricem14pc Oct 15, 2024

Choose a reason for hiding this comment

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

Required to fix failing CaseGroupEndpointUnitTest tests.

Error "Name for argument of type [java.util.UUID] not specified, and parameter name information not found in class file either"

with spring 3 upgrade when using org.springframework.test.web.servlet.MockMvc

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<failsafe.skipITs>true</failsafe.skipITs>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To allow me to control the tests during development. This will of course be false when delivered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants