Skip to content

Commit

Permalink
Java 21 compatibility (#1546)
Browse files Browse the repository at this point in the history
  • Loading branch information
meiao authored Oct 12, 2023
1 parent 5a75a5e commit 5708812
Show file tree
Hide file tree
Showing 44 changed files with 199 additions and 84 deletions.
6 changes: 3 additions & 3 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ runs:
with:
distribution: 'temurin'
java-version: |
20
21
17
11
8
Expand All @@ -29,7 +29,7 @@ runs:
sed -i -e "s|jdk8=8|jdk8=${JAVA_HOME_8_X64}|
s|jdk11=11|jdk11=${JAVA_HOME_11_X64}|
s|jdk17=17|jdk17=${JAVA_HOME_17_X64}|
s|jdk20=20|jdk20=${JAVA_HOME_20_X64}|" gradle.properties.gha
s|jdk21=21|jdk21=${JAVA_HOME_21_X64}|" gradle.properties.gha
cat gradle.properties.gha >> gradle.properties
- name: Setup Gradle
Expand All @@ -39,7 +39,7 @@ runs:

- name: Setup Gradle options
shell: bash
run: echo "GRADLE_OPTIONS=--console=plain --parallel -Porg.gradle.java.installations.auto-detect=false -Porg.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME_17_X64,JAVA_HOME_20_X64" >> $GITHUB_ENV
run: echo "GRADLE_OPTIONS=--console=plain --parallel -Porg.gradle.java.installations.auto-detect=false -Porg.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME_17_X64,JAVA_HOME_21_X64" >> $GITHUB_ENV

- name: Download S3 instrumentation jar zip
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/GHA-Functional-Tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
##max-parallel: 1 ## used to force sequential
fail-fast: false
matrix:
java-version: [ 8, 11, 17, 20 ]
java-version: [8, 11, 17, 21]
steps:
- name: Checkout Java agent
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/GHA-Unit-Tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
# max-parallel: 1 ## used to force sequential vs. concurrent
fail-fast: false
matrix:
java-version: [8, 11, 17, 20]
java-version: [8, 11, 17, 21]
steps:
- name: Checkout Java agent
uses: actions/checkout@v3
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/Java-Instrumentation-Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
strategy:
fail-fast: false
matrix:
jre: [8, 11, 17, 20]
name: Java ${{ matrix.jre }}
java-version: [8, 11, 17, 21]
name: Java ${{ matrix.java-version }}
timeout-minutes: 120
# needs: install-all-java
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -55,29 +55,29 @@ jobs:

# GHA run instrumentation tests

- name: Run instrumentation tests for Java ${{ matrix.jre }} (attempt 1)
- name: Run instrumentation tests for Java ${{ matrix.java-version }} (attempt 1)
id: run_tests_1
continue-on-error: true
timeout-minutes: 35
run: ./gradlew $GRADLE_OPTIONS :instrumentation:test -Ptest${{ matrix.jre }} --continue
run: ./gradlew $GRADLE_OPTIONS :instrumentation:test -Ptest${{ matrix.java-version }} --continue

- name: Run instrumentation tests for Java ${{ matrix.jre }} (attempt 2)
- name: Run instrumentation tests for Java ${{ matrix.java-version }} (attempt 2)
id: run_tests_2
continue-on-error: true
timeout-minutes: 35
if: steps.run_tests_1.outcome == 'failure'
run: ./gradlew $GRADLE_OPTIONS :instrumentation:test -Ptest${{ matrix.jre }} --continue
run: ./gradlew $GRADLE_OPTIONS :instrumentation:test -Ptest${{ matrix.java-version }} --continue

- name: Run instrumentation tests for Java ${{ matrix.jre }} (attempt 3)
- name: Run instrumentation tests for Java ${{ matrix.java-version }} (attempt 3)
timeout-minutes: 35
if: steps.run_tests_2.outcome == 'failure'
run: ./gradlew $GRADLE_OPTIONS :instrumentation:test -Ptest${{ matrix.jre }} --continue
run: ./gradlew $GRADLE_OPTIONS :instrumentation:test -Ptest${{ matrix.java-version }} --continue

# Capture HTML build result in artifacts
- name: Capture build reports
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: instrumentation-tests-results-java-${{ matrix.jre }}
name: instrumentation-tests-results-java-${{ matrix.java-version }}
path: |
instrumentation/**/build/reports/tests/*
14 changes: 7 additions & 7 deletions .github/workflows/Test-AITs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ jobs:
with:
distribution: 'zulu'
java-version: |
20
21
17
11
Expand All @@ -207,14 +207,14 @@ jobs:
run: |
echo "JDK_zulu_11=${JAVA_HOME_11_X64}" >> $GITHUB_ENV
echo "JDK_zulu_17=${JAVA_HOME_17_X64}" >> $GITHUB_ENV
echo "JDK_zulu_20=${JAVA_HOME_20_X64}" >> $GITHUB_ENV
echo "JDK_zulu_21=${JAVA_HOME_21_X64}" >> $GITHUB_ENV
- name: Set up Javas
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: |
20
21
17
11
8
Expand Down Expand Up @@ -257,10 +257,10 @@ jobs:
<toolchain>
<type>jdk</type>
<provides>
<version>20</version>
<version>21</version>
</provides>
<configuration>
<jdkHome>${JAVA_HOME_20_X64}</jdkHome>
<jdkHome>${JAVA_HOME_21_X64}</jdkHome>
</configuration>
</toolchain>
</toolchains>
Expand Down Expand Up @@ -291,11 +291,11 @@ jobs:
bin/pip3 install -r conf/requirements.txt
ZULU11=${JDK_zulu_11} \
ZULU17=${JDK_zulu_17} \
ZULU20=${JDK_zulu_20} \
ZULU21=${JDK_zulu_21} \
JAVA8JRE=${JAVA_HOME_8_X64} \
JAVA11JRE=${JAVA_HOME_11_X64} \
JAVA17JRE=${JAVA_HOME_17_X64} \
JAVA20JRE=${JAVA_HOME_20_X64} \
JAVA21JRE=${JAVA_HOME_21_X64} \
conf/autoconfigure
. conf/testenv java
cat conf/java_local_config.yml
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ ext {
// SynchronizedAnnotationNode, SynchronizedClassNode, SynchronizedFieldNode, SynchronizedInnerClassNode, SynchronizedMethodNode,
// SynchronizedModuleExportNode, SynchronizedModuleNode, SynchronizedModuleOpenNode, SynchronizedModuleProvideNode, SynchronizedModuleRequireNode,
// SynchronizedTypeAnnotationNode
asmVersion="9.5"
asmVersion="9.6"
}
4 changes: 2 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ repositories {
dependencies {
// This is how we do our NR-specific patching. That is, moving Log4jPlugins,
// changing Logger.getLogger, and checking for unmapped dependencies.
implementation("org.ow2.asm:asm:9.3")
implementation("org.ow2.asm:asm-commons:9.3")
implementation("org.ow2.asm:asm:9.6")
implementation("org.ow2.asm:asm-commons:9.6")

// Shadow is used here because several classes implement the Transformer interface
implementation("com.github.jengelman.gradle.plugins:shadow:6.0.0")
Expand Down
2 changes: 1 addition & 1 deletion functional_test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test {
//testLogging.showStandardStreams = true

// when using an early access Java version, we need to pass an extra param to the agent
if (project.hasProperty("test21")) {
if (project.hasProperty("test22")) {
jvmArgs += ["-Dnewrelic.config.experimental_runtime=true"]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.newrelic.api.agent.Trace;
import com.newrelic.test.marker.IBMJ9IncompatibleTest;
import com.newrelic.test.marker.Java17IncompatibleTest;
import com.newrelic.test.marker.Java20IncompatibleTest;
import com.newrelic.test.marker.Java21IncompatibleTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand Down Expand Up @@ -68,7 +68,7 @@ public void testMissingNewRelicClass() throws ClassNotFoundException {

// Java 12 no longer lets us access the declared field
@Test
@Category({ IBMJ9IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class })
@Category({ IBMJ9IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class })
public void testSetSystemClassLoader() throws Exception {

final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

import com.newrelic.test.marker.Java11IncompatibleTest;
import com.newrelic.test.marker.Java17IncompatibleTest;
import com.newrelic.test.marker.Java20IncompatibleTest;
import com.newrelic.test.marker.Java21IncompatibleTest;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import javax.activation.MimeType;
import java.util.HashMap;
import java.util.Map;

@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class })
@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class })
public class ClassRetransformBootstrapTest {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import com.newrelic.api.agent.Trace;
import com.newrelic.test.marker.Java11IncompatibleTest;
import com.newrelic.test.marker.Java17IncompatibleTest;
import com.newrelic.test.marker.Java20IncompatibleTest;
import com.newrelic.test.marker.Java21IncompatibleTest;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;

import javax.activation.MimeType;

@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class })
@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class })
public class CustomExtensionTestAddition {

@Test
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties.gha
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jdk8=8
jdk11=11
jdk17=17
jdk20=20
jdk21=21
10 changes: 6 additions & 4 deletions gradle/script/java.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ test {
ext.configuredWithValidTestJDK = {
if (project.hasProperty("test9") || project.hasProperty("test10") || project.hasProperty("test12") || project.hasProperty("test13") ||
project.hasProperty("test14") || project.hasProperty("test15") || project.hasProperty("test16") || project.hasProperty("test18") ||
project.hasProperty("test19")) {
project.hasProperty("test19") || project.hasProperty("test20")) {
logger.lifecycle("The newrelic-java-agent project does not support testing with the Java version configured by the -PtestN gradle property.")
return false
}
Expand All @@ -117,8 +117,8 @@ test {
configuration.call()
}

if (project.hasProperty("test20")) {
configureTest("jdk20") {
if (project.hasProperty("test21")) {
configureTest("jdk21") {
jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED',
'--add-opens=java.base/java.util=ALL-UNNAMED',
'--add-opens=java.base/java.net=ALL-UNNAMED',
Expand All @@ -127,9 +127,11 @@ test {
'--add-exports=java.base/sun.net.spi=ALL-UNNAMED',
'--add-exports=java.xml/com.sun.org.apache.xalan.internal.xsltc.trax=ALL-UNNAMED'
useJUnit {
excludeCategories 'com.newrelic.test.marker.Java20IncompatibleTest'
excludeCategories 'com.newrelic.test.marker.Java21IncompatibleTest'
}
}
// mockito uses a version of bytebuddy that has experimental support for Java 21
systemProperty("net.bytebuddy.experimental", "true")
}
if (project.hasProperty("test17")) {
configureTest("jdk17") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.newrelic.agent.introspec.Introspector;
import com.newrelic.agent.introspec.TracedMetricData;
import com.newrelic.test.marker.Java17IncompatibleTest;
import com.newrelic.test.marker.Java20IncompatibleTest;
import com.newrelic.test.marker.Java21IncompatibleTest;
import com.nr.instrumentation.akka22.test.actors.broadcasting.ActorA;
import com.nr.instrumentation.akka22.test.actors.broadcasting.ActorB;
import com.nr.instrumentation.akka22.test.actors.broadcasting.ActorC;
Expand All @@ -32,7 +32,7 @@
import static org.junit.Assert.assertTrue;

// Not compatible with Java 11+ and Scala 2.13+ https://github.com/scala/bug/issues/12340
@Category({ Java17IncompatibleTest.class, Java20IncompatibleTest.class })
@Category({ Java17IncompatibleTest.class, Java21IncompatibleTest.class })
@RunWith(InstrumentationTestRunner.class)
@InstrumentationTestConfig(includePrefixes = {"akka.actor", "akka.dispatch", "akka.pattern", "akka.routing"})
public class AkkaTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import static org.hamcrest.Matchers.containsString;

// Not compatible with Java 11+ and Scala 2.13+ https://github.com/scala/bug/issues/12340
@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class })
@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class })
@RunWith(InstrumentationTestRunner.class)
@InstrumentationTestConfig(includePrefixes = {"akka", "scala", "com.agent", "com.nr"})
public class AkkaHttpRoutesTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.newrelic.agent.introspec.TransactionEvent;
import com.newrelic.test.marker.Java11IncompatibleTest;
import com.newrelic.test.marker.Java17IncompatibleTest;
import com.newrelic.test.marker.Java20IncompatibleTest;
import com.newrelic.test.marker.Java21IncompatibleTest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand All @@ -29,7 +29,7 @@
import static org.junit.Assert.assertTrue;

// Not compatible with Java 11+ and Scala 2.13+ https://github.com/scala/bug/issues/12340
@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class })
@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class })
@RunWith(InstrumentationTestRunner.class)
@InstrumentationTestConfig(includePrefixes = {"akka", "scala"})
public class AkkaResponseWrapperTest {
Expand Down
11 changes: 11 additions & 0 deletions instrumentation/apache-log4j-1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Log4J1 instrumentation

## Regarding ignored tests under Java 21

Log4J1 supposes it is running on Java 1 unless the Java version has a `.` followed by a number different than `1`.
When it runs on Java 1, it does not set MDC entries.

Corretto distribution of Java 21(.0.0) returns "21" when `System.getProperty("java.version")` is invoked.

So when running our tests with Java 21, MDC will not work. Thus our tests will fail.
It is likely that this will be fixed when 21.0.1 is released. At which point we could re-enable the tests.
4 changes: 0 additions & 4 deletions instrumentation/apache-log4j-1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,3 @@ site {
title 'Log4j-1'
type 'Framework'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.newrelic.agent.bridge.logging.AppLoggingUtils;
import com.newrelic.agent.bridge.logging.LogAttributeKey;
import com.newrelic.agent.bridge.logging.LogAttributeType;
import com.newrelic.test.marker.Java21IncompatibleTest;
import org.apache.log4j.Category;
import org.apache.log4j.MDC;
import org.apache.log4j.Priority;
Expand All @@ -22,9 +23,13 @@
import java.util.Map;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.*;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

// Log4J1 has a quirk with Java 21(.0.0), maybe this will work when 21.0.1 is released
@org.junit.experimental.categories.Category({ Java21IncompatibleTest.class})
public class LoggingEventMapTest {

private static Stream<Arguments> providerParamsForLoggingEventMapTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
import com.newrelic.agent.introspec.InstrumentationTestRunner;
import com.newrelic.agent.introspec.Introspector;
import com.newrelic.agent.model.LogEvent;
import com.newrelic.test.marker.Java21IncompatibleTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.util.Collection;
import java.util.Map;

import static org.junit.Assert.assertEquals;

// Log4J1 has a quirk with Java 21(.0.0), maybe this will work when 21.0.1 is released
@Category({Java21IncompatibleTest.class})
@RunWith(InstrumentationTestRunner.class)
@InstrumentationTestConfig(includePrefixes = {"org.apache.log4j"}, configName = "application_logging_context_data_enabled.yml")
public class ContextDataTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class })
@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class })
@RunWith(InstrumentationTestRunner.class)
@InstrumentationTestConfig(includePrefixes = {"com.nr.agent.instrumentation.asynchttpclient", "org.asynchttpclient"})
public class AsyncHttpClient2_0_0Tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class })
@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class })
@RunWith(InstrumentationTestRunner.class)
@InstrumentationTestConfig(includePrefixes = {"com.nr.agent.instrumentation.asynchttpclient", "org.asynchttpclient"})
public class AsyncHttpClient2_1_0Tests {
Expand Down
Loading

0 comments on commit 5708812

Please sign in to comment.