Skip to content

Commit

Permalink
Add OpenJ9 JDK 21 CI build (#3768)
Browse files Browse the repository at this point in the history
* Use jfr-polyfill when compiling for/running on OpenJ9
* Disable exception message tests on OpenJ9 JVMs
* Disable JFR-related tests on OpenJ9 JVMs
* Disable test on OpenJ9 due to Kotlin DSL issues
  • Loading branch information
marcphilipp committed Apr 12, 2024
1 parent f5ec47f commit 84d426c
Show file tree
Hide file tree
Showing 21 changed files with 145 additions and 10 deletions.
7 changes: 6 additions & 1 deletion .github/actions/setup-test-jdk/action.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
name: Set up Test JDK
description: Sets up the JDK required to run platform-tooling-support-tests
inputs:
distribution:
required: true
description: 'The JDK distribution to use'
default: 'temurin'
runs:
using: "composite"
steps:
- uses: actions/setup-java@v4
with:
distribution: temurin
distribution: ${{ inputs.distribution }}
java-version: 8
- shell: bash
run: echo "JDK8=$JAVA_HOME" >> $GITHUB_ENV
37 changes: 35 additions & 2 deletions .github/workflows/cross-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
jdk: [22, 23]
jdk: [ 22, 23 ]
name: "OpenJDK ${{ matrix.jdk }}"
runs-on: ubuntu-latest
steps:
Expand All @@ -41,11 +41,44 @@ jobs:
uses: ./.github/actions/run-gradle
with:
arguments: |
-PjavaToolchainVersion=${{ matrix.jdk }}
-PjavaToolchain.version=${{ matrix.jdk }}
-Dscan.tag.JDK_${{ matrix.jdk }}
build
- name: Upload Test Distribution trace files
uses: actions/upload-artifact@v4
with:
name: "Test Distribution trace files (OpenJDK ${{ matrix.jdk }})"
path: '**/build/test-results/*/trace.json'
openj9:
strategy:
fail-fast: false
matrix:
jdk: [ 21 ]
name: "OpenJ9 ${{ matrix.jdk }}"
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Test JDK
uses: ./.github/actions/setup-test-jdk
with:
distribution: semeru
- name: 'Set up JDK ${{ matrix.jdk }}'
uses: actions/setup-java@v4
with:
distribution: semeru
java-version: ${{ matrix.jdk }}
- name: 'Prepare JDK${{ matrix.jdk }} env var'
shell: bash
run: echo "JDK${{ matrix.jdk }}=$JAVA_HOME" >> $GITHUB_ENV
- name: Build
uses: ./.github/actions/run-gradle
with:
arguments: |
-PjavaToolchain.version=${{ matrix.jdk }}
-PjavaToolchain.implementation=j9
-Dscan.tag.JDK_${{ matrix.jdk }}
-Dscan.tag.OpenJ9
build
6 changes: 6 additions & 0 deletions documentation/documentation.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ dependencies {
because("Jimfs is used in src/test/java")
}

if (java.toolchain.implementation.orNull == JvmImplementation.J9) {
testRuntimeOnly(libs.jfrPolyfill) {
because("OpenJ9 does not include JFR")
}
}

standaloneConsoleLauncher(projects.junitPlatformConsoleStandalone)
}

Expand Down
3 changes: 3 additions & 0 deletions documentation/src/test/java/example/AssertionsDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ void dependentAssertions() {
);
}

// end::user_guide[]
@extensions.DisabledOnOpenJ9
// tag::user_guide[]
@Test
void exceptionTesting() {
Exception exception = assertThrows(ArithmeticException.class, () ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void verifyAllJupiterEvents() {
message(m -> m.contains("abc does not contain Z")))),
event(test("failingTest"), started()),
event(test("failingTest"), finishedWithFailure(
instanceOf(ArithmeticException.class), message("/ by zero"))),
instanceOf(ArithmeticException.class), message(it -> it.endsWith("by zero")))),
event(container(ExampleTestCase.class), finishedSuccessfully()),
event(engine(), finishedSuccessfully()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void verifyJupiterMethodFailed() {
.assertThatEvents().haveExactly(1, // <5>
event(test("failingTest"),
finishedWithFailure(
instanceOf(ArithmeticException.class), message("/ by zero"))));
instanceOf(ArithmeticException.class), message(it -> it.endsWith("by zero")))));
}

}
Expand Down
24 changes: 24 additions & 0 deletions documentation/src/test/java/extensions/DisabledOnOpenJ9.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/

package extensions;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.condition.DisabledIfSystemProperty;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@DisabledIfSystemProperty(named = "java.vm.vendor", matches = ".*OpenJ9.*")
public @interface DisabledOnOpenJ9 {
}
3 changes: 3 additions & 0 deletions documentation/src/test/kotlin/example/KotlinAssertionsDemo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class KotlinAssertionsDemo {
assertEquals(0, result)
}

// tag::user_guide[]
@Test
// end::user_guide[]
@extensions.DisabledOnOpenJ9
fun `expected exception testing`() {
val calculator = Calculator()
val exception = assertThrows<ArithmeticException> ("Should throw an exception") {
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ gradle-versions = { module = "com.github.ben-manes:gradle-versions-plugin", vers
groovy4 = { module = "org.apache.groovy:groovy", version = "4.0.21" }
groovy2-bom = { module = "org.codehaus.groovy:groovy-bom", version = "2.5.21" }
hamcrest = { module = "org.hamcrest:hamcrest", version = "2.2" }
jfrPolyfill = { module = "org.gradle.jfr.polyfill:jfr-polyfill", version = "1.0.2" }
jfrunit = { module = "org.moditect.jfrunit:jfrunit-core", version = "1.0.0.Alpha2" }
jimfs = { module = "com.google.jimfs:jimfs", version = "1.3.0" }
jmh-core = { module = "org.openjdk.jmh:jmh-core", version.ref = "jmh" }
Expand Down
10 changes: 8 additions & 2 deletions gradle/plugins/build-parameters/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ buildParameters {
defaultValue = false
fromEnvironment()
}
integer("javaToolchainVersion") {
description = "Defines the Java toolchain version to use for compiling code"
group("javaToolchain") {
description = "Parameters controlling the Java toolchain used for compiling code and running tests"
integer("version") {
description = "JDK version"
}
string("implementation") {
description = "JDK implementation (for example, 'j9')"
}
}
group("documentation") {
description = "Parameters controlling how the documentation is built"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ plugins {

project.pluginManager.withPlugin("java") {
val defaultLanguageVersion = JavaLanguageVersion.of(21)
val javaLanguageVersion = buildParameters.javaToolchainVersion.map { JavaLanguageVersion.of(it) }.getOrElse(defaultLanguageVersion)
val javaLanguageVersion = buildParameters.javaToolchain.version.map { JavaLanguageVersion.of(it) }.getOrElse(defaultLanguageVersion)
val jvmImplementation = buildParameters.javaToolchain.implementation.map {
when(it) {
"j9" -> JvmImplementation.J9
else -> throw InvalidUserDataException("Unsupported JDK implementation: $it")
}
}.getOrElse(JvmImplementation.VENDOR_SPECIFIC)

val extension = the<JavaPluginExtension>()
val javaToolchainService = the<JavaToolchainService>()

extension.toolchain.languageVersion = javaLanguageVersion
extension.toolchain {
languageVersion = javaLanguageVersion
implementation = jvmImplementation
}

pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
configure<KotlinJvmProjectExtension> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ dependencies {
testRuntimeOnly(project(":junit-platform-reporting"))

testRuntimeOnly(bundleFromLibs("log4j"))
testRuntimeOnly(dependencyFromLibs("jfrPolyfill")) {
because("OpenJ9 does not include JFR")
}
testRuntimeOnly(dependencyFromLibs("openTestReporting-events")) {
because("it's required to run tests via IntelliJ which does not consumed the shadowed jar of junit-platform-reporting")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/

package org.junit.jupiter.api.extension;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.condition.DisabledIfSystemProperty;

@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@DisabledIfSystemProperty(named = "java.vm.vendor", matches = ".*OpenJ9.*")
public @interface DisabledOnOpenJ9 {
}
6 changes: 6 additions & 0 deletions junit-platform-jfr/junit-platform-jfr.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ dependencies {

compileOnlyApi(libs.apiguardian)

if (java.toolchain.implementation.orNull == JvmImplementation.J9) {
compileOnly(libs.jfrPolyfill) {
because("OpenJ9 does not include JFR")
}
}

osgiVerification(projects.junitJupiterEngine)
osgiVerification(projects.junitPlatformLauncher)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,8 @@ void findNestedClassesWithInvalidNestedClassFile(@TrackLogRecords LogRecordListe
assertEquals(fqcn, classWithInvalidNestedClassFile.getName());
var noClassDefFoundError = assertThrows(NoClassDefFoundError.class,
classWithInvalidNestedClassFile::getDeclaredClasses);
assertEquals("tests/NestedInterfaceGroovyTests$NestedInterface$1", noClassDefFoundError.getMessage());
assertThat(noClassDefFoundError) //
.hasMessageMatching("tests[./]NestedInterfaceGroovyTests\\$NestedInterface\\$1");

assertThat(findNestedClasses(classWithInvalidNestedClassFile)).isEmpty();
// @formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
import static org.moditect.jfrunit.JfrEventsAssert.assertThat;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.DisabledOnOpenJ9;
import org.junit.jupiter.engine.JupiterTestEngine;
import org.junit.platform.launcher.core.LauncherFactoryForTestingPurposesOnly;
import org.moditect.jfrunit.EnableEvent;
import org.moditect.jfrunit.JfrEventTest;
import org.moditect.jfrunit.JfrEvents;

@JfrEventTest
@DisabledOnOpenJ9
public class FlightRecordingDiscoveryListenerIntegrationTests {

public JfrEvents jfrEvents = new JfrEvents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestReporter;
import org.junit.jupiter.api.extension.DisabledOnOpenJ9;
import org.junit.jupiter.engine.JupiterTestEngine;
import org.junit.platform.launcher.core.LauncherFactoryForTestingPurposesOnly;
import org.moditect.jfrunit.EnableEvent;
import org.moditect.jfrunit.JfrEventTest;
import org.moditect.jfrunit.JfrEvents;

@JfrEventTest
@DisabledOnOpenJ9
public class FlightRecordingExecutionListenerIntegrationTests {

public JfrEvents jfrEvents = new JfrEvents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ dependencies {
because("we reference Ant's main class")
}
testImplementation(libs.bundles.xmlunit)
testImplementation(testFixtures(projects.junitJupiterApi))

thirdPartyJars(libs.junit4)
thirdPartyJars(libs.assertj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import de.sormuras.bartholdy.tool.GradleWrapper;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.DisabledOnOpenJ9;

import platform.tooling.support.MavenRepo;
import platform.tooling.support.Request;

/**
* @since 1.9.1
*/
@DisabledOnOpenJ9
class GraalVmStarterTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.codehaus.groovy.runtime.ProcessGroovyMethods;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.DisabledOnOpenJ9;
import org.junit.jupiter.api.io.TempDir;

import platform.tooling.support.Helper;
Expand All @@ -35,6 +36,7 @@
/**
* @since 1.5
*/
@DisabledOnOpenJ9
class ModularUserGuideTests {

private static final String DOCUMENTATION_MODULE_DESCRIPTOR = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.DisabledOnOpenJ9;

import platform.tooling.support.Helper;
import platform.tooling.support.MavenRepo;
Expand Down Expand Up @@ -87,6 +88,7 @@ void findAndRunJUnitOnTheClassPath() {
}

@Test
@DisabledOnOpenJ9
void findAndRunJUnitOnTheModulePath() {
var finder = ModuleFinder.of(LIB);
var modules = finder.findAll().stream() //
Expand Down

0 comments on commit 84d426c

Please sign in to comment.