From 7584238543934270569f8db82b876852af1ab921 Mon Sep 17 00:00:00 2001 From: OpenTelemetry Bot <107717825+opentelemetrybot@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:18:37 -0500 Subject: [PATCH] [release/v1.42.x] Stop publishing test fixtures with opentelemetry-api (#6698) Co-authored-by: jack-berg <34418638+jack-berg@users.noreply.github.com> --- api/all/build.gradle.kts | 7 ++----- .../opentelemetry/api/OpenTelemetryTest.java | 1 + .../api/logs/DefaultLoggerTest.java | 2 ++ .../api/metrics/DefaultMeterTest.java | 2 ++ .../api/trace/DefaultTracerTest.java | 2 ++ api/incubator/build.gradle.kts | 2 +- .../incubator/ExtendedOpenTelemetryTest.java | 2 +- .../logs/ExtendedDefaultLoggerTest.java | 2 +- .../metrics/ExtendedDefaultMeterTest.java | 2 +- .../trace/ExtendedDefaultTracerTest.java | 2 +- api/testing-internal/build.gradle.kts | 21 +++++++++++++++++++ .../internal}/AbstractDefaultLoggerTest.java | 7 +++++-- .../internal}/AbstractDefaultMeterTest.java | 17 +++++++++++++-- .../internal}/AbstractDefaultTracerTest.java | 13 ++++++++++-- .../internal}/AbstractOpenTelemetryTest.java | 10 ++++++--- settings.gradle.kts | 1 + 16 files changed, 74 insertions(+), 19 deletions(-) create mode 100644 api/testing-internal/build.gradle.kts rename api/{all/src/testFixtures/java/io/opentelemetry/api/logs => testing-internal/src/main/java/io/opentelemetry/api/testing/internal}/AbstractDefaultLoggerTest.java (90%) rename api/{all/src/testFixtures/java/io/opentelemetry/api/metrics => testing-internal/src/main/java/io/opentelemetry/api/testing/internal}/AbstractDefaultMeterTest.java (90%) rename api/{all/src/testFixtures/java/io/opentelemetry/api/trace => testing-internal/src/main/java/io/opentelemetry/api/testing/internal}/AbstractDefaultTracerTest.java (92%) rename api/{all/src/testFixtures/java/io/opentelemetry/api => testing-internal/src/main/java/io/opentelemetry/api/testing/internal}/AbstractOpenTelemetryTest.java (92%) diff --git a/api/all/build.gradle.kts b/api/all/build.gradle.kts index 6ade72dfd88..ad6896387d8 100644 --- a/api/all/build.gradle.kts +++ b/api/all/build.gradle.kts @@ -1,7 +1,6 @@ plugins { id("otel.java-conventions") id("otel.publish-conventions") - id("java-test-fixtures") id("otel.jmh-conventions") id("otel.animalsniffer-conventions") @@ -16,12 +15,10 @@ dependencies { annotationProcessor("com.google.auto.value:auto-value") + testImplementation(project(":api:testing-internal")) + testImplementation("edu.berkeley.cs.jqf:jqf-fuzz") testImplementation("com.google.guava:guava-testlib") - testFixturesApi(project(":testing-internal")) - testFixturesApi("junit:junit") - testFixturesApi("org.assertj:assertj-core") - testFixturesApi("org.mockito:mockito-core") } tasks.test { diff --git a/api/all/src/test/java/io/opentelemetry/api/OpenTelemetryTest.java b/api/all/src/test/java/io/opentelemetry/api/OpenTelemetryTest.java index c3754a6df3b..f985cffe2ed 100644 --- a/api/all/src/test/java/io/opentelemetry/api/OpenTelemetryTest.java +++ b/api/all/src/test/java/io/opentelemetry/api/OpenTelemetryTest.java @@ -7,6 +7,7 @@ import io.opentelemetry.api.logs.LoggerProvider; import io.opentelemetry.api.metrics.MeterProvider; +import io.opentelemetry.api.testing.internal.AbstractOpenTelemetryTest; import io.opentelemetry.api.trace.TracerProvider; class OpenTelemetryTest extends AbstractOpenTelemetryTest { diff --git a/api/all/src/test/java/io/opentelemetry/api/logs/DefaultLoggerTest.java b/api/all/src/test/java/io/opentelemetry/api/logs/DefaultLoggerTest.java index 436baee524c..10b43897a3e 100644 --- a/api/all/src/test/java/io/opentelemetry/api/logs/DefaultLoggerTest.java +++ b/api/all/src/test/java/io/opentelemetry/api/logs/DefaultLoggerTest.java @@ -5,6 +5,8 @@ package io.opentelemetry.api.logs; +import io.opentelemetry.api.testing.internal.AbstractDefaultLoggerTest; + class DefaultLoggerTest extends AbstractDefaultLoggerTest { @Override diff --git a/api/all/src/test/java/io/opentelemetry/api/metrics/DefaultMeterTest.java b/api/all/src/test/java/io/opentelemetry/api/metrics/DefaultMeterTest.java index 1b012be1d55..69b32d5ecc0 100644 --- a/api/all/src/test/java/io/opentelemetry/api/metrics/DefaultMeterTest.java +++ b/api/all/src/test/java/io/opentelemetry/api/metrics/DefaultMeterTest.java @@ -5,6 +5,8 @@ package io.opentelemetry.api.metrics; +import io.opentelemetry.api.testing.internal.AbstractDefaultMeterTest; + public class DefaultMeterTest extends AbstractDefaultMeterTest { @Override diff --git a/api/all/src/test/java/io/opentelemetry/api/trace/DefaultTracerTest.java b/api/all/src/test/java/io/opentelemetry/api/trace/DefaultTracerTest.java index f0f577d9946..b6736fa3843 100644 --- a/api/all/src/test/java/io/opentelemetry/api/trace/DefaultTracerTest.java +++ b/api/all/src/test/java/io/opentelemetry/api/trace/DefaultTracerTest.java @@ -5,6 +5,8 @@ package io.opentelemetry.api.trace; +import io.opentelemetry.api.testing.internal.AbstractDefaultTracerTest; + class DefaultTracerTest extends AbstractDefaultTracerTest { @Override diff --git a/api/incubator/build.gradle.kts b/api/incubator/build.gradle.kts index b28295de6d0..bdf12950acf 100644 --- a/api/incubator/build.gradle.kts +++ b/api/incubator/build.gradle.kts @@ -15,7 +15,7 @@ dependencies { annotationProcessor("com.google.auto.value:auto-value") testImplementation(project(":sdk:testing")) - testImplementation(testFixtures(project(":api:all"))) + testImplementation(project(":api:testing-internal")) testImplementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating") diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/ExtendedOpenTelemetryTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/ExtendedOpenTelemetryTest.java index b33c29c8194..4903d00c2e6 100644 --- a/api/incubator/src/test/java/io/opentelemetry/api/incubator/ExtendedOpenTelemetryTest.java +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/ExtendedOpenTelemetryTest.java @@ -7,7 +7,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import io.opentelemetry.api.AbstractOpenTelemetryTest; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.incubator.logs.ExtendedDefaultLoggerProvider; import io.opentelemetry.api.incubator.logs.ExtendedLogger; @@ -17,6 +16,7 @@ import io.opentelemetry.api.incubator.trace.ExtendedTracer; import io.opentelemetry.api.logs.LoggerProvider; import io.opentelemetry.api.metrics.MeterProvider; +import io.opentelemetry.api.testing.internal.AbstractOpenTelemetryTest; import io.opentelemetry.api.trace.TracerProvider; import io.opentelemetry.context.propagation.ContextPropagators; import org.junit.jupiter.api.Test; diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLoggerTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLoggerTest.java index e558b53fcf1..e92a3c160a6 100644 --- a/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLoggerTest.java +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/logs/ExtendedDefaultLoggerTest.java @@ -8,9 +8,9 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.common.Value; -import io.opentelemetry.api.logs.AbstractDefaultLoggerTest; import io.opentelemetry.api.logs.Logger; import io.opentelemetry.api.logs.LoggerProvider; +import io.opentelemetry.api.testing.internal.AbstractDefaultLoggerTest; import org.junit.jupiter.api.Test; class ExtendedDefaultLoggerTest extends AbstractDefaultLoggerTest { diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeterTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeterTest.java index 3d342a33661..a56a8740b04 100644 --- a/api/incubator/src/test/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeterTest.java +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/metrics/ExtendedDefaultMeterTest.java @@ -8,9 +8,9 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.metrics.AbstractDefaultMeterTest; import io.opentelemetry.api.metrics.Meter; import io.opentelemetry.api.metrics.MeterProvider; +import io.opentelemetry.api.testing.internal.AbstractDefaultMeterTest; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/api/incubator/src/test/java/io/opentelemetry/api/incubator/trace/ExtendedDefaultTracerTest.java b/api/incubator/src/test/java/io/opentelemetry/api/incubator/trace/ExtendedDefaultTracerTest.java index 1550796d42d..791c6b7d47c 100644 --- a/api/incubator/src/test/java/io/opentelemetry/api/incubator/trace/ExtendedDefaultTracerTest.java +++ b/api/incubator/src/test/java/io/opentelemetry/api/incubator/trace/ExtendedDefaultTracerTest.java @@ -8,7 +8,7 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.trace.AbstractDefaultTracerTest; +import io.opentelemetry.api.testing.internal.AbstractDefaultTracerTest; import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.api.trace.TracerProvider; import org.junit.jupiter.api.Test; diff --git a/api/testing-internal/build.gradle.kts b/api/testing-internal/build.gradle.kts new file mode 100644 index 00000000000..b3e79cf0cfe --- /dev/null +++ b/api/testing-internal/build.gradle.kts @@ -0,0 +1,21 @@ +plugins { + id("otel.java-conventions") +} + +description = "OpenTelemetry API Testing (Internal)" +otelJava.moduleName.set("io.opentelemetry.api.testing.internal") + +dependencies { + api(project(":api:all")) + + implementation(project(":testing-internal")) + + implementation("com.linecorp.armeria:armeria-junit5") + implementation("org.assertj:assertj-core") + implementation("org.mockito:mockito-core") +} + +// Skip OWASP dependencyCheck task on test module +dependencyCheck { + skip = true +} diff --git a/api/all/src/testFixtures/java/io/opentelemetry/api/logs/AbstractDefaultLoggerTest.java b/api/testing-internal/src/main/java/io/opentelemetry/api/testing/internal/AbstractDefaultLoggerTest.java similarity index 90% rename from api/all/src/testFixtures/java/io/opentelemetry/api/logs/AbstractDefaultLoggerTest.java rename to api/testing-internal/src/main/java/io/opentelemetry/api/testing/internal/AbstractDefaultLoggerTest.java index 88ecb74809a..82d9f0b1f67 100644 --- a/api/all/src/testFixtures/java/io/opentelemetry/api/logs/AbstractDefaultLoggerTest.java +++ b/api/testing-internal/src/main/java/io/opentelemetry/api/testing/internal/AbstractDefaultLoggerTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.api.logs; +package io.opentelemetry.api.testing.internal; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; @@ -11,12 +11,15 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.Value; +import io.opentelemetry.api.logs.Logger; +import io.opentelemetry.api.logs.LoggerProvider; +import io.opentelemetry.api.logs.Severity; import io.opentelemetry.context.Context; import java.time.Instant; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; -/** Unit tests for {@link DefaultLogger}. */ +/** Unit tests for No-op {@link Logger}. */ public abstract class AbstractDefaultLoggerTest { protected abstract LoggerProvider getLoggerProvider(); diff --git a/api/all/src/testFixtures/java/io/opentelemetry/api/metrics/AbstractDefaultMeterTest.java b/api/testing-internal/src/main/java/io/opentelemetry/api/testing/internal/AbstractDefaultMeterTest.java similarity index 90% rename from api/all/src/testFixtures/java/io/opentelemetry/api/metrics/AbstractDefaultMeterTest.java rename to api/testing-internal/src/main/java/io/opentelemetry/api/testing/internal/AbstractDefaultMeterTest.java index b64c0929803..b96de557c42 100644 --- a/api/all/src/testFixtures/java/io/opentelemetry/api/metrics/AbstractDefaultMeterTest.java +++ b/api/testing-internal/src/main/java/io/opentelemetry/api/testing/internal/AbstractDefaultMeterTest.java @@ -3,16 +3,28 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.api.metrics; +package io.opentelemetry.api.testing.internal; import static io.opentelemetry.api.common.AttributeKey.stringKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.metrics.DoubleCounter; +import io.opentelemetry.api.metrics.DoubleGauge; +import io.opentelemetry.api.metrics.DoubleHistogram; +import io.opentelemetry.api.metrics.DoubleUpDownCounter; +import io.opentelemetry.api.metrics.LongCounter; +import io.opentelemetry.api.metrics.LongGauge; +import io.opentelemetry.api.metrics.LongHistogram; +import io.opentelemetry.api.metrics.LongUpDownCounter; +import io.opentelemetry.api.metrics.Meter; +import io.opentelemetry.api.metrics.MeterProvider; +import io.opentelemetry.api.metrics.ObservableDoubleMeasurement; +import io.opentelemetry.api.metrics.ObservableLongMeasurement; import io.opentelemetry.context.Context; import io.opentelemetry.internal.testing.slf4j.SuppressLogger; import org.junit.jupiter.api.Test; -/** Unit tests for {@link DefaultMeter}. */ +/** Unit tests for No-op {@link Meter}. */ @SuppressLogger() public abstract class AbstractDefaultMeterTest { private final Meter meter = getMeter(); @@ -245,6 +257,7 @@ void noopObservableDoubleUpDownCounter_doesNotThrow() { } @Test + @SuppressWarnings("NullAway") void noopBatchCallback_doesNotThrow() { meter.batchCallback(() -> {}, null); } diff --git a/api/all/src/testFixtures/java/io/opentelemetry/api/trace/AbstractDefaultTracerTest.java b/api/testing-internal/src/main/java/io/opentelemetry/api/testing/internal/AbstractDefaultTracerTest.java similarity index 92% rename from api/all/src/testFixtures/java/io/opentelemetry/api/trace/AbstractDefaultTracerTest.java rename to api/testing-internal/src/main/java/io/opentelemetry/api/testing/internal/AbstractDefaultTracerTest.java index 1933e289d5b..c90b7da21d9 100644 --- a/api/all/src/testFixtures/java/io/opentelemetry/api/trace/AbstractDefaultTracerTest.java +++ b/api/testing-internal/src/main/java/io/opentelemetry/api/testing/internal/AbstractDefaultTracerTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.api.trace; +package io.opentelemetry.api.testing.internal; import static io.opentelemetry.api.common.AttributeKey.stringKey; import static org.assertj.core.api.Assertions.assertThat; @@ -11,12 +11,19 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanBuilder; +import io.opentelemetry.api.trace.SpanContext; +import io.opentelemetry.api.trace.TraceFlags; +import io.opentelemetry.api.trace.TraceState; +import io.opentelemetry.api.trace.Tracer; +import io.opentelemetry.api.trace.TracerProvider; import io.opentelemetry.context.Context; import java.time.Instant; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; -/** Unit tests for {@link DefaultTracer}. */ +/** Unit tests for No-op {@link Tracer}. */ // Need to suppress warnings for MustBeClosed because Android 14 does not support // try-with-resources. @SuppressWarnings("MustBeClosedChecker") @@ -56,6 +63,7 @@ void defaultSpanBuilderWithName() { } @Test + @SuppressWarnings("NullAway") void spanContextPropagationExplicitParent() { assertThat( defaultTracer @@ -109,6 +117,7 @@ void spanContextPropagation_fromContextThenNoParent() { } @Test + @SuppressWarnings("NullAway") void doNotCrash_NoopImplementation() { assertThatCode( () -> { diff --git a/api/all/src/testFixtures/java/io/opentelemetry/api/AbstractOpenTelemetryTest.java b/api/testing-internal/src/main/java/io/opentelemetry/api/testing/internal/AbstractOpenTelemetryTest.java similarity index 92% rename from api/all/src/testFixtures/java/io/opentelemetry/api/AbstractOpenTelemetryTest.java rename to api/testing-internal/src/main/java/io/opentelemetry/api/testing/internal/AbstractOpenTelemetryTest.java index 6ba27d89760..4223d853661 100644 --- a/api/all/src/testFixtures/java/io/opentelemetry/api/AbstractOpenTelemetryTest.java +++ b/api/testing-internal/src/main/java/io/opentelemetry/api/testing/internal/AbstractOpenTelemetryTest.java @@ -3,11 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.api; +package io.opentelemetry.api.testing.internal; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.logs.LoggerProvider; import io.opentelemetry.api.metrics.MeterProvider; import io.opentelemetry.api.trace.TracerProvider; @@ -17,8 +19,9 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; -/** Unit tests for {@link OpenTelemetry}. */ +/** Unit tests for No-op {@link OpenTelemetry}. */ public abstract class AbstractOpenTelemetryTest { + @BeforeAll public static void beforeClass() { GlobalOpenTelemetry.resetForTest(); @@ -96,7 +99,8 @@ void setThenSet() { @Test void getThenSet() { - assertThat(getGlobalOpenTelemetry()).isInstanceOf(DefaultOpenTelemetry.class); + assertThat(getGlobalOpenTelemetry().getClass().getName()) + .isEqualTo("io.opentelemetry.api.DefaultOpenTelemetry"); assertThatThrownBy(() -> GlobalOpenTelemetry.set(getOpenTelemetry())) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("GlobalOpenTelemetry.set has already been called") diff --git a/settings.gradle.kts b/settings.gradle.kts index 4bf7ca86538..12121e5094a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -25,6 +25,7 @@ rootProject.name = "opentelemetry-java" include(":all") include(":api:all") include(":api:incubator") +include(":api:testing-internal") include(":bom") include(":bom-alpha") include(":context")