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

Fix jfr tests on openj9 #12876

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import jdk.jfr.FlightRecorder;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -20,10 +21,11 @@ class JfrRuntimeMetricsTest {
@BeforeAll
static void setUp() {
try {
Class.forName("jdk.jfr.consumer.RecordingStream");
Class.forName("jdk.jfr.FlightRecorder");
} catch (ClassNotFoundException exception) {
Assumptions.abort("JFR not present");
}
Assumptions.assumeTrue(FlightRecorder.isAvailable(), "JFR not available");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.logging.Logger;
import javax.annotation.Nullable;
import jdk.jfr.EventSettings;
import jdk.jfr.FlightRecorder;
import jdk.jfr.consumer.RecordingStream;

/** The entry point class for runtime metrics support using JFR and JMX. */
Expand Down Expand Up @@ -107,7 +108,7 @@ private JfrRuntimeMetrics(OpenTelemetry openTelemetry, Predicate<JfrFeature> fea

static JfrRuntimeMetrics build(
OpenTelemetry openTelemetry, Predicate<JfrFeature> featurePredicate) {
if (!hasJfrRecordingStream()) {
if (!isJfrAvailable()) {
return null;
}
return new JfrRuntimeMetrics(openTelemetry, featurePredicate);
Expand All @@ -134,13 +135,14 @@ CountDownLatch getStartUpLatch() {
return startUpLatch;
}

private static boolean hasJfrRecordingStream() {
private static boolean isJfrAvailable() {
try {
Class.forName("jdk.jfr.consumer.RecordingStream");
return true;
Class.forName("jdk.jfr.FlightRecorder");
} catch (ClassNotFoundException e) {
return false;
}

return FlightRecorder.isAvailable();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import jdk.jfr.FlightRecorder;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
Expand All @@ -36,10 +37,11 @@ public JfrExtension(Consumer<RuntimeMetricsBuilder> builderConsumer) {
@Override
public void beforeEach(ExtensionContext context) throws InterruptedException {
try {
Class.forName("jdk.jfr.consumer.RecordingStream");
Class.forName("jdk.jfr.FlightRecorder");
} catch (ClassNotFoundException exception) {
Assumptions.abort("JFR not present");
}
Assumptions.assumeTrue(FlightRecorder.isAvailable(), "JFR not available");

metricReader = InMemoryMetricReader.create();
meterProvider = SdkMeterProvider.builder().registerMetricReader(metricReader).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.opentelemetry.api.OpenTelemetry;
import java.util.Arrays;
import java.util.HashMap;
import jdk.jfr.FlightRecorder;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -19,10 +20,11 @@ class RuntimeMetricsBuilderTest {
@BeforeAll
static void setup() {
try {
Class.forName("jdk.jfr.consumer.RecordingStream");
Class.forName("jdk.jfr.FlightRecorder");
} catch (ClassNotFoundException exception) {
Assumptions.abort("JFR not present");
}
Assumptions.assumeTrue(FlightRecorder.isAvailable(), "JFR not available");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import java.util.concurrent.atomic.AtomicBoolean;
import jdk.jfr.FlightRecorder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -28,10 +29,11 @@ class RuntimeMetricsTest {
@BeforeEach
void setup() {
try {
Class.forName("jdk.jfr.consumer.RecordingStream");
Class.forName("jdk.jfr.FlightRecorder");
} catch (ClassNotFoundException exception) {
Assumptions.abort("JFR not present");
}
Assumptions.assumeTrue(FlightRecorder.isAvailable(), "JFR not available");

reader = InMemoryMetricReader.createDelta();
sdk =
Expand Down
Loading