Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert play-ws groovy to java #12377

Merged
merged 25 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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 {}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,33 @@ 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"))
}

val testLatestDeps = findProperty("testLatestDeps") as Boolean

latestDepTestLibrary("com.typesafe.play:play-ahc-ws-standalone_2.13:+")
testing {
suites {
val latestDepTest by registering(JvmTestSuite::class) {
dependencies {
implementation("com.typesafe.play:play-ahc-ws-standalone_2.13:+")
}
}
}
}

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")
tasks {
if (testLatestDeps) {
// disable regular test running and compiling tasks when latest dep test task is run
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment is a bit misleading, as far as I can tell compile task is not disabled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only disabling test module. why do i need disable compile task?

named("test") {
enabled = false
}
}

named("latestDepTest") {
enabled = testLatestDeps
}

check {
dependsOn(testing.suites)
}
}
Original file line number Diff line number Diff line change
@@ -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<StandaloneWSRequest> {
heyams marked this conversation as resolved.
Show resolved Hide resolved

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();
}
heyams marked this conversation as resolved.
Show resolved Hide resolved
super.tearDown();
}

@Override
public StandaloneWSRequest buildRequest(String method, URI uri, Map<String, String> 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<String, String> headers)
throws ExecutionException, InterruptedException {
return internalSendRequest(request).toCompletableFuture().get().getStatus();
}

@Override
public void sendRequestWithCallback(
StandaloneWSRequest request,
String method,
URI uri,
Map<String, String> headers,
HttpClientResult requestResult) {
internalSendRequest(request)
.whenComplete(
(response, throwable) -> {
if (throwable != null) {
requestResult.complete(throwable.getCause());
} else {
requestResult.complete(response.getStatus());
}
});
}

private static CompletionStage<StandaloneWSResponse> internalSendRequest(
StandaloneWSRequest request) {
CompletionStage<? extends StandaloneWSResponse> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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<StandaloneWSRequest> {

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<String, String> 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<String, String> headers)
throws ExecutionException, InterruptedException {
return request.execute().toCompletableFuture().get().getStatus();
}

@Override
public void sendRequestWithCallback(
StandaloneWSRequest request,
String method,
URI uri,
Map<String, String> 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;
}
}
Loading
Loading