Convert azure sdk tests to java (#5504)
* Convert azure sdk tests to java * Better assertj
This commit is contained in:
parent
805f25868c
commit
44b04210ff
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright The OpenTelemetry Authors
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
import com.azure.core.http.policy.HttpPolicyProviders
|
|
||||||
import com.azure.core.util.Context
|
|
||||||
import com.azure.core.util.tracing.TracerProxy
|
|
||||||
import io.opentelemetry.api.trace.StatusCode
|
|
||||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
|
||||||
|
|
||||||
class AzureSdkTest extends AgentInstrumentationSpecification {
|
|
||||||
|
|
||||||
def "test helper classes injected"() {
|
|
||||||
expect:
|
|
||||||
TracerProxy.isTracingEnabled()
|
|
||||||
|
|
||||||
def list = new ArrayList()
|
|
||||||
HttpPolicyProviders.addAfterRetryPolicies(list)
|
|
||||||
|
|
||||||
list.size() == 1
|
|
||||||
list.get(0).getClass().getName() == "io.opentelemetry.javaagent.instrumentation.azurecore.v1_14.shaded" +
|
|
||||||
".com.azure.core.tracing.opentelemetry.OpenTelemetryHttpPolicy"
|
|
||||||
}
|
|
||||||
|
|
||||||
def "test span"() {
|
|
||||||
when:
|
|
||||||
Context context = TracerProxy.start("hello", Context.NONE)
|
|
||||||
TracerProxy.end(200, null, context)
|
|
||||||
|
|
||||||
then:
|
|
||||||
assertTraces(1) {
|
|
||||||
trace(0, 1) {
|
|
||||||
span(0) {
|
|
||||||
name "hello"
|
|
||||||
status StatusCode.OK
|
|
||||||
attributes {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import com.azure.core.http.policy.HttpPipelinePolicy;
|
||||||
|
import com.azure.core.http.policy.HttpPolicyProviders;
|
||||||
|
import com.azure.core.util.Context;
|
||||||
|
import com.azure.core.util.tracing.TracerProxy;
|
||||||
|
import io.opentelemetry.api.common.Attributes;
|
||||||
|
import io.opentelemetry.api.trace.SpanKind;
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
|
import io.opentelemetry.sdk.trace.data.StatusData;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
|
class AzureSdkTest {
|
||||||
|
|
||||||
|
@RegisterExtension
|
||||||
|
public static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testHelperClassesInjected() {
|
||||||
|
|
||||||
|
assertThat(TracerProxy.isTracingEnabled()).isTrue();
|
||||||
|
|
||||||
|
List<HttpPipelinePolicy> list = new ArrayList<>();
|
||||||
|
HttpPolicyProviders.addAfterRetryPolicies(list);
|
||||||
|
|
||||||
|
assertThat(list)
|
||||||
|
.satisfiesExactly(
|
||||||
|
item ->
|
||||||
|
assertThat(item.getClass().getName())
|
||||||
|
.isEqualTo(
|
||||||
|
"io.opentelemetry.javaagent.instrumentation.azurecore.v1_14.shaded"
|
||||||
|
+ ".com.azure.core.tracing.opentelemetry.OpenTelemetryHttpPolicy"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSpan() {
|
||||||
|
Context context = TracerProxy.start("hello", Context.NONE);
|
||||||
|
TracerProxy.end(200, null, context);
|
||||||
|
|
||||||
|
testing.waitAndAssertTraces(
|
||||||
|
trace ->
|
||||||
|
trace.hasSpansSatisfyingExactly(
|
||||||
|
span ->
|
||||||
|
span.hasName("hello")
|
||||||
|
.hasKind(SpanKind.INTERNAL)
|
||||||
|
.hasStatus(StatusData.ok())
|
||||||
|
.hasAttributesSatisfying(Attributes::isEmpty)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright The OpenTelemetry Authors
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
import com.azure.core.http.policy.HttpPolicyProviders
|
|
||||||
import com.azure.core.util.Context
|
|
||||||
import com.azure.core.util.tracing.TracerProxy
|
|
||||||
import io.opentelemetry.api.trace.StatusCode
|
|
||||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
|
||||||
|
|
||||||
class AzureSdkTest extends AgentInstrumentationSpecification {
|
|
||||||
|
|
||||||
def "test helper classes injected"() {
|
|
||||||
expect:
|
|
||||||
TracerProxy.isTracingEnabled()
|
|
||||||
|
|
||||||
def list = new ArrayList()
|
|
||||||
HttpPolicyProviders.addAfterRetryPolicies(list)
|
|
||||||
|
|
||||||
list.size() == 1
|
|
||||||
list.get(0).getClass().getName() == "io.opentelemetry.javaagent.instrumentation.azurecore.v1_19.shaded" +
|
|
||||||
".com.azure.core.tracing.opentelemetry.OpenTelemetryHttpPolicy"
|
|
||||||
}
|
|
||||||
|
|
||||||
def "test span"() {
|
|
||||||
when:
|
|
||||||
Context context = TracerProxy.start("hello", Context.NONE)
|
|
||||||
TracerProxy.end(200, null, context)
|
|
||||||
|
|
||||||
then:
|
|
||||||
assertTraces(1) {
|
|
||||||
trace(0, 1) {
|
|
||||||
span(0) {
|
|
||||||
name "hello"
|
|
||||||
status StatusCode.OK
|
|
||||||
attributes {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import com.azure.core.http.policy.HttpPipelinePolicy;
|
||||||
|
import com.azure.core.http.policy.HttpPolicyProviders;
|
||||||
|
import com.azure.core.util.Context;
|
||||||
|
import com.azure.core.util.tracing.TracerProxy;
|
||||||
|
import io.opentelemetry.api.common.Attributes;
|
||||||
|
import io.opentelemetry.api.trace.SpanKind;
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
|
import io.opentelemetry.sdk.trace.data.StatusData;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
|
class AzureSdkTest {
|
||||||
|
|
||||||
|
@RegisterExtension
|
||||||
|
public static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testHelperClassesInjected() {
|
||||||
|
|
||||||
|
assertThat(TracerProxy.isTracingEnabled()).isTrue();
|
||||||
|
|
||||||
|
List<HttpPipelinePolicy> list = new ArrayList<>();
|
||||||
|
HttpPolicyProviders.addAfterRetryPolicies(list);
|
||||||
|
|
||||||
|
assertThat(list)
|
||||||
|
.satisfiesExactly(
|
||||||
|
item ->
|
||||||
|
assertThat(item.getClass().getName())
|
||||||
|
.isEqualTo(
|
||||||
|
"io.opentelemetry.javaagent.instrumentation.azurecore.v1_19.shaded"
|
||||||
|
+ ".com.azure.core.tracing.opentelemetry.OpenTelemetryHttpPolicy"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSpan() {
|
||||||
|
Context context = TracerProxy.start("hello", Context.NONE);
|
||||||
|
TracerProxy.end(200, null, context);
|
||||||
|
|
||||||
|
testing.waitAndAssertTraces(
|
||||||
|
trace ->
|
||||||
|
trace.hasSpansSatisfyingExactly(
|
||||||
|
span ->
|
||||||
|
span.hasName("hello")
|
||||||
|
.hasKind(SpanKind.INTERNAL)
|
||||||
|
.hasStatus(StatusData.ok())
|
||||||
|
.hasAttributesSatisfying(Attributes::isEmpty)));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue