Fix jfr tests on openj9 (#12876)
This commit is contained in:
parent
ccedc40de9
commit
c070dc8dea
|
@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.javaagent.runtimemetrics.java17;
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
|
import jdk.jfr.FlightRecorder;
|
||||||
import org.junit.jupiter.api.Assumptions;
|
import org.junit.jupiter.api.Assumptions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -20,10 +21,11 @@ class JfrRuntimeMetricsTest {
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void setUp() {
|
static void setUp() {
|
||||||
try {
|
try {
|
||||||
Class.forName("jdk.jfr.consumer.RecordingStream");
|
Class.forName("jdk.jfr.FlightRecorder");
|
||||||
} catch (ClassNotFoundException exception) {
|
} catch (ClassNotFoundException exception) {
|
||||||
Assumptions.abort("JFR not present");
|
Assumptions.abort("JFR not present");
|
||||||
}
|
}
|
||||||
|
Assumptions.assumeTrue(FlightRecorder.isAvailable(), "JFR not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import jdk.jfr.EventSettings;
|
import jdk.jfr.EventSettings;
|
||||||
|
import jdk.jfr.FlightRecorder;
|
||||||
import jdk.jfr.consumer.RecordingStream;
|
import jdk.jfr.consumer.RecordingStream;
|
||||||
|
|
||||||
/** The entry point class for runtime metrics support using JFR and JMX. */
|
/** The entry point class for runtime metrics support using JFR and JMX. */
|
||||||
|
@ -107,7 +108,7 @@ public final class RuntimeMetrics implements Closeable {
|
||||||
|
|
||||||
static JfrRuntimeMetrics build(
|
static JfrRuntimeMetrics build(
|
||||||
OpenTelemetry openTelemetry, Predicate<JfrFeature> featurePredicate) {
|
OpenTelemetry openTelemetry, Predicate<JfrFeature> featurePredicate) {
|
||||||
if (!hasJfrRecordingStream()) {
|
if (!isJfrAvailable()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new JfrRuntimeMetrics(openTelemetry, featurePredicate);
|
return new JfrRuntimeMetrics(openTelemetry, featurePredicate);
|
||||||
|
@ -134,13 +135,14 @@ public final class RuntimeMetrics implements Closeable {
|
||||||
return startUpLatch;
|
return startUpLatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasJfrRecordingStream() {
|
private static boolean isJfrAvailable() {
|
||||||
try {
|
try {
|
||||||
Class.forName("jdk.jfr.consumer.RecordingStream");
|
Class.forName("jdk.jfr.FlightRecorder");
|
||||||
return true;
|
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return FlightRecorder.isAvailable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import jdk.jfr.FlightRecorder;
|
||||||
import org.junit.jupiter.api.Assumptions;
|
import org.junit.jupiter.api.Assumptions;
|
||||||
import org.junit.jupiter.api.extension.AfterEachCallback;
|
import org.junit.jupiter.api.extension.AfterEachCallback;
|
||||||
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||||
|
@ -36,10 +37,11 @@ public class JfrExtension implements BeforeEachCallback, AfterEachCallback {
|
||||||
@Override
|
@Override
|
||||||
public void beforeEach(ExtensionContext context) throws InterruptedException {
|
public void beforeEach(ExtensionContext context) throws InterruptedException {
|
||||||
try {
|
try {
|
||||||
Class.forName("jdk.jfr.consumer.RecordingStream");
|
Class.forName("jdk.jfr.FlightRecorder");
|
||||||
} catch (ClassNotFoundException exception) {
|
} catch (ClassNotFoundException exception) {
|
||||||
Assumptions.abort("JFR not present");
|
Assumptions.abort("JFR not present");
|
||||||
}
|
}
|
||||||
|
Assumptions.assumeTrue(FlightRecorder.isAvailable(), "JFR not available");
|
||||||
|
|
||||||
metricReader = InMemoryMetricReader.create();
|
metricReader = InMemoryMetricReader.create();
|
||||||
meterProvider = SdkMeterProvider.builder().registerMetricReader(metricReader).build();
|
meterProvider = SdkMeterProvider.builder().registerMetricReader(metricReader).build();
|
||||||
|
|
|
@ -10,6 +10,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import io.opentelemetry.api.OpenTelemetry;
|
import io.opentelemetry.api.OpenTelemetry;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import jdk.jfr.FlightRecorder;
|
||||||
import org.junit.jupiter.api.Assumptions;
|
import org.junit.jupiter.api.Assumptions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -19,10 +20,11 @@ class RuntimeMetricsBuilderTest {
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void setup() {
|
static void setup() {
|
||||||
try {
|
try {
|
||||||
Class.forName("jdk.jfr.consumer.RecordingStream");
|
Class.forName("jdk.jfr.FlightRecorder");
|
||||||
} catch (ClassNotFoundException exception) {
|
} catch (ClassNotFoundException exception) {
|
||||||
Assumptions.abort("JFR not present");
|
Assumptions.abort("JFR not present");
|
||||||
}
|
}
|
||||||
|
Assumptions.assumeTrue(FlightRecorder.isAvailable(), "JFR not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -12,6 +12,7 @@ import io.opentelemetry.sdk.OpenTelemetrySdk;
|
||||||
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
|
||||||
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import jdk.jfr.FlightRecorder;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Assumptions;
|
import org.junit.jupiter.api.Assumptions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
@ -28,10 +29,11 @@ class RuntimeMetricsTest {
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() {
|
void setup() {
|
||||||
try {
|
try {
|
||||||
Class.forName("jdk.jfr.consumer.RecordingStream");
|
Class.forName("jdk.jfr.FlightRecorder");
|
||||||
} catch (ClassNotFoundException exception) {
|
} catch (ClassNotFoundException exception) {
|
||||||
Assumptions.abort("JFR not present");
|
Assumptions.abort("JFR not present");
|
||||||
}
|
}
|
||||||
|
Assumptions.assumeTrue(FlightRecorder.isAvailable(), "JFR not available");
|
||||||
|
|
||||||
reader = InMemoryMetricReader.createDelta();
|
reader = InMemoryMetricReader.createDelta();
|
||||||
sdk =
|
sdk =
|
||||||
|
|
Loading…
Reference in New Issue