From 834bbf3c3029065382f983db6d3f9a3f60fc488b Mon Sep 17 00:00:00 2001 From: heyams Date: Tue, 1 Oct 2024 17:31:38 -0700 Subject: [PATCH 01/22] Convert play-ws groovy to java --- .../play-ws-common/testing/build.gradle.kts | 1 - .../main/groovy/PlayWsClientTestBase.groovy | 247 ------------------ .../groovy/PlayWsClientTestBaseBase.groovy | 119 --------- .../PlayJavaStreamedWsClientBaseTest.java | 92 +++++++ .../playws/PlayJavaWsClientBaseTest.java | 83 ++++++ .../PlayScalaStreamedWsClientBaseTest.java | 120 +++++++++ .../playws/PlayScalaWsClientBaseTest.java | 107 ++++++++ .../playws/PlayWsClientBaseTest.java | 158 +++++++++++ 8 files changed, 560 insertions(+), 367 deletions(-) delete mode 100644 instrumentation/play/play-ws/play-ws-common/testing/src/main/groovy/PlayWsClientTestBase.groovy delete mode 100644 instrumentation/play/play-ws/play-ws-common/testing/src/main/groovy/PlayWsClientTestBaseBase.groovy create mode 100644 instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java create mode 100644 instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaWsClientBaseTest.java create mode 100644 instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java create mode 100644 instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java create mode 100644 instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java diff --git a/instrumentation/play/play-ws/play-ws-common/testing/build.gradle.kts b/instrumentation/play/play-ws/play-ws-common/testing/build.gradle.kts index c6b3d498a4b4..e295ab2392a1 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/build.gradle.kts +++ b/instrumentation/play/play-ws/play-ws-common/testing/build.gradle.kts @@ -8,7 +8,6 @@ dependencies { api(project(":testing-common")) api("com.typesafe.play:play-ahc-ws-standalone_$scalaVersion:1.0.2") - implementation("org.apache.groovy:groovy") implementation("io.opentelemetry:opentelemetry-api") implementation("org.spockframework:spock-core") } diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/groovy/PlayWsClientTestBase.groovy b/instrumentation/play/play-ws/play-ws-common/testing/src/main/groovy/PlayWsClientTestBase.groovy deleted file mode 100644 index 52f47021b4d3..000000000000 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/groovy/PlayWsClientTestBase.groovy +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult -import play.libs.ws.StandaloneWSClient -import play.libs.ws.StandaloneWSRequest -import play.libs.ws.StandaloneWSResponse -import play.libs.ws.ahc.StandaloneAhcWSClient -import scala.Function1 -import scala.collection.JavaConverters -import scala.concurrent.Await -import scala.concurrent.ExecutionContext -import scala.concurrent.Future -import scala.concurrent.duration.Duration -import scala.util.Try -import spock.lang.Shared - -import java.util.concurrent.CompletionStage -import java.util.concurrent.TimeUnit - -class PlayJavaWsClientTestBase extends PlayWsClientTestBaseBase { - @Shared - StandaloneWSClient wsClient - @Shared - StandaloneWSClient wsClientWithReadTimeout - - @Override - StandaloneWSRequest buildRequest(String method, URI uri, Map headers) { - def request = getClient(uri).url(uri.toURL().toString()).setFollowRedirects(true) - headers.entrySet().each { entry -> request.addHeader(entry.getKey(), entry.getValue()) } - return request.setMethod(method) - } - - @Override - int sendRequest(StandaloneWSRequest request, String method, URI uri, Map headers) { - return request.execute().toCompletableFuture().get().status - } - - @Override - void sendRequestWithCallback(StandaloneWSRequest request, String method, URI uri, Map headers, HttpClientResult requestResult) { - request.execute().whenComplete { response, throwable -> - requestResult.complete({ response.status }, throwable) - } - } - - def getClient(URI uri) { - if (uri.toString().contains("/read-timeout")) { - return wsClientWithReadTimeout - } - return wsClient - } - - def setupSpec() { - wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer) - wsClientWithReadTimeout = new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer) - } - - def cleanupSpec() { - wsClient?.close() - wsClientWithReadTimeout?.close() - } -} - -class PlayJavaStreamedWsClientTestBase extends PlayWsClientTestBaseBase { - @Shared - StandaloneWSClient wsClient - @Shared - StandaloneWSClient wsClientWithReadTimeout - - @Override - StandaloneWSRequest buildRequest(String method, URI uri, Map headers) { - def request = getClient(uri).url(uri.toURL().toString()).setFollowRedirects(true) - headers.entrySet().each { entry -> request.addHeader(entry.getKey(), entry.getValue()) } - request.setMethod(method) - return request - } - - @Override - int sendRequest(StandaloneWSRequest request, String method, URI uri, Map headers) { - return internalSendRequest(request).toCompletableFuture().get().status - } - - @Override - void sendRequestWithCallback(StandaloneWSRequest request, String method, URI uri, Map headers, HttpClientResult requestResult) { - internalSendRequest(request).whenComplete { response, throwable -> - requestResult.complete({ response.status }, throwable?.getCause()) - } - } - - private CompletionStage internalSendRequest(StandaloneWSRequest request) { - def stream = request.stream() - // The status can be ready before the body so explicitly call wait for body to be ready - return stream - .thenCompose { StandaloneWSResponse response -> - response.getBodyAsSource().runFold("", { acc, out -> "" }, materializer) - } - .thenCombine(stream) { String body, StandaloneWSResponse response -> - response - } - } - - def getClient(URI uri) { - if (uri.toString().contains("/read-timeout")) { - return wsClientWithReadTimeout - } - return wsClient - } - - def setupSpec() { - wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer) - wsClientWithReadTimeout = new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer) - } - - def cleanupSpec() { - wsClient?.close() - wsClientWithReadTimeout?.close() - } -} - -class PlayScalaWsClientTestBase extends PlayWsClientTestBaseBase { - @Shared - play.api.libs.ws.StandaloneWSClient wsClient - @Shared - play.api.libs.ws.StandaloneWSClient wsClientWithReadTimeout - - @Override - play.api.libs.ws.StandaloneWSRequest buildRequest(String method, URI uri, Map headers) { - return getClient(uri).url(uri.toURL().toString()) - .withMethod(method) - .withFollowRedirects(true) - .withHttpHeaders(JavaConverters.mapAsScalaMap(headers).toSeq()) - } - - @Override - int sendRequest(play.api.libs.ws.StandaloneWSRequest request, String method, URI uri, Map headers) { - def futureResponse = request.execute() - Await.ready(futureResponse, Duration.apply(10, TimeUnit.SECONDS)) - def value = futureResponse.value().get() - if (value.isSuccess()) { - return value.get().status() - } - throw value.failed().get() - } - - @Override - void sendRequestWithCallback(play.api.libs.ws.StandaloneWSRequest request, String method, URI uri, Map headers, HttpClientResult requestResult) { - request.execute().onComplete(new Function1, Void>() { - @Override - Void apply(Try response) { - if (response.isSuccess()) { - requestResult.complete(response.get().status()) - } else { - requestResult.complete(response.failed().get()) - } - return null - } - }, ExecutionContext.global()) - } - - def getClient(URI uri) { - if (uri.toString().contains("/read-timeout")) { - return wsClientWithReadTimeout - } - return wsClient - } - - def setupSpec() { - wsClient = new play.api.libs.ws.ahc.StandaloneAhcWSClient(asyncHttpClient, materializer) - wsClientWithReadTimeout = new play.api.libs.ws.ahc.StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer) - } - - def cleanupSpec() { - wsClient?.close() - wsClientWithReadTimeout?.close() - } -} - -class PlayScalaStreamedWsClientTestBase extends PlayWsClientTestBaseBase { - @Shared - play.api.libs.ws.StandaloneWSClient wsClient - @Shared - play.api.libs.ws.StandaloneWSClient wsClientWithReadTimeout - - @Override - play.api.libs.ws.StandaloneWSRequest buildRequest(String method, URI uri, Map headers) { - return getClient(uri).url(uri.toURL().toString()) - .withMethod(method) - .withFollowRedirects(true) - .withHttpHeaders(JavaConverters.mapAsScalaMap(headers).toSeq()) - } - - @Override - int sendRequest(play.api.libs.ws.StandaloneWSRequest request, String method, URI uri, Map headers) { - Await.result(internalSendRequest(request), Duration.apply(10, TimeUnit.SECONDS)).status() - } - - @Override - void sendRequestWithCallback(play.api.libs.ws.StandaloneWSRequest request, String method, URI uri, Map headers, HttpClientResult requestResult) { - internalSendRequest(request).onComplete(new Function1, Void>() { - @Override - Void apply(Try response) { - if (response.isSuccess()) { - requestResult.complete(response.get().status()) - } else { - requestResult.complete(response.failed().get()) - } - return null - } - }, ExecutionContext.global()) - } - - private Future internalSendRequest(play.api.libs.ws.StandaloneWSRequest request) { - Future futureResponse = request.stream() - // The status can be ready before the body so explicitly call wait for body to be ready - Future bodyResponse = futureResponse.flatMap(new Function1>() { - @Override - Future apply(play.api.libs.ws.StandaloneWSResponse wsResponse) { - return wsResponse.bodyAsSource().runFold("", { acc, out -> "" }, materializer) - } - }, ExecutionContext.global()) - return bodyResponse.flatMap(new Function1>() { - @Override - Future apply(String v1) { - return futureResponse - } - }, ExecutionContext.global()) - } - - def getClient(URI uri) { - if (uri.toString().contains("/read-timeout")) { - return wsClientWithReadTimeout - } - return wsClient - } - - def setupSpec() { - wsClient = new play.api.libs.ws.ahc.StandaloneAhcWSClient(asyncHttpClient, materializer) - wsClientWithReadTimeout = new play.api.libs.ws.ahc.StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer) - } - - def cleanupSpec() { - wsClient?.close() - wsClientWithReadTimeout?.close() - } -} diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/groovy/PlayWsClientTestBaseBase.groovy b/instrumentation/play/play-ws/play-ws-common/testing/src/main/groovy/PlayWsClientTestBaseBase.groovy deleted file mode 100644 index 20df768f7b10..000000000000 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/groovy/PlayWsClientTestBaseBase.groovy +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import akka.actor.ActorSystem -import akka.stream.ActorMaterializer -import akka.stream.ActorMaterializerSettings -import io.opentelemetry.api.common.AttributeKey -import io.opentelemetry.instrumentation.test.AgentTestTrait -import io.opentelemetry.instrumentation.test.base.HttpClientTest -import io.opentelemetry.semconv.ServerAttributes -import io.opentelemetry.semconv.NetworkAttributes -import play.shaded.ahc.io.netty.resolver.InetNameResolver -import play.shaded.ahc.io.netty.util.concurrent.EventExecutor -import play.shaded.ahc.io.netty.util.concurrent.ImmediateEventExecutor -import play.shaded.ahc.io.netty.util.concurrent.Promise -import play.shaded.ahc.org.asynchttpclient.AsyncHttpClient -import play.shaded.ahc.org.asynchttpclient.AsyncHttpClientConfig -import play.shaded.ahc.org.asynchttpclient.DefaultAsyncHttpClient -import play.shaded.ahc.org.asynchttpclient.DefaultAsyncHttpClientConfig -import play.shaded.ahc.org.asynchttpclient.RequestBuilderBase -import spock.lang.Shared - -abstract class PlayWsClientTestBaseBase extends HttpClientTest implements AgentTestTrait { - @Shared - ActorSystem system - - @Shared - AsyncHttpClient asyncHttpClient - - @Shared - AsyncHttpClient asyncHttpClientWithReadTimeout - - @Shared - ActorMaterializer materializer - - def setupSpec() { - String name = "play-ws" - system = ActorSystem.create(name) - ActorMaterializerSettings settings = ActorMaterializerSettings.create(system) - materializer = ActorMaterializer.create(settings, system, name) - - // Replace dns name resolver with custom implementation that returns only once address for each - // host. This is needed for "connection error dropped request" because in case of connection - // failure ahc will try the next address which isn't necessary for this test. - RequestBuilderBase.DEFAULT_NAME_RESOLVER = new CustomNameResolver(ImmediateEventExecutor.INSTANCE) - - asyncHttpClient = createClient(false) - asyncHttpClientWithReadTimeout = createClient(true) - } - - def createClient(boolean readTimeout) { - DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder() - .setMaxRequestRetry(0) - .setShutdownQuietPeriod(0) - .setShutdownTimeout(0) - .setMaxRedirects(3) - .setConnectTimeout(CONNECT_TIMEOUT_MS) - - if (readTimeout) { - builder.setReadTimeout(READ_TIMEOUT_MS) - } - - AsyncHttpClientConfig asyncHttpClientConfig =builder.build() - return new DefaultAsyncHttpClient(asyncHttpClientConfig) - } - - def cleanupSpec() { - system?.terminate() - asyncHttpClient?.close() - asyncHttpClientWithReadTimeout?.close() - } - - @Override - Integer responseCodeOnRedirectError() { - // apparently play ws does not report the 302 status code - null - } - - @Override - int maxRedirects() { - 3 - } - - @Override - Set> httpAttributes(URI uri) { - def attributes = super.httpAttributes(uri) - attributes.remove(NetworkAttributes.NETWORK_PROTOCOL_VERSION) - if (uri.toString().endsWith("/circular-redirect")) { - attributes.remove(ServerAttributes.SERVER_ADDRESS) - attributes.remove(ServerAttributes.SERVER_PORT) - } - return attributes - } -} - -class CustomNameResolver extends InetNameResolver { - CustomNameResolver(EventExecutor executor) { - super(executor) - } - - protected void doResolve(String inetHost, Promise promise) throws Exception { - try { - promise.setSuccess(InetAddress.getByName(inetHost)) - } catch (UnknownHostException exception) { - promise.setFailure(exception) - } - } - - protected void doResolveAll(String inetHost, Promise> promise) throws Exception { - try { - // default implementation calls InetAddress.getAllByName - promise.setSuccess(Collections.singletonList(InetAddress.getByName(inetHost))) - } catch (UnknownHostException exception) { - promise.setFailure(exception) - } - } -} diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java new file mode 100644 index 000000000000..a7473a293629 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java @@ -0,0 +1,92 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws; + +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; +import java.io.IOException; +import java.net.URI; +import java.util.Map; +import java.util.concurrent.CompletionStage; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import play.libs.ws.StandaloneWSClient; +import play.libs.ws.StandaloneWSRequest; +import play.libs.ws.StandaloneWSResponse; +import play.libs.ws.ahc.StandaloneAhcWSClient; + +class PlayJavaStreamedWsClientBaseTest extends PlayWsClientBaseTest { + + private static StandaloneWSClient wsClient; + private static StandaloneWSClient wsClientWithReadTimeout; + + @BeforeEach + void setup() { + wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer); + wsClientWithReadTimeout = + new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer); + autoCleanup.deferCleanup(wsClient); + autoCleanup.deferCleanup(wsClientWithReadTimeout); + } + + @AfterEach + public void tearDown() throws IOException { + if (wsClient != null) { + wsClient.close(); + } + if (wsClientWithReadTimeout != null) { + wsClientWithReadTimeout.close(); + } + } + + @Override + public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) { + StandaloneWSRequest request = getClient(uri).url(uri.toString()).setFollowRedirects(true); + headers.forEach(request::addHeader); + request.setMethod(method); + return request; + } + + @Override + public int sendRequest( + StandaloneWSRequest request, String method, URI uri, Map headers) + throws Exception { + return internalSendRequest(request).toCompletableFuture().get().getStatus(); + } + + @Override + public void sendRequestWithCallback( + StandaloneWSRequest request, + String method, + URI uri, + Map headers, + HttpClientResult requestResult) { + internalSendRequest(request) + .whenComplete( + (response, throwable) -> { + if (throwable != null) { + requestResult.complete(throwable.getCause()); + } else { + requestResult.complete(response.getStatus()); + } + }); + } + + private CompletionStage internalSendRequest(StandaloneWSRequest request) { + CompletionStage stream = request.stream(); + // The status can be ready before the body so explicitly call wait for body to be ready + return stream + .thenCompose( + response -> response.getBodyAsSource().runFold("", (acc, out) -> "", materializer)) + .thenCombine(stream, (body, response) -> response); + } + + private StandaloneWSClient getClient(URI uri) { + if (uri.toString().contains("/read-timeout")) { + return wsClientWithReadTimeout; + } + return wsClient; + } +} diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaWsClientBaseTest.java new file mode 100644 index 000000000000..d394131e2cb3 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaWsClientBaseTest.java @@ -0,0 +1,83 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws; + +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; +import java.io.IOException; +import java.net.URI; +import java.util.Map; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import play.libs.ws.StandaloneWSClient; +import play.libs.ws.StandaloneWSRequest; +import play.libs.ws.ahc.StandaloneAhcWSClient; + +public class PlayJavaWsClientBaseTest extends PlayWsClientBaseTest { + + private static StandaloneWSClient wsClient; + private static StandaloneWSClient wsClientWithReadTimeout; + + @BeforeEach + void setup() { + super.setup(); + wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer); + wsClientWithReadTimeout = + new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer); + autoCleanup.deferCleanup(wsClient); + autoCleanup.deferCleanup(wsClientWithReadTimeout); + } + + @AfterEach + void tearDown() throws IOException { + if (wsClient != null) { + wsClient.close(); + } + if (wsClientWithReadTimeout != null) { + wsClientWithReadTimeout.close(); + } + super.tearDown(); + } + + @Override + public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) { + StandaloneWSRequest request = getClient(uri).url(uri.toString()).setFollowRedirects(true); + headers.forEach(request::addHeader); + return request.setMethod(method); + } + + @Override + public int sendRequest( + StandaloneWSRequest request, String method, URI uri, Map headers) + throws Exception { + return request.execute().toCompletableFuture().get().getStatus(); + } + + @Override + public void sendRequestWithCallback( + StandaloneWSRequest request, + String method, + URI uri, + Map headers, + HttpClientResult requestResult) { + request + .execute() + .whenComplete( + (response, throwable) -> { + if (throwable != null) { + requestResult.complete(throwable); + } else { + requestResult.complete(response.getStatus()); + } + }); + } + + private StandaloneWSClient getClient(URI uri) { + if (uri.toString().contains("/read-timeout")) { + return wsClientWithReadTimeout; + } + return wsClient; + } +} diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java new file mode 100644 index 000000000000..4272684c7e38 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java @@ -0,0 +1,120 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws; + +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; +import java.io.IOException; +import java.net.URI; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import play.api.libs.ws.StandaloneWSClient; +import play.api.libs.ws.StandaloneWSRequest; +import play.api.libs.ws.StandaloneWSResponse; +import play.api.libs.ws.ahc.StandaloneAhcWSClient; +import scala.Function1; +import scala.collection.JavaConverters; +import scala.concurrent.Await; +import scala.concurrent.ExecutionContext; +import scala.concurrent.Future; +import scala.concurrent.duration.Duration; +import scala.util.Try; + +public class PlayScalaStreamedWsClientBaseTest extends PlayWsClientBaseTest { + + private static StandaloneWSClient wsClient; + private static StandaloneWSClient wsClientWithReadTimeout; + + @BeforeEach + void setup() { + wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer); + wsClientWithReadTimeout = + new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer); + autoCleanup.deferCleanup(wsClient); + autoCleanup.deferCleanup(wsClientWithReadTimeout); + } + + @AfterEach + void tearDown() throws IOException { + if (wsClient != null) { + wsClient.close(); + } + if (wsClientWithReadTimeout != null) { + wsClientWithReadTimeout.close(); + } + } + + @Override + public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) + throws Exception { + return getClient(uri) + .url(uri.toURL().toString()) + .withMethod(method) + .withFollowRedirects(true) + .withHttpHeaders(JavaConverters.mapAsScalaMap(headers).toSeq()); + } + + @Override + public int sendRequest( + StandaloneWSRequest request, String method, URI uri, Map headers) + throws Exception { + return Await.result(internalSendRequest(request), Duration.apply(10, TimeUnit.SECONDS)) + .status(); + } + + @Override + public void sendRequestWithCallback( + StandaloneWSRequest request, + String method, + URI uri, + Map headers, + HttpClientResult requestResult) { + internalSendRequest(request) + .onComplete( + new Function1, Void>() { + @Override + public Void apply(Try response) { + if (response.isSuccess()) { + requestResult.complete(response.get().status()); + } else { + requestResult.complete(response.failed().get()); + } + return null; + } + }, + ExecutionContext.global()); + } + + private Future internalSendRequest(StandaloneWSRequest request) { + Future futureResponse = request.stream(); + // The status can be ready before the body so explicitly call wait for body to be ready + Future bodyResponse = + futureResponse.flatMap( + new Function1>() { + @Override + public Future apply(StandaloneWSResponse wsResponse) { + return wsResponse.bodyAsSource().runFold("", (acc, out) -> "", materializer); + } + }, + ExecutionContext.global()); + return bodyResponse.flatMap( + new Function1>() { + @Override + public Future apply(String v1) { + return futureResponse; + } + }, + ExecutionContext.global()); + } + + private StandaloneWSClient getClient(URI uri) { + if (uri.toString().contains("/read-timeout")) { + return wsClientWithReadTimeout; + } + return wsClient; + } +} diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java new file mode 100644 index 000000000000..b6eaff937659 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java @@ -0,0 +1,107 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws; + +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import play.api.libs.ws.StandaloneWSClient; +import play.api.libs.ws.StandaloneWSRequest; +import play.api.libs.ws.StandaloneWSResponse; +import play.api.libs.ws.ahc.StandaloneAhcWSClient; +import scala.Function1; +import scala.collection.JavaConverters; +import scala.concurrent.Await; +import scala.concurrent.ExecutionContext; +import scala.concurrent.Future; +import scala.concurrent.duration.Duration; +import scala.util.Try; + +public class PlayScalaWsClientBaseTest extends PlayWsClientBaseTest { + + private static StandaloneWSClient wsClient; + private static StandaloneWSClient wsClientWithReadTimeout; + + @BeforeEach + void setup() { + wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer); + wsClientWithReadTimeout = + new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer); + autoCleanup.deferCleanup(wsClient); + autoCleanup.deferCleanup(wsClientWithReadTimeout); + } + + @AfterEach + void tearDown() throws IOException { + if (wsClient != null) { + wsClient.close(); + } + if (wsClientWithReadTimeout != null) { + wsClientWithReadTimeout.close(); + } + } + + @Override + public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) + throws MalformedURLException { + return getClient(uri) + .url(uri.toURL().toString()) + .withMethod(method) + .withFollowRedirects(true) + .withHttpHeaders(JavaConverters.mapAsScalaMap(headers).toSeq()); + } + + @Override + public int sendRequest( + StandaloneWSRequest request, String method, URI uri, Map headers) + throws InterruptedException, TimeoutException { + Future futureResponse = request.execute(); + Await.ready(futureResponse, Duration.apply(10, TimeUnit.SECONDS)); + Try value = futureResponse.value().get(); + if (value.isSuccess()) { + return value.get().status(); + } + // Catch the Throwable and rethrow it as an IllegalStateException + throw new IllegalStateException(value.failed().get()); + } + + @Override + public void sendRequestWithCallback( + StandaloneWSRequest request, + String method, + URI uri, + Map headers, + HttpClientResult requestResult) { + request + .execute() + .onComplete( + new Function1, Void>() { + @Override + public Void apply(Try response) { + if (response.isSuccess()) { + requestResult.complete(response.get().status()); + } else { + requestResult.complete(response.failed().get()); + } + return null; + } + }, + ExecutionContext.global()); + } + + private StandaloneWSClient getClient(URI uri) { + if (uri.toString().contains("/read-timeout")) { + return wsClientWithReadTimeout; + } + return wsClient; + } +} diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java new file mode 100644 index 000000000000..886fd224e267 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java @@ -0,0 +1,158 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws; + +import akka.actor.ActorSystem; +import akka.stream.ActorMaterializer; +import akka.stream.ActorMaterializerSettings; +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; +import io.opentelemetry.semconv.NetworkAttributes; +import io.opentelemetry.semconv.ServerAttributes; +import java.io.IOException; +import java.net.InetAddress; +import java.net.URI; +import java.net.UnknownHostException; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; +import play.shaded.ahc.io.netty.resolver.InetNameResolver; +import play.shaded.ahc.io.netty.util.concurrent.EventExecutor; +import play.shaded.ahc.io.netty.util.concurrent.ImmediateEventExecutor; +import play.shaded.ahc.io.netty.util.concurrent.Promise; +import play.shaded.ahc.org.asynchttpclient.AsyncHttpClient; +import play.shaded.ahc.org.asynchttpclient.AsyncHttpClientConfig; +import play.shaded.ahc.org.asynchttpclient.DefaultAsyncHttpClient; +import play.shaded.ahc.org.asynchttpclient.DefaultAsyncHttpClientConfig; +import play.shaded.ahc.org.asynchttpclient.RequestBuilderBase; + +abstract class PlayWsClientBaseTest extends AbstractHttpClientTest { + + @RegisterExtension + static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent(); + + static final AutoCleanupExtension autoCleanup = AutoCleanupExtension.create(); + + private static ActorSystem system; + protected static AsyncHttpClient asyncHttpClient; + protected static AsyncHttpClient asyncHttpClientWithReadTimeout; + protected static ActorMaterializer materializer; + + @BeforeEach + void setup() { + String name = "play-ws"; + system = ActorSystem.create(name); + materializer = ActorMaterializer.create(ActorMaterializerSettings.create(system), system, name); + + // Replace dns name resolver with custom implementation that returns only once address for each + // host. This is needed for "connection error dropped request" because in case of connection + // failure ahc will try the next address which isn't necessary for this test. + RequestBuilderBase.DEFAULT_NAME_RESOLVER = + new CustomNameResolver(ImmediateEventExecutor.INSTANCE); + + asyncHttpClient = createClient(false); + asyncHttpClientWithReadTimeout = createClient(true); + autoCleanup.deferCleanup(asyncHttpClient); + autoCleanup.deferCleanup(asyncHttpClientWithReadTimeout); + } + + @AfterEach + void tearDown() throws IOException { + if (system != null) { + system.terminate(); + } + if (asyncHttpClient != null) { + asyncHttpClient.close(); + } + if (asyncHttpClientWithReadTimeout != null) { + asyncHttpClientWithReadTimeout.close(); + } + } + + @Override + public REQUEST buildRequest(String method, URI uri, Map headers) + throws Exception { + return null; + } + + @Override + public int sendRequest(REQUEST request, String method, URI uri, Map headers) + throws Exception { + return 0; + } + + @Override + protected void configure(HttpClientTestOptions.Builder optionsBuilder) { + super.configure(optionsBuilder); + // apparently play ws does not report the 302 status code + optionsBuilder.setResponseCodeOnRedirectError(null); + optionsBuilder.setMaxRedirects(3); + optionsBuilder.setHttpAttributes( + uri -> { + Set> attributes = + new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); + attributes.remove(NetworkAttributes.NETWORK_PROTOCOL_VERSION); + if (uri.toString().endsWith("/circular-redirect")) { + attributes.remove(ServerAttributes.SERVER_ADDRESS); + attributes.remove(ServerAttributes.SERVER_PORT); + } + return attributes; + }); + } + + private AsyncHttpClient createClient(boolean readTimeout) { + DefaultAsyncHttpClientConfig.Builder builder = + new DefaultAsyncHttpClientConfig.Builder() + .setMaxRequestRetry(0) + .setShutdownQuietPeriod(0) + .setShutdownTimeout(0) + .setMaxRedirects(3) + .setConnectTimeout(5000); + + if (readTimeout) { + builder.setReadTimeout(2000); + } + + AsyncHttpClientConfig asyncHttpClientConfig = builder.build(); + return new DefaultAsyncHttpClient(asyncHttpClientConfig); + } +} + +class CustomNameResolver extends InetNameResolver { + + public CustomNameResolver(EventExecutor executor) { + super(executor); + } + + @Override + protected void doResolve(String inetHost, Promise promise) throws Exception { + try { + promise.setSuccess(InetAddress.getByName(inetHost)); + } catch (UnknownHostException exception) { + promise.setFailure(exception); + } + } + + @Override + protected void doResolveAll(String inetHost, Promise> promise) + throws Exception { + try { + // default implementation calls InetAddress.getAllByName + promise.setSuccess(Collections.singletonList(InetAddress.getByName(inetHost))); + } catch (UnknownHostException exception) { + promise.setFailure(exception); + } + } +} From 452f827c9e2c453f76e510239cc2ec9cfa4d6eb7 Mon Sep 17 00:00:00 2001 From: heyams Date: Wed, 2 Oct 2024 10:17:43 -0700 Subject: [PATCH 02/22] Fix errorprone --- .../playws/PlayJavaStreamedWsClientBaseTest.java | 6 +++++- .../instrumentation/playws/PlayJavaWsClientBaseTest.java | 2 ++ .../playws/PlayScalaStreamedWsClientBaseTest.java | 4 ++++ .../instrumentation/playws/PlayScalaWsClientBaseTest.java | 4 ++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java index a7473a293629..a4582f1b2690 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java @@ -23,7 +23,9 @@ class PlayJavaStreamedWsClientBaseTest extends PlayWsClientBaseTest Date: Wed, 2 Oct 2024 10:53:59 -0700 Subject: [PATCH 03/22] Fix --- .../playws/PlayJavaStreamedWsClientBaseTest.java | 5 +++-- .../instrumentation/playws/PlayJavaWsClientBaseTest.java | 5 +++-- .../playws/PlayScalaStreamedWsClientBaseTest.java | 2 +- .../instrumentation/playws/PlayScalaWsClientBaseTest.java | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java index a4582f1b2690..0b67f54761e9 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java @@ -10,6 +10,7 @@ import java.net.URI; import java.util.Map; import java.util.concurrent.CompletionStage; +import java.util.concurrent.ExecutionException; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import play.libs.ws.StandaloneWSClient; @@ -56,7 +57,7 @@ public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) - throws Exception { + throws ExecutionException, InterruptedException { return internalSendRequest(request).toCompletableFuture().get().getStatus(); } @@ -87,7 +88,7 @@ private CompletionStage internalSendRequest(StandaloneWSRe .thenCombine(stream, (body, response) -> response); } - private StandaloneWSClient getClient(URI uri) { + private static StandaloneWSClient getClient(URI uri) { if (uri.toString().contains("/read-timeout")) { return wsClientWithReadTimeout; } diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaWsClientBaseTest.java index 8503a38e75bb..c534ada973b2 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaWsClientBaseTest.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.net.URI; import java.util.Map; +import java.util.concurrent.ExecutionException; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import play.libs.ws.StandaloneWSClient; @@ -53,7 +54,7 @@ public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) - throws Exception { + throws ExecutionException, InterruptedException { return request.execute().toCompletableFuture().get().getStatus(); } @@ -76,7 +77,7 @@ public void sendRequestWithCallback( }); } - private StandaloneWSClient getClient(URI uri) { + private static StandaloneWSClient getClient(URI uri) { if (uri.toString().contains("/read-timeout")) { return wsClientWithReadTimeout; } diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java index e1b37dddcad9..04093745fb75 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java @@ -115,7 +115,7 @@ public Future apply(String v1) { ExecutionContext.global()); } - private StandaloneWSClient getClient(URI uri) { + private static StandaloneWSClient getClient(URI uri) { if (uri.toString().contains("/read-timeout")) { return wsClientWithReadTimeout; } diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java index 4eaaa55f3225..56b0eb9568ce 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java @@ -102,7 +102,7 @@ public Void apply(Try response) { ExecutionContext.global()); } - private StandaloneWSClient getClient(URI uri) { + private static StandaloneWSClient getClient(URI uri) { if (uri.toString().contains("/read-timeout")) { return wsClientWithReadTimeout; } From 7110f1112802b68852f1717cd30cca93b3c845c8 Mon Sep 17 00:00:00 2001 From: heyams Date: Wed, 2 Oct 2024 11:12:13 -0700 Subject: [PATCH 04/22] Fix --- .../playws/PlayJavaStreamedWsClientBaseTest.java | 2 +- .../playws/PlayScalaStreamedWsClientBaseTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java index 0b67f54761e9..444fce39db0e 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java @@ -79,7 +79,7 @@ public void sendRequestWithCallback( }); } - private CompletionStage internalSendRequest(StandaloneWSRequest request) { + private static CompletionStage internalSendRequest(StandaloneWSRequest request) { CompletionStage stream = request.stream(); // The status can be ready before the body so explicitly call wait for body to be ready return stream diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java index 04093745fb75..8c589b23714a 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java @@ -93,7 +93,7 @@ public Void apply(Try response) { ExecutionContext.global()); } - private Future internalSendRequest(StandaloneWSRequest request) { + private static Future internalSendRequest(StandaloneWSRequest request) { Future futureResponse = request.stream(); // The status can be ready before the body so explicitly call wait for body to be ready Future bodyResponse = From 700e2db082825d1cd7f0b95b1335b42a340b8448 Mon Sep 17 00:00:00 2001 From: heyams Date: Wed, 2 Oct 2024 11:20:52 -0700 Subject: [PATCH 05/22] Update --- .../src/test/groovy/PlayWsClientTest.groovy | 12 ------------ .../playws/v2_1/PlayWsClientTest.java | 19 +++++++++++++++++++ .../PlayJavaStreamedWsClientBaseTest.java | 5 +++-- 3 files changed, 22 insertions(+), 14 deletions(-) delete mode 100644 instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/groovy/PlayWsClientTest.groovy create mode 100644 instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientTest.java diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/groovy/PlayWsClientTest.groovy b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/groovy/PlayWsClientTest.groovy deleted file mode 100644 index 0e20a872adf8..000000000000 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/groovy/PlayWsClientTest.groovy +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -class PlayJavaWsClientTest extends PlayJavaWsClientTestBase {} - -class PlayJavaStreamedWsClientTest extends PlayJavaStreamedWsClientTestBase {} - -class PlayScalaWsClientTest extends PlayScalaWsClientTestBase {} - -class PlayScalaStreamedWsClientTest extends PlayScalaStreamedWsClientTestBase {} diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientTest.java new file mode 100644 index 000000000000..c5c4e7aaa8f2 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientTest.java @@ -0,0 +1,19 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_1; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaStreamedWsClientBaseTest; +import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaWsClientBaseTest; +import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaStreamedWsClientBaseTest; +import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaWsClientBaseTest; + +class PlayJavaWsClientTest extends PlayJavaWsClientBaseTest {} + +class PlayJavaStreamedWsClientTest extends PlayJavaStreamedWsClientBaseTest {} + +class PlayScalaWsClientTest extends PlayScalaWsClientBaseTest {} + +class PlayScalaStreamedWsClientTest extends PlayScalaStreamedWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java index 444fce39db0e..1f0552d15ae9 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java @@ -18,7 +18,7 @@ import play.libs.ws.StandaloneWSResponse; import play.libs.ws.ahc.StandaloneAhcWSClient; -class PlayJavaStreamedWsClientBaseTest extends PlayWsClientBaseTest { +public class PlayJavaStreamedWsClientBaseTest extends PlayWsClientBaseTest { private static StandaloneWSClient wsClient; private static StandaloneWSClient wsClientWithReadTimeout; @@ -79,7 +79,8 @@ public void sendRequestWithCallback( }); } - private static CompletionStage internalSendRequest(StandaloneWSRequest request) { + private static CompletionStage internalSendRequest( + StandaloneWSRequest request) { CompletionStage stream = request.stream(); // The status can be ready before the body so explicitly call wait for body to be ready return stream From 584db50d8bc9d92a82dade76b0a018fe3ad88a5b Mon Sep 17 00:00:00 2001 From: heyams Date: Wed, 2 Oct 2024 11:25:45 -0700 Subject: [PATCH 06/22] More update --- .../src/test/groovy/PlayWsClientTest.groovy | 12 ------------ .../playws/v2_0/PlayWsClientTest.java | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 12 deletions(-) delete mode 100644 instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/groovy/PlayWsClientTest.groovy create mode 100644 instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayWsClientTest.java diff --git a/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/groovy/PlayWsClientTest.groovy b/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/groovy/PlayWsClientTest.groovy deleted file mode 100644 index 0e20a872adf8..000000000000 --- a/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/groovy/PlayWsClientTest.groovy +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -class PlayJavaWsClientTest extends PlayJavaWsClientTestBase {} - -class PlayJavaStreamedWsClientTest extends PlayJavaStreamedWsClientTestBase {} - -class PlayScalaWsClientTest extends PlayScalaWsClientTestBase {} - -class PlayScalaStreamedWsClientTest extends PlayScalaStreamedWsClientTestBase {} diff --git a/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayWsClientTest.java new file mode 100644 index 000000000000..b983bf15dda5 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayWsClientTest.java @@ -0,0 +1,19 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_0; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaStreamedWsClientBaseTest; +import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaWsClientBaseTest; +import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaStreamedWsClientBaseTest; +import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaWsClientBaseTest; + +class PlayJavaWsClientTest extends PlayJavaWsClientBaseTest {} + +class PlayJavaStreamedWsClientTest extends PlayJavaStreamedWsClientBaseTest {} + +class PlayScalaWsClientTest extends PlayScalaWsClientBaseTest {} + +class PlayScalaStreamedWsClientTest extends PlayScalaStreamedWsClientBaseTest {} From 69272df972fce76799ac5e88a63b3e7fba4646e9 Mon Sep 17 00:00:00 2001 From: heyams Date: Wed, 2 Oct 2024 11:37:31 -0700 Subject: [PATCH 07/22] Update --- .../src/test/groovy/PlayWsClientTest.groovy | 12 ------ .../playws/v1_0/PlayWsClientTest.java | 19 +++++++++ .../playws/PlayWsClientBaseTest.java | 42 +++++++++---------- 3 files changed, 40 insertions(+), 33 deletions(-) delete mode 100644 instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/groovy/PlayWsClientTest.groovy create mode 100644 instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayWsClientTest.java diff --git a/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/groovy/PlayWsClientTest.groovy b/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/groovy/PlayWsClientTest.groovy deleted file mode 100644 index 0e20a872adf8..000000000000 --- a/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/groovy/PlayWsClientTest.groovy +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -class PlayJavaWsClientTest extends PlayJavaWsClientTestBase {} - -class PlayJavaStreamedWsClientTest extends PlayJavaStreamedWsClientTestBase {} - -class PlayScalaWsClientTest extends PlayScalaWsClientTestBase {} - -class PlayScalaStreamedWsClientTest extends PlayScalaStreamedWsClientTestBase {} diff --git a/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayWsClientTest.java b/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayWsClientTest.java new file mode 100644 index 000000000000..afab45905b10 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayWsClientTest.java @@ -0,0 +1,19 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v1_0; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaStreamedWsClientBaseTest; +import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaWsClientBaseTest; +import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaStreamedWsClientBaseTest; +import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaWsClientBaseTest; + +class PlayJavaWsClientTest extends PlayJavaWsClientBaseTest {} + +class PlayJavaStreamedWsClientTest extends PlayJavaStreamedWsClientBaseTest {} + +class PlayScalaWsClientTest extends PlayScalaWsClientBaseTest {} + +class PlayScalaStreamedWsClientTest extends PlayScalaStreamedWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java index 886fd224e267..b74f7d4dd43f 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java @@ -112,7 +112,7 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { }); } - private AsyncHttpClient createClient(boolean readTimeout) { + private static AsyncHttpClient createClient(boolean readTimeout) { DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder() .setMaxRequestRetry(0) @@ -128,31 +128,31 @@ private AsyncHttpClient createClient(boolean readTimeout) { AsyncHttpClientConfig asyncHttpClientConfig = builder.build(); return new DefaultAsyncHttpClient(asyncHttpClientConfig); } -} -class CustomNameResolver extends InetNameResolver { + private static class CustomNameResolver extends InetNameResolver { - public CustomNameResolver(EventExecutor executor) { - super(executor); - } + public CustomNameResolver(EventExecutor executor) { + super(executor); + } - @Override - protected void doResolve(String inetHost, Promise promise) throws Exception { - try { - promise.setSuccess(InetAddress.getByName(inetHost)); - } catch (UnknownHostException exception) { - promise.setFailure(exception); + @Override + protected void doResolve(String inetHost, Promise promise) throws Exception { + try { + promise.setSuccess(InetAddress.getByName(inetHost)); + } catch (UnknownHostException exception) { + promise.setFailure(exception); + } } - } - @Override - protected void doResolveAll(String inetHost, Promise> promise) - throws Exception { - try { - // default implementation calls InetAddress.getAllByName - promise.setSuccess(Collections.singletonList(InetAddress.getByName(inetHost))); - } catch (UnknownHostException exception) { - promise.setFailure(exception); + @Override + protected void doResolveAll(String inetHost, Promise> promise) + throws Exception { + try { + // default implementation calls InetAddress.getAllByName + promise.setSuccess(Collections.singletonList(InetAddress.getByName(inetHost))); + } catch (UnknownHostException exception) { + promise.setFailure(exception); + } } } } From 1977a57ec0d800cfd30b5ffae5cf9494801d9785 Mon Sep 17 00:00:00 2001 From: heyams Date: Wed, 2 Oct 2024 15:00:12 -0700 Subject: [PATCH 08/22] Fix sytle one top level class --- .../v1_0/PlayJavaStreamedWsClientTest.java | 10 ++++++++++ .../playws/v1_0/PlayJavaWsClientTest.java | 10 ++++++++++ .../v1_0/PlayScalaStreamedWsClientTest.java | 10 ++++++++++ .../playws/v1_0/PlayScalaWsClientTest.java | 10 ++++++++++ .../playws/v1_0/PlayWsClientTest.java | 19 ------------------- .../v2_0/PlayJavaStreamedWsClientTest.java | 10 ++++++++++ .../playws/v2_0/PlayJavaWsClientTest.java | 10 ++++++++++ .../v2_0/PlayScalaStreamedWsClientTest.java | 10 ++++++++++ .../playws/v2_0/PlayScalaWsClientTest.java | 10 ++++++++++ .../playws/v2_0/PlayWsClientTest.java | 19 ------------------- .../v2_1/PlayJavaStreamedWsClientTest.java | 10 ++++++++++ .../playws/v2_1/PlayJavaWsClientTest.java | 10 ++++++++++ .../v2_1/PlayScalaStreamedWsClientTest.java | 10 ++++++++++ .../playws/v2_1/PlayScalaWsClientTest.java | 10 ++++++++++ .../playws/v2_1/PlayWsClientTest.java | 19 ------------------- 15 files changed, 120 insertions(+), 57 deletions(-) create mode 100644 instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayJavaStreamedWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayJavaWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayScalaStreamedWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayScalaWsClientTest.java delete mode 100644 instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayJavaStreamedWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayJavaWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayScalaStreamedWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayScalaWsClientTest.java delete mode 100644 instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java delete mode 100644 instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientTest.java diff --git a/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayJavaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayJavaStreamedWsClientTest.java new file mode 100644 index 000000000000..400e4149643d --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayJavaStreamedWsClientTest.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v1_0; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaStreamedWsClientBaseTest; + +class PlayJavaStreamedWsClientTest extends PlayJavaStreamedWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayJavaWsClientTest.java b/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayJavaWsClientTest.java new file mode 100644 index 000000000000..111378b7c259 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayJavaWsClientTest.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v1_0; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaWsClientBaseTest; + +class PlayJavaWsClientTest extends PlayJavaWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayScalaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayScalaStreamedWsClientTest.java new file mode 100644 index 000000000000..39a73d93c85a --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayScalaStreamedWsClientTest.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v1_0; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaStreamedWsClientBaseTest; + +class PlayScalaStreamedWsClientTest extends PlayScalaStreamedWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayScalaWsClientTest.java b/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayScalaWsClientTest.java new file mode 100644 index 000000000000..afe93bde2875 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayScalaWsClientTest.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v1_0; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaWsClientBaseTest; + +class PlayScalaWsClientTest extends PlayScalaWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayWsClientTest.java b/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayWsClientTest.java deleted file mode 100644 index afab45905b10..000000000000 --- a/instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayWsClientTest.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.playws.v1_0; - -import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaStreamedWsClientBaseTest; -import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaWsClientBaseTest; -import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaStreamedWsClientBaseTest; -import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaWsClientBaseTest; - -class PlayJavaWsClientTest extends PlayJavaWsClientBaseTest {} - -class PlayJavaStreamedWsClientTest extends PlayJavaStreamedWsClientBaseTest {} - -class PlayScalaWsClientTest extends PlayScalaWsClientBaseTest {} - -class PlayScalaStreamedWsClientTest extends PlayScalaStreamedWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayJavaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayJavaStreamedWsClientTest.java new file mode 100644 index 000000000000..fdffbac49403 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayJavaStreamedWsClientTest.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_0; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaStreamedWsClientBaseTest; + +class PlayJavaStreamedWsClientTest extends PlayJavaStreamedWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayJavaWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayJavaWsClientTest.java new file mode 100644 index 000000000000..f9175d644e21 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayJavaWsClientTest.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_0; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaWsClientBaseTest; + +class PlayJavaWsClientTest extends PlayJavaWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayScalaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayScalaStreamedWsClientTest.java new file mode 100644 index 000000000000..63f68e80b602 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayScalaStreamedWsClientTest.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_0; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaStreamedWsClientBaseTest; + +class PlayScalaStreamedWsClientTest extends PlayScalaStreamedWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayScalaWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayScalaWsClientTest.java new file mode 100644 index 000000000000..7063c444938f --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayScalaWsClientTest.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_0; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaWsClientBaseTest; + +class PlayScalaWsClientTest extends PlayScalaWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayWsClientTest.java deleted file mode 100644 index b983bf15dda5..000000000000 --- a/instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayWsClientTest.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.playws.v2_0; - -import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaStreamedWsClientBaseTest; -import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaWsClientBaseTest; -import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaStreamedWsClientBaseTest; -import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaWsClientBaseTest; - -class PlayJavaWsClientTest extends PlayJavaWsClientBaseTest {} - -class PlayJavaStreamedWsClientTest extends PlayJavaStreamedWsClientBaseTest {} - -class PlayScalaWsClientTest extends PlayScalaWsClientBaseTest {} - -class PlayScalaStreamedWsClientTest extends PlayScalaStreamedWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java new file mode 100644 index 000000000000..66eb33c82202 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_1; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaStreamedWsClientBaseTest; + +class PlayJavaStreamedWsClientTest extends PlayJavaStreamedWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java new file mode 100644 index 000000000000..1fe6a418fd66 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_1; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaWsClientBaseTest; + +class PlayJavaWsClientTest extends PlayJavaWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java new file mode 100644 index 000000000000..d557676e3843 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_1; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaStreamedWsClientBaseTest; + +class PlayScalaStreamedWsClientTest extends PlayScalaStreamedWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java new file mode 100644 index 000000000000..1e0c8959db2a --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_1; + +import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaWsClientBaseTest; + +class PlayScalaWsClientTest extends PlayScalaWsClientBaseTest {} diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientTest.java deleted file mode 100644 index c5c4e7aaa8f2..000000000000 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientTest.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.playws.v2_1; - -import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaStreamedWsClientBaseTest; -import io.opentelemetry.javaagent.instrumentation.playws.PlayJavaWsClientBaseTest; -import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaStreamedWsClientBaseTest; -import io.opentelemetry.javaagent.instrumentation.playws.PlayScalaWsClientBaseTest; - -class PlayJavaWsClientTest extends PlayJavaWsClientBaseTest {} - -class PlayJavaStreamedWsClientTest extends PlayJavaStreamedWsClientBaseTest {} - -class PlayScalaWsClientTest extends PlayScalaWsClientBaseTest {} - -class PlayScalaStreamedWsClientTest extends PlayScalaStreamedWsClientBaseTest {} From 0de5c478ef6d174fd329ef839e96718610aa11b7 Mon Sep 17 00:00:00 2001 From: heyams Date: Wed, 2 Oct 2024 15:03:29 -0700 Subject: [PATCH 09/22] Fix --- .../javaagent/instrumentation/playws/PlayWsClientBaseTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java index b74f7d4dd43f..c49f10972a03 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java @@ -99,6 +99,7 @@ protected void configure(HttpClientTestOptions.Builder optionsBuilder) { // apparently play ws does not report the 302 status code optionsBuilder.setResponseCodeOnRedirectError(null); optionsBuilder.setMaxRedirects(3); + optionsBuilder.spanEndsAfterBody(); optionsBuilder.setHttpAttributes( uri -> { Set> attributes = From f6792ac33fe04320243fe030a6233a2f36b8941c Mon Sep 17 00:00:00 2001 From: heyams Date: Wed, 2 Oct 2024 15:28:41 -0700 Subject: [PATCH 10/22] Fix --- .../instrumentation/playws/PlayScalaWsClientBaseTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java index 56b0eb9568ce..30dfd9d214f0 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java @@ -11,7 +11,6 @@ import java.net.URI; import java.util.Map; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import play.api.libs.ws.StandaloneWSClient; @@ -67,15 +66,15 @@ public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) - throws InterruptedException, TimeoutException { + throws Exception { Future futureResponse = request.execute(); Await.ready(futureResponse, Duration.apply(10, TimeUnit.SECONDS)); Try value = futureResponse.value().get(); if (value.isSuccess()) { return value.get().status(); } - // Catch the Throwable and rethrow it as an IllegalStateException - throw new IllegalStateException(value.failed().get()); + // Catch the Throwable and rethrow it + throw (Exception) value.failed().get(); } @Override From 8e4c0f633c51e3ec00ca7b353c8f9a33389d2c3b Mon Sep 17 00:00:00 2001 From: heyams Date: Wed, 2 Oct 2024 16:32:15 -0700 Subject: [PATCH 11/22] Fix NoSuchMethodError: 'scala.collection.Seq scala.collection.mutable.Map.toSeq() --- .../playws/PlayScalaStreamedWsClientBaseTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java index 8c589b23714a..16cee17148ab 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java @@ -17,11 +17,11 @@ import play.api.libs.ws.StandaloneWSResponse; import play.api.libs.ws.ahc.StandaloneAhcWSClient; import scala.Function1; -import scala.collection.JavaConverters; import scala.concurrent.Await; import scala.concurrent.ExecutionContext; import scala.concurrent.Future; import scala.concurrent.duration.Duration; +import scala.jdk.javaapi.CollectionConverters; import scala.util.Try; public class PlayScalaStreamedWsClientBaseTest extends PlayWsClientBaseTest { @@ -59,7 +59,7 @@ public StandaloneWSRequest buildRequest(String method, URI uri, Map Date: Thu, 3 Oct 2024 14:38:55 -0700 Subject: [PATCH 12/22] Create latestDepTest module as the latest jar uses diff packages --- .../play-ws-2.1/javaagent/build.gradle.kts | 28 +++- .../v2_1/PlayJavaStreamedWsClientTest.java | 98 +++++++++++ .../playws/v2_1/PlayJavaWsClientTest.java | 86 ++++++++++ .../v2_1/PlayScalaStreamedWsClientTest.java | 124 ++++++++++++++ .../playws/v2_1/PlayScalaWsClientTest.java | 110 ++++++++++++ .../playws/v2_1/PlayWsClientBaseTest.java | 158 ++++++++++++++++++ 6 files changed, 603 insertions(+), 1 deletion(-) create mode 100644 instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java create mode 100644 instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/build.gradle.kts b/instrumentation/play/play-ws/play-ws-2.1/javaagent/build.gradle.kts index 92ded4cea19f..a76166fb4baf 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/build.gradle.kts +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/build.gradle.kts @@ -41,8 +41,34 @@ dependencies { testInstrumentation(project(":instrumentation:netty:netty-4.1:javaagent")) testInstrumentation(project(":instrumentation:akka:akka-http-10.0:javaagent")) testInstrumentation(project(":instrumentation:akka:akka-actor-2.3:javaagent")) +} + +testing { + suites { + val latestDepTest by registering(JvmTestSuite::class) { + dependencies { + implementation("com.typesafe.play:play-ahc-ws-standalone_2.13:+") + } + } + } +} - latestDepTestLibrary("com.typesafe.play:play-ahc-ws-standalone_2.13:+") +val testLatestDeps = findProperty("testLatestDeps") as Boolean +tasks { + if (testLatestDeps) { + // disable regular test running and compiling tasks when latest dep test task is run + named("test") { + enabled = false + } + } + + named("latestDepTest") { + enabled = testLatestDeps + } + + check { + dependsOn(testing.suites) + } } if (findProperty("testLatestDeps") as Boolean) { diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java new file mode 100644 index 000000000000..d73234b84061 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java @@ -0,0 +1,98 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_1; + +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; +import java.io.IOException; +import java.net.URI; +import java.util.Map; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.ExecutionException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import play.libs.ws.StandaloneWSClient; +import play.libs.ws.StandaloneWSRequest; +import play.libs.ws.StandaloneWSResponse; +import play.libs.ws.ahc.StandaloneAhcWSClient; + +public class PlayJavaStreamedWsClientTest extends PlayWsClientBaseTest { + + private static StandaloneWSClient wsClient; + private static StandaloneWSClient wsClientWithReadTimeout; + + @BeforeEach + @Override + void setup() { + super.setup(); + wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer); + wsClientWithReadTimeout = + new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer); + autoCleanup.deferCleanup(wsClient); + autoCleanup.deferCleanup(wsClientWithReadTimeout); + } + + @AfterEach + @Override + void tearDown() throws IOException { + if (wsClient != null) { + wsClient.close(); + } + if (wsClientWithReadTimeout != null) { + wsClientWithReadTimeout.close(); + } + super.tearDown(); + } + + @Override + public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) { + StandaloneWSRequest request = getClient(uri).url(uri.toString()).setFollowRedirects(true); + headers.forEach(request::addHeader); + request.setMethod(method); + return request; + } + + @Override + public int sendRequest( + StandaloneWSRequest request, String method, URI uri, Map headers) + throws ExecutionException, InterruptedException { + return internalSendRequest(request).toCompletableFuture().get().getStatus(); + } + + @Override + public void sendRequestWithCallback( + StandaloneWSRequest request, + String method, + URI uri, + Map headers, + HttpClientResult requestResult) { + internalSendRequest(request) + .whenComplete( + (response, throwable) -> { + if (throwable != null) { + requestResult.complete(throwable.getCause()); + } else { + requestResult.complete(response.getStatus()); + } + }); + } + + private static CompletionStage internalSendRequest( + StandaloneWSRequest request) { + CompletionStage stream = request.stream(); + // The status can be ready before the body so explicitly call wait for body to be ready + return stream + .thenCompose( + response -> response.getBodyAsSource().runFold("", (acc, out) -> "", materializer)) + .thenCombine(stream, (body, response) -> response); + } + + private static StandaloneWSClient getClient(URI uri) { + if (uri.toString().contains("/read-timeout")) { + return wsClientWithReadTimeout; + } + return wsClient; + } +} diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java new file mode 100644 index 000000000000..83190bb9c46a --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java @@ -0,0 +1,86 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_1; + +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; +import java.io.IOException; +import java.net.URI; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import play.libs.ws.StandaloneWSClient; +import play.libs.ws.StandaloneWSRequest; +import play.libs.ws.ahc.StandaloneAhcWSClient; + +public class PlayJavaWsClientTest extends PlayWsClientBaseTest { + + private static StandaloneWSClient wsClient; + private static StandaloneWSClient wsClientWithReadTimeout; + + @BeforeEach + @Override + void setup() { + super.setup(); + wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer); + wsClientWithReadTimeout = + new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer); + autoCleanup.deferCleanup(wsClient); + autoCleanup.deferCleanup(wsClientWithReadTimeout); + } + + @AfterEach + @Override + void tearDown() throws IOException { + if (wsClient != null) { + wsClient.close(); + } + if (wsClientWithReadTimeout != null) { + wsClientWithReadTimeout.close(); + } + super.tearDown(); + } + + @Override + public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) { + StandaloneWSRequest request = getClient(uri).url(uri.toString()).setFollowRedirects(true); + headers.forEach(request::addHeader); + return request.setMethod(method); + } + + @Override + public int sendRequest( + StandaloneWSRequest request, String method, URI uri, Map headers) + throws ExecutionException, InterruptedException { + return request.execute().toCompletableFuture().get().getStatus(); + } + + @Override + public void sendRequestWithCallback( + StandaloneWSRequest request, + String method, + URI uri, + Map headers, + HttpClientResult requestResult) { + request + .execute() + .whenComplete( + (response, throwable) -> { + if (throwable != null) { + requestResult.complete(throwable); + } else { + requestResult.complete(response.getStatus()); + } + }); + } + + private static StandaloneWSClient getClient(URI uri) { + if (uri.toString().contains("/read-timeout")) { + return wsClientWithReadTimeout; + } + return wsClient; + } +} diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java new file mode 100644 index 000000000000..5bbbcba66a4b --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java @@ -0,0 +1,124 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_1; + +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; +import java.io.IOException; +import java.net.URI; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import play.api.libs.ws.StandaloneWSClient; +import play.api.libs.ws.StandaloneWSRequest; +import play.api.libs.ws.StandaloneWSResponse; +import play.api.libs.ws.ahc.StandaloneAhcWSClient; +import scala.Function1; +import scala.concurrent.Await; +import scala.concurrent.ExecutionContext; +import scala.concurrent.Future; +import scala.concurrent.duration.Duration; +import scala.jdk.javaapi.CollectionConverters; +import scala.util.Try; + +public class PlayScalaStreamedWsClientTest extends PlayWsClientBaseTest { + + private static StandaloneWSClient wsClient; + private static StandaloneWSClient wsClientWithReadTimeout; + + @BeforeEach + @Override + void setup() { + super.setup(); + wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer); + wsClientWithReadTimeout = + new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer); + autoCleanup.deferCleanup(wsClient); + autoCleanup.deferCleanup(wsClientWithReadTimeout); + } + + @AfterEach + @Override + void tearDown() throws IOException { + if (wsClient != null) { + wsClient.close(); + } + if (wsClientWithReadTimeout != null) { + wsClientWithReadTimeout.close(); + } + super.tearDown(); + } + + @Override + public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) + throws Exception { + return getClient(uri) + .url(uri.toURL().toString()) + .withMethod(method) + .withFollowRedirects(true) + .withHttpHeaders(CollectionConverters.asScala(headers).toList()); + } + + @Override + public int sendRequest( + StandaloneWSRequest request, String method, URI uri, Map headers) + throws Exception { + return Await.result(internalSendRequest(request), Duration.apply(10, TimeUnit.SECONDS)) + .status(); + } + + @Override + public void sendRequestWithCallback( + StandaloneWSRequest request, + String method, + URI uri, + Map headers, + HttpClientResult requestResult) { + internalSendRequest(request) + .onComplete( + new Function1, Void>() { + @Override + public Void apply(Try response) { + if (response.isSuccess()) { + requestResult.complete(response.get().status()); + } else { + requestResult.complete(response.failed().get()); + } + return null; + } + }, + ExecutionContext.global()); + } + + private static Future internalSendRequest(StandaloneWSRequest request) { + Future futureResponse = request.stream(); + // The status can be ready before the body so explicitly call wait for body to be ready + Future bodyResponse = + futureResponse.flatMap( + new Function1>() { + @Override + public Future apply(StandaloneWSResponse wsResponse) { + return wsResponse.bodyAsSource().runFold("", (acc, out) -> "", materializer); + } + }, + ExecutionContext.global()); + return bodyResponse.flatMap( + new Function1>() { + @Override + public Future apply(String v1) { + return futureResponse; + } + }, + ExecutionContext.global()); + } + + private static StandaloneWSClient getClient(URI uri) { + if (uri.toString().contains("/read-timeout")) { + return wsClientWithReadTimeout; + } + return wsClient; + } +} diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java new file mode 100644 index 000000000000..f31a4ef238b2 --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java @@ -0,0 +1,110 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_1; + +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import play.api.libs.ws.StandaloneWSClient; +import play.api.libs.ws.StandaloneWSRequest; +import play.api.libs.ws.StandaloneWSResponse; +import play.api.libs.ws.ahc.StandaloneAhcWSClient; +import scala.Function1; +import scala.concurrent.Await; +import scala.concurrent.ExecutionContext; +import scala.concurrent.Future; +import scala.concurrent.duration.Duration; +import scala.jdk.javaapi.CollectionConverters; +import scala.util.Try; + +public class PlayScalaWsClientTest extends PlayWsClientBaseTest { + + private static StandaloneWSClient wsClient; + private static StandaloneWSClient wsClientWithReadTimeout; + + @BeforeEach + @Override + void setup() { + super.setup(); + wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer); + wsClientWithReadTimeout = + new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer); + autoCleanup.deferCleanup(wsClient); + autoCleanup.deferCleanup(wsClientWithReadTimeout); + } + + @AfterEach + @Override + void tearDown() throws IOException { + if (wsClient != null) { + wsClient.close(); + } + if (wsClientWithReadTimeout != null) { + wsClientWithReadTimeout.close(); + } + super.tearDown(); + } + + @Override + public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) + throws MalformedURLException { + return getClient(uri) + .url(uri.toURL().toString()) + .withMethod(method) + .withFollowRedirects(true) + .withHttpHeaders(CollectionConverters.asScala(headers).toSeq()); + } + + @Override + public int sendRequest( + StandaloneWSRequest request, String method, URI uri, Map headers) + throws Exception { + Future futureResponse = request.execute(); + Await.ready(futureResponse, Duration.apply(10, TimeUnit.SECONDS)); + Try value = futureResponse.value().get(); + if (value.isSuccess()) { + return value.get().status(); + } + // Catch the Throwable and rethrow it + throw (Exception) value.failed().get(); + } + + @Override + public void sendRequestWithCallback( + StandaloneWSRequest request, + String method, + URI uri, + Map headers, + HttpClientResult requestResult) { + request + .execute() + .onComplete( + new Function1, Void>() { + @Override + public Void apply(Try response) { + if (response.isSuccess()) { + requestResult.complete(response.get().status()); + } else { + requestResult.complete(response.failed().get()); + } + return null; + } + }, + ExecutionContext.global()); + } + + private static StandaloneWSClient getClient(URI uri) { + if (uri.toString().contains("/read-timeout")) { + return wsClientWithReadTimeout; + } + return wsClient; + } +} diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java new file mode 100644 index 000000000000..738bcb0eb15c --- /dev/null +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java @@ -0,0 +1,158 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.playws.v2_1; + +import akka.actor.ActorSystem; +import akka.stream.Materializer; +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; +import io.opentelemetry.semconv.NetworkAttributes; +import io.opentelemetry.semconv.ServerAttributes; +import java.io.IOException; +import java.net.InetAddress; +import java.net.URI; +import java.net.UnknownHostException; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; +import play.shaded.ahc.io.netty.resolver.InetNameResolver; +import play.shaded.ahc.io.netty.util.concurrent.EventExecutor; +import play.shaded.ahc.io.netty.util.concurrent.ImmediateEventExecutor; +import play.shaded.ahc.io.netty.util.concurrent.Promise; +import play.shaded.ahc.org.asynchttpclient.AsyncHttpClient; +import play.shaded.ahc.org.asynchttpclient.AsyncHttpClientConfig; +import play.shaded.ahc.org.asynchttpclient.DefaultAsyncHttpClient; +import play.shaded.ahc.org.asynchttpclient.DefaultAsyncHttpClientConfig; +import play.shaded.ahc.org.asynchttpclient.RequestBuilderBase; + +abstract class PlayWsClientBaseTest extends AbstractHttpClientTest { + + @RegisterExtension + static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent(); + + static final AutoCleanupExtension autoCleanup = AutoCleanupExtension.create(); + + private static ActorSystem system; + protected static AsyncHttpClient asyncHttpClient; + protected static AsyncHttpClient asyncHttpClientWithReadTimeout; + protected static Materializer materializer; + + @BeforeEach + void setup() { + String name = "play-ws"; + system = ActorSystem.create(name); + materializer = Materializer.matFromSystem(system); + + // Replace dns name resolver with custom implementation that returns only once address for each + // host. This is needed for "connection error dropped request" because in case of connection + // failure ahc will try the next address which isn't necessary for this test. + RequestBuilderBase.DEFAULT_NAME_RESOLVER = + new CustomNameResolver(ImmediateEventExecutor.INSTANCE); + + asyncHttpClient = createClient(false); + asyncHttpClientWithReadTimeout = createClient(true); + autoCleanup.deferCleanup(asyncHttpClient); + autoCleanup.deferCleanup(asyncHttpClientWithReadTimeout); + } + + @AfterEach + void tearDown() throws IOException { + if (system != null) { + system.terminate(); + } + if (asyncHttpClient != null) { + asyncHttpClient.close(); + } + if (asyncHttpClientWithReadTimeout != null) { + asyncHttpClientWithReadTimeout.close(); + } + } + + @Override + public REQUEST buildRequest(String method, URI uri, Map headers) + throws Exception { + return null; + } + + @Override + public int sendRequest(REQUEST request, String method, URI uri, Map headers) + throws Exception { + return 0; + } + + @Override + protected void configure(HttpClientTestOptions.Builder optionsBuilder) { + super.configure(optionsBuilder); + // apparently play ws does not report the 302 status code + optionsBuilder.setResponseCodeOnRedirectError(null); + optionsBuilder.setMaxRedirects(3); + optionsBuilder.spanEndsAfterBody(); + optionsBuilder.setHttpAttributes( + uri -> { + Set> attributes = + new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES); + attributes.remove(NetworkAttributes.NETWORK_PROTOCOL_VERSION); + if (uri.toString().endsWith("/circular-redirect")) { + attributes.remove(ServerAttributes.SERVER_ADDRESS); + attributes.remove(ServerAttributes.SERVER_PORT); + } + return attributes; + }); + } + + private static AsyncHttpClient createClient(boolean readTimeout) { + DefaultAsyncHttpClientConfig.Builder builder = + new DefaultAsyncHttpClientConfig.Builder() + .setMaxRequestRetry(0) + .setShutdownQuietPeriod(0) + .setShutdownTimeout(0) + .setMaxRedirects(3) + .setConnectTimeout(5000); + + if (readTimeout) { + builder.setReadTimeout(2000); + } + + AsyncHttpClientConfig asyncHttpClientConfig = builder.build(); + return new DefaultAsyncHttpClient(asyncHttpClientConfig); + } + + private static class CustomNameResolver extends InetNameResolver { + + public CustomNameResolver(EventExecutor executor) { + super(executor); + } + + @Override + protected void doResolve(String inetHost, Promise promise) throws Exception { + try { + promise.setSuccess(InetAddress.getByName(inetHost)); + } catch (UnknownHostException exception) { + promise.setFailure(exception); + } + } + + @Override + protected void doResolveAll(String inetHost, Promise> promise) + throws Exception { + try { + // default implementation calls InetAddress.getAllByName + promise.setSuccess(Collections.singletonList(InetAddress.getByName(inetHost))); + } catch (UnknownHostException exception) { + promise.setFailure(exception); + } + } + } +} From 279347ccdbeea1e6ebc829526780ddbd6c04cd70 Mon Sep 17 00:00:00 2001 From: heyams Date: Thu, 3 Oct 2024 16:32:18 -0700 Subject: [PATCH 13/22] Fix compilation error --- .../playws/PlayScalaStreamedWsClientBaseTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java index 16cee17148ab..e4a169db5b63 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java @@ -17,6 +17,7 @@ import play.api.libs.ws.StandaloneWSResponse; import play.api.libs.ws.ahc.StandaloneAhcWSClient; import scala.Function1; +import scala.collection.JavaConverters; import scala.concurrent.Await; import scala.concurrent.ExecutionContext; import scala.concurrent.Future; @@ -59,7 +60,7 @@ public StandaloneWSRequest buildRequest(String method, URI uri, Map Date: Mon, 7 Oct 2024 12:35:25 -0700 Subject: [PATCH 14/22] Fix spotless --- .../playws/PlayScalaStreamedWsClientBaseTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java index e4a169db5b63..8c589b23714a 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java @@ -22,7 +22,6 @@ import scala.concurrent.ExecutionContext; import scala.concurrent.Future; import scala.concurrent.duration.Duration; -import scala.jdk.javaapi.CollectionConverters; import scala.util.Try; public class PlayScalaStreamedWsClientBaseTest extends PlayWsClientBaseTest { From 8f4c604961cbb09da37aa790972ffb359309ba7f Mon Sep 17 00:00:00 2001 From: heyams Date: Tue, 8 Oct 2024 13:40:32 -0700 Subject: [PATCH 15/22] Fix --- .../play-ws/play-ws-2.1/javaagent/build.gradle.kts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/build.gradle.kts b/instrumentation/play/play-ws/play-ws-2.1/javaagent/build.gradle.kts index a76166fb4baf..597e952503b1 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/build.gradle.kts +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/build.gradle.kts @@ -43,6 +43,8 @@ dependencies { testInstrumentation(project(":instrumentation:akka:akka-actor-2.3:javaagent")) } +val testLatestDeps = findProperty("testLatestDeps") as Boolean + testing { suites { val latestDepTest by registering(JvmTestSuite::class) { @@ -53,7 +55,7 @@ testing { } } -val testLatestDeps = findProperty("testLatestDeps") as Boolean + tasks { if (testLatestDeps) { // disable regular test running and compiling tasks when latest dep test task is run @@ -70,12 +72,3 @@ tasks { dependsOn(testing.suites) } } - -if (findProperty("testLatestDeps") as Boolean) { - configurations { - // play-ws artifact name is different for regular and latest tests - testImplementation { - exclude("com.typesafe.play", "play-ahc-ws-standalone_$scalaVersion") - } - } -} From 4ce3d86f437574d75bba0bad827f43d97d71b30a Mon Sep 17 00:00:00 2001 From: heyams Date: Tue, 8 Oct 2024 13:41:59 -0700 Subject: [PATCH 16/22] Fix spotless --- .../play/play-ws/play-ws-2.1/javaagent/build.gradle.kts | 1 - 1 file changed, 1 deletion(-) diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/build.gradle.kts b/instrumentation/play/play-ws/play-ws-2.1/javaagent/build.gradle.kts index 597e952503b1..8060ebc876fb 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/build.gradle.kts +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/build.gradle.kts @@ -55,7 +55,6 @@ testing { } } - tasks { if (testLatestDeps) { // disable regular test running and compiling tasks when latest dep test task is run From 8b32915d17f295721374c5257aa4fe31e494c347 Mon Sep 17 00:00:00 2001 From: heyams Date: Wed, 16 Oct 2024 12:11:53 -0700 Subject: [PATCH 17/22] Comments --- .../playws/v2_1/PlayJavaStreamedWsClientTest.java | 14 -------------- .../playws/v2_1/PlayJavaWsClientTest.java | 14 -------------- .../v2_1/PlayScalaStreamedWsClientTest.java | 14 -------------- .../playws/v2_1/PlayScalaWsClientTest.java | 14 -------------- .../playws/v2_1/PlayWsClientBaseTest.java | 15 --------------- 5 files changed, 71 deletions(-) diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java index d73234b84061..6ee1575458de 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java @@ -6,12 +6,10 @@ package io.opentelemetry.javaagent.instrumentation.playws.v2_1; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; -import java.io.IOException; import java.net.URI; import java.util.Map; import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import play.libs.ws.StandaloneWSClient; import play.libs.ws.StandaloneWSRequest; @@ -34,18 +32,6 @@ void setup() { autoCleanup.deferCleanup(wsClientWithReadTimeout); } - @AfterEach - @Override - void tearDown() throws IOException { - if (wsClient != null) { - wsClient.close(); - } - if (wsClientWithReadTimeout != null) { - wsClientWithReadTimeout.close(); - } - super.tearDown(); - } - @Override public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) { StandaloneWSRequest request = getClient(uri).url(uri.toString()).setFollowRedirects(true); diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java index 83190bb9c46a..18ae561807ec 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java @@ -6,11 +6,9 @@ package io.opentelemetry.javaagent.instrumentation.playws.v2_1; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; -import java.io.IOException; import java.net.URI; import java.util.Map; import java.util.concurrent.ExecutionException; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import play.libs.ws.StandaloneWSClient; import play.libs.ws.StandaloneWSRequest; @@ -32,18 +30,6 @@ void setup() { autoCleanup.deferCleanup(wsClientWithReadTimeout); } - @AfterEach - @Override - void tearDown() throws IOException { - if (wsClient != null) { - wsClient.close(); - } - if (wsClientWithReadTimeout != null) { - wsClientWithReadTimeout.close(); - } - super.tearDown(); - } - @Override public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) { StandaloneWSRequest request = getClient(uri).url(uri.toString()).setFollowRedirects(true); diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java index 5bbbcba66a4b..7a4962624241 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java @@ -6,11 +6,9 @@ package io.opentelemetry.javaagent.instrumentation.playws.v2_1; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; -import java.io.IOException; import java.net.URI; import java.util.Map; import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import play.api.libs.ws.StandaloneWSClient; import play.api.libs.ws.StandaloneWSRequest; @@ -40,18 +38,6 @@ void setup() { autoCleanup.deferCleanup(wsClientWithReadTimeout); } - @AfterEach - @Override - void tearDown() throws IOException { - if (wsClient != null) { - wsClient.close(); - } - if (wsClientWithReadTimeout != null) { - wsClientWithReadTimeout.close(); - } - super.tearDown(); - } - @Override public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) throws Exception { diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java index f31a4ef238b2..fdca64dc4e5f 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java @@ -6,12 +6,10 @@ package io.opentelemetry.javaagent.instrumentation.playws.v2_1; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; -import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; import java.util.Map; import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import play.api.libs.ws.StandaloneWSClient; import play.api.libs.ws.StandaloneWSRequest; @@ -41,18 +39,6 @@ void setup() { autoCleanup.deferCleanup(wsClientWithReadTimeout); } - @AfterEach - @Override - void tearDown() throws IOException { - if (wsClient != null) { - wsClient.close(); - } - if (wsClientWithReadTimeout != null) { - wsClientWithReadTimeout.close(); - } - super.tearDown(); - } - @Override public StandaloneWSRequest buildRequest(String method, URI uri, Map headers) throws MalformedURLException { diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java index 738bcb0eb15c..e947ec81e0be 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java @@ -15,7 +15,6 @@ import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; import io.opentelemetry.semconv.NetworkAttributes; import io.opentelemetry.semconv.ServerAttributes; -import java.io.IOException; import java.net.InetAddress; import java.net.URI; import java.net.UnknownHostException; @@ -24,7 +23,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; import play.shaded.ahc.io.netty.resolver.InetNameResolver; @@ -67,19 +65,6 @@ void setup() { autoCleanup.deferCleanup(asyncHttpClientWithReadTimeout); } - @AfterEach - void tearDown() throws IOException { - if (system != null) { - system.terminate(); - } - if (asyncHttpClient != null) { - asyncHttpClient.close(); - } - if (asyncHttpClientWithReadTimeout != null) { - asyncHttpClientWithReadTimeout.close(); - } - } - @Override public REQUEST buildRequest(String method, URI uri, Map headers) throws Exception { From 570f8d1f0b279e4eba1375d41bfe82b689632569 Mon Sep 17 00:00:00 2001 From: heyams Date: Fri, 25 Oct 2024 12:22:43 -0700 Subject: [PATCH 18/22] Comments --- .../v2_1/PlayJavaStreamedWsClientTest.java | 2 +- .../playws/v2_1/PlayJavaWsClientTest.java | 2 +- .../v2_1/PlayScalaStreamedWsClientTest.java | 2 +- .../playws/v2_1/PlayScalaWsClientTest.java | 2 +- .../playws/v2_1/PlayWsClientBaseTest.java | 16 ---------- .../playws/PlayWsClientBaseTest.java | 29 ------------------- 6 files changed, 4 insertions(+), 49 deletions(-) diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java index 6ee1575458de..2d8c3867b768 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java @@ -16,7 +16,7 @@ import play.libs.ws.StandaloneWSResponse; import play.libs.ws.ahc.StandaloneAhcWSClient; -public class PlayJavaStreamedWsClientTest extends PlayWsClientBaseTest { +class PlayJavaStreamedWsClientTest extends PlayWsClientBaseTest { private static StandaloneWSClient wsClient; private static StandaloneWSClient wsClientWithReadTimeout; diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java index 18ae561807ec..8f76b0d8ffdc 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java @@ -14,7 +14,7 @@ import play.libs.ws.StandaloneWSRequest; import play.libs.ws.ahc.StandaloneAhcWSClient; -public class PlayJavaWsClientTest extends PlayWsClientBaseTest { +class PlayJavaWsClientTest extends PlayWsClientBaseTest { private static StandaloneWSClient wsClient; private static StandaloneWSClient wsClientWithReadTimeout; diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java index 7a4962624241..2bd4824e21b3 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java @@ -22,7 +22,7 @@ import scala.jdk.javaapi.CollectionConverters; import scala.util.Try; -public class PlayScalaStreamedWsClientTest extends PlayWsClientBaseTest { +class PlayScalaStreamedWsClientTest extends PlayWsClientBaseTest { private static StandaloneWSClient wsClient; private static StandaloneWSClient wsClientWithReadTimeout; diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java index fdca64dc4e5f..d763114445a2 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaWsClientTest.java @@ -23,7 +23,7 @@ import scala.jdk.javaapi.CollectionConverters; import scala.util.Try; -public class PlayScalaWsClientTest extends PlayWsClientBaseTest { +class PlayScalaWsClientTest extends PlayWsClientBaseTest { private static StandaloneWSClient wsClient; private static StandaloneWSClient wsClientWithReadTimeout; diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java index e947ec81e0be..b323e0e9c989 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java @@ -16,14 +16,11 @@ import io.opentelemetry.semconv.NetworkAttributes; import io.opentelemetry.semconv.ServerAttributes; import java.net.InetAddress; -import java.net.URI; import java.net.UnknownHostException; import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; import play.shaded.ahc.io.netty.resolver.InetNameResolver; import play.shaded.ahc.io.netty.util.concurrent.EventExecutor; @@ -47,7 +44,6 @@ abstract class PlayWsClientBaseTest extends AbstractHttpClientTest headers) - throws Exception { - return null; - } - - @Override - public int sendRequest(REQUEST request, String method, URI uri, Map headers) - throws Exception { - return 0; - } - @Override protected void configure(HttpClientTestOptions.Builder optionsBuilder) { super.configure(optionsBuilder); diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java index c49f10972a03..8ed035c33eb9 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java @@ -16,16 +16,12 @@ import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; import io.opentelemetry.semconv.NetworkAttributes; import io.opentelemetry.semconv.ServerAttributes; -import java.io.IOException; import java.net.InetAddress; -import java.net.URI; import java.net.UnknownHostException; import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; import play.shaded.ahc.io.netty.resolver.InetNameResolver; @@ -68,31 +64,6 @@ void setup() { autoCleanup.deferCleanup(asyncHttpClientWithReadTimeout); } - @AfterEach - void tearDown() throws IOException { - if (system != null) { - system.terminate(); - } - if (asyncHttpClient != null) { - asyncHttpClient.close(); - } - if (asyncHttpClientWithReadTimeout != null) { - asyncHttpClientWithReadTimeout.close(); - } - } - - @Override - public REQUEST buildRequest(String method, URI uri, Map headers) - throws Exception { - return null; - } - - @Override - public int sendRequest(REQUEST request, String method, URI uri, Map headers) - throws Exception { - return 0; - } - @Override protected void configure(HttpClientTestOptions.Builder optionsBuilder) { super.configure(optionsBuilder); From b0cf9899578602820df59bd8d3b48399571f82db Mon Sep 17 00:00:00 2001 From: heyams Date: Fri, 25 Oct 2024 13:39:13 -0700 Subject: [PATCH 19/22] Fix compilation errors --- .../playws/PlayJavaStreamedWsClientBaseTest.java | 16 ---------------- .../playws/PlayJavaWsClientBaseTest.java | 16 ---------------- .../PlayScalaStreamedWsClientBaseTest.java | 13 ------------- .../playws/PlayScalaWsClientBaseTest.java | 16 ---------------- .../playws/PlayWsClientBaseTest.java | 2 -- 5 files changed, 63 deletions(-) diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java index 1f0552d15ae9..f5dbc7ec7f09 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaStreamedWsClientBaseTest.java @@ -6,13 +6,10 @@ package io.opentelemetry.javaagent.instrumentation.playws; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; -import java.io.IOException; import java.net.URI; import java.util.Map; import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import play.libs.ws.StandaloneWSClient; import play.libs.ws.StandaloneWSRequest; import play.libs.ws.StandaloneWSResponse; @@ -23,7 +20,6 @@ public class PlayJavaStreamedWsClientBaseTest extends PlayWsClientBaseTest headers) { StandaloneWSRequest request = getClient(uri).url(uri.toString()).setFollowRedirects(true); diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaWsClientBaseTest.java index c534ada973b2..74eb4a4e7276 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayJavaWsClientBaseTest.java @@ -6,12 +6,9 @@ package io.opentelemetry.javaagent.instrumentation.playws; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; -import java.io.IOException; import java.net.URI; import java.util.Map; import java.util.concurrent.ExecutionException; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import play.libs.ws.StandaloneWSClient; import play.libs.ws.StandaloneWSRequest; import play.libs.ws.ahc.StandaloneAhcWSClient; @@ -21,7 +18,6 @@ public class PlayJavaWsClientBaseTest extends PlayWsClientBaseTest headers) { StandaloneWSRequest request = getClient(uri).url(uri.toString()).setFollowRedirects(true); diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java index 8c589b23714a..4ce6f0c57cb2 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java @@ -29,7 +29,6 @@ public class PlayScalaStreamedWsClientBaseTest extends PlayWsClientBaseTest headers) throws Exception { diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java index 30dfd9d214f0..9aff49f37fa2 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaWsClientBaseTest.java @@ -6,13 +6,10 @@ package io.opentelemetry.javaagent.instrumentation.playws; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; -import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; import java.util.Map; import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import play.api.libs.ws.StandaloneWSClient; import play.api.libs.ws.StandaloneWSRequest; import play.api.libs.ws.StandaloneWSResponse; @@ -30,7 +27,6 @@ public class PlayScalaWsClientBaseTest extends PlayWsClientBaseTest headers) throws MalformedURLException { diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java index 8ed035c33eb9..d73e99b37bcc 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayWsClientBaseTest.java @@ -22,7 +22,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; import play.shaded.ahc.io.netty.resolver.InetNameResolver; import play.shaded.ahc.io.netty.util.concurrent.EventExecutor; @@ -46,7 +45,6 @@ abstract class PlayWsClientBaseTest extends AbstractHttpClientTest Date: Fri, 25 Oct 2024 13:46:51 -0700 Subject: [PATCH 20/22] Fix spotless --- .../playws/PlayScalaStreamedWsClientBaseTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java index 4ce6f0c57cb2..09ea95b66399 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/playws/PlayScalaStreamedWsClientBaseTest.java @@ -6,12 +6,9 @@ package io.opentelemetry.javaagent.instrumentation.playws; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; -import java.io.IOException; import java.net.URI; import java.util.Map; import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import play.api.libs.ws.StandaloneWSClient; import play.api.libs.ws.StandaloneWSRequest; import play.api.libs.ws.StandaloneWSResponse; From 49a4c5f7f0a3700c26c7e073dc7b108ff9a0a655 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Wed, 30 Oct 2024 09:26:34 +0200 Subject: [PATCH 21/22] reuse http client --- .../v2_1/PlayJavaStreamedWsClientTest.java | 18 +++++++++++------- .../playws/v2_1/PlayJavaWsClientTest.java | 18 +++++++++++------- .../v2_1/PlayScalaStreamedWsClientTest.java | 16 ++++++++++------ .../playws/v2_1/PlayScalaWsClientTest.java | 16 ++++++++++------ .../playws/v2_1/PlayWsClientBaseTest.java | 18 ++++++++++++------ .../PlayJavaStreamedWsClientBaseTest.java | 16 +++++++++++----- .../playws/PlayJavaWsClientBaseTest.java | 18 +++++++++++++----- .../PlayScalaStreamedWsClientBaseTest.java | 14 ++++++++++---- .../playws/PlayScalaWsClientBaseTest.java | 14 ++++++++++---- .../playws/PlayWsClientBaseTest.java | 18 ++++++++++++------ 10 files changed, 110 insertions(+), 56 deletions(-) diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java index 2d8c3867b768..610f468b823f 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java @@ -6,11 +6,13 @@ package io.opentelemetry.javaagent.instrumentation.playws.v2_1; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; +import java.io.IOException; import java.net.URI; import java.util.Map; import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import play.libs.ws.StandaloneWSClient; import play.libs.ws.StandaloneWSRequest; import play.libs.ws.StandaloneWSResponse; @@ -21,15 +23,17 @@ class PlayJavaStreamedWsClientTest extends PlayWsClientBaseTest { private static StandaloneWSClient wsClient; private static StandaloneWSClient wsClientWithReadTimeout; - @BeforeEach - @Override - void setup() { - super.setup(); + @BeforeAll + static void setup() { wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer); wsClientWithReadTimeout = new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer); - autoCleanup.deferCleanup(wsClient); - autoCleanup.deferCleanup(wsClientWithReadTimeout); + } + + @AfterAll + static void cleanup() throws IOException { + wsClient.close(); + wsClientWithReadTimeout.close(); } @Override diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java index 2bd4824e21b3..2f65c1193de5 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java @@ -6,10 +6,12 @@ package io.opentelemetry.javaagent.instrumentation.playws.v2_1; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; +import java.io.IOException; import java.net.URI; import java.util.Map; import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import play.api.libs.ws.StandaloneWSClient; import play.api.libs.ws.StandaloneWSRequest; import play.api.libs.ws.StandaloneWSResponse; @@ -27,15 +29,17 @@ class PlayScalaStreamedWsClientTest extends PlayWsClientBaseTest { private static StandaloneWSClient wsClient; private static StandaloneWSClient wsClientWithReadTimeout; - @BeforeEach - @Override + @BeforeAll void setup() { - super.setup(); wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer); wsClientWithReadTimeout = new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer); - autoCleanup.deferCleanup(wsClient); - autoCleanup.deferCleanup(wsClientWithReadTimeout); + } + + @AfterAll + static void cleanup() throws IOException { + wsClient.close(); + wsClientWithReadTimeout.close(); } @Override diff --git a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java index b323e0e9c989..a9288e8be04c 100644 --- a/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java +++ b/instrumentation/play/play-ws/play-ws-2.1/javaagent/src/latestDepTest/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayWsClientBaseTest.java @@ -8,19 +8,21 @@ import akka.actor.ActorSystem; import akka.stream.Materializer; import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; import io.opentelemetry.semconv.NetworkAttributes; import io.opentelemetry.semconv.ServerAttributes; +import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.extension.RegisterExtension; import play.shaded.ahc.io.netty.resolver.InetNameResolver; import play.shaded.ahc.io.netty.util.concurrent.EventExecutor; @@ -37,14 +39,13 @@ abstract class PlayWsClientBaseTest extends AbstractHttpClientTest extends AbstractHttpClientTest Date: Wed, 30 Oct 2024 13:45:43 +0200 Subject: [PATCH 22/22] remove spock dependency --- .../play/play-ws/play-ws-common/testing/build.gradle.kts | 1 - 1 file changed, 1 deletion(-) diff --git a/instrumentation/play/play-ws/play-ws-common/testing/build.gradle.kts b/instrumentation/play/play-ws/play-ws-common/testing/build.gradle.kts index e295ab2392a1..c6668c7801e1 100644 --- a/instrumentation/play/play-ws/play-ws-common/testing/build.gradle.kts +++ b/instrumentation/play/play-ws/play-ws-common/testing/build.gradle.kts @@ -9,5 +9,4 @@ dependencies { api("com.typesafe.play:play-ahc-ws-standalone_$scalaVersion:1.0.2") implementation("io.opentelemetry:opentelemetry-api") - implementation("org.spockframework:spock-core") }