From 294c8ad277f016373cb04b5d27457c70a9190300 Mon Sep 17 00:00:00 2001 From: SylvainJuge <763082+SylvainJuge@users.noreply.github.com> Date: Tue, 7 Nov 2023 11:04:05 +0100 Subject: [PATCH] jdk update reminder (#3410) * add time-based reminder test * add back jdk 21 for testing in CI * better testing and notification msg * remove jdk 21 * Revert "remove jdk 21" This reverts commit 874220e99c66d60cc8e260ef2666e44d95597b90. * set system property when running test * remove jdk 21 + trigger a bit later * Update apm-agent-core/src/test/java/co/elastic/apm/agent/util/JdkVersionTest.java Co-authored-by: jackshirazi --------- Co-authored-by: jackshirazi --- .github/workflows/main.yml | 6 +- .../apm/agent/util/JdkVersionTest.java | 92 +++++++++++++++++++ 2 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 apm-agent-core/src/test/java/co/elastic/apm/agent/util/JdkVersionTest.java diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d9ed0061a4..4574e507a3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -299,10 +299,10 @@ jobs: distribution: 'temurin' - version: 17 distribution: 'temurin' - - version: 22-ea - distribution: 'temurin' - version: 21 distribution: 'temurin' + - version: 22-ea + distribution: 'temurin' steps: - uses: actions/checkout@v4 - uses: ./.github/workflows/maven-goal @@ -311,7 +311,7 @@ jobs: test-java-distribution: ${{ matrix.distribution }} command: ./mvnw install -DskipTests=true -Dmaven.javadoc.skip=true - name: Run tests for ${{ matrix.version }}:${{ matrix.distribution }} - run: ./mvnw test -Dtest_java_binary=${{ env.TEST_JAVA_BINARY }} + run: ./mvnw test -Delastic.jdkCompatibilityTest=true -Dtest_java_binary=${{ env.TEST_JAVA_BINARY }} - name: Store test results if: success() || failure() uses: actions/upload-artifact@v3 diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/util/JdkVersionTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/util/JdkVersionTest.java new file mode 100644 index 0000000000..324ddf7014 --- /dev/null +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/util/JdkVersionTest.java @@ -0,0 +1,92 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.util; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.params.provider.Arguments; + +import java.time.LocalDate; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class JdkVersionTest { + + private static List releaseSchedule() { + // from https://www.oracle.com/java/technologies/java-se-support-roadmap.html + return List.of( + Arguments.of(22, LocalDate.parse("2024-04-01")), + Arguments.of(23, LocalDate.parse("2024-10-01")), + Arguments.of(24, LocalDate.parse("2025-04-01")), + Arguments.of(25, LocalDate.parse("2025-10-01")) + ); + } + + @Test + @EnabledIfSystemProperty(named = "elastic.jdkCompatibilityTest", matches = "true") + void jdkReleaseScheduleReminder() { + // not using @MethodSource and directly the arguments stream to ensure at least one is in the future + jdkReleaseScheduleReminder(releaseSchedule(), LocalDate.now()); + } + + void jdkReleaseScheduleReminder(List args, LocalDate now) { + + assertThat(args).isNotEmpty(); + + args.forEach(a -> jdkReleaseScheduleReminder((int) a.get()[0], (LocalDate) a.get()[1], now)); + } + + void jdkReleaseScheduleReminder(int version, LocalDate gaDate, LocalDate now) { + if (now.isBefore(gaDate)) { + return; + } + + assertThat(false) + .describedAs( + "This test fails to remind you that JDK %d is about or already released,\n\n" + + "please update the following:\n" + + "\n" + + "- .github/workflows/main.yml in 'jdk-compatibility-tests' : replace early-access with released GA version and add the new early-access version\n" + + "- in this test: remove released version in the release schedule\n" + + "- in this test: update release schedule if needed\n" + , version) + .isTrue(); + + } + + @Test + void selfTest() { + // verify that the test will fail in the future when we need to get reminded to update + + LocalDate now = LocalDate.now(); + + assertThatThrownBy(() -> jdkReleaseScheduleReminder(List.of(), now)) + .isInstanceOf(AssertionError.class); + + assertThatThrownBy(() -> + jdkReleaseScheduleReminder(List.of(Arguments.of(42, now)), now)) + .isInstanceOf(AssertionError.class); + + // should not trigger until the release day + jdkReleaseScheduleReminder(List.of(Arguments.of(42, now.plusDays(1))), now); + + } +}