Skip to content

Commit

Permalink
Stop publishing test fixtures with opentelemetry-api (#6695)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored Sep 10, 2024
1 parent b0643fe commit 9ddccad
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 19 deletions.
7 changes: 2 additions & 5 deletions api/all/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.api.logs;

import io.opentelemetry.api.testing.internal.AbstractDefaultLoggerTest;

class DefaultLoggerTest extends AbstractDefaultLoggerTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.api.metrics;

import io.opentelemetry.api.testing.internal.AbstractDefaultMeterTest;

public class DefaultMeterTest extends AbstractDefaultMeterTest {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.api.trace;

import io.opentelemetry.api.testing.internal.AbstractDefaultTracerTest;

class DefaultTracerTest extends AbstractDefaultTracerTest {

@Override
Expand Down
2 changes: 1 addition & 1 deletion api/incubator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions api/testing-internal/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
* 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;

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -245,6 +257,7 @@ void noopObservableDoubleUpDownCounter_doesNotThrow() {
}

@Test
@SuppressWarnings("NullAway")
void noopBatchCallback_doesNotThrow() {
meter.batchCallback(() -> {}, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@
* 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;
import static org.assertj.core.api.Assertions.assertThatCode;

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")
Expand Down Expand Up @@ -56,6 +63,7 @@ void defaultSpanBuilderWithName() {
}

@Test
@SuppressWarnings("NullAway")
void spanContextPropagationExplicitParent() {
assertThat(
defaultTracer
Expand Down Expand Up @@ -109,6 +117,7 @@ void spanContextPropagation_fromContextThenNoParent() {
}

@Test
@SuppressWarnings("NullAway")
void doNotCrash_NoopImplementation() {
assertThatCode(
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 9ddccad

Please sign in to comment.