Skip to content

Commit

Permalink
jdk update reminder (#3410)
Browse files Browse the repository at this point in the history
* 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 874220e.

* 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 <[email protected]>

---------

Co-authored-by: jackshirazi <[email protected]>
  • Loading branch information
SylvainJuge and jackshirazi authored Nov 7, 2023
1 parent 8c173e5 commit 294c8ad
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Arguments> 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<Arguments> 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);

}
}

0 comments on commit 294c8ad

Please sign in to comment.