-
Notifications
You must be signed in to change notification settings - Fork 872
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create latestDepTest module as the latest jar uses diff packages
- Loading branch information
Showing
6 changed files
with
603 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
.../io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaStreamedWsClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
|
||
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); | ||
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; | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...est/java/io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayJavaWsClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
...io/opentelemetry/javaagent/instrumentation/playws/v2_1/PlayScalaStreamedWsClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<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) | ||
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<String, String> 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<String, String> headers, | ||
HttpClientResult requestResult) { | ||
internalSendRequest(request) | ||
.onComplete( | ||
new Function1<Try<StandaloneWSResponse>, Void>() { | ||
@Override | ||
public Void apply(Try<StandaloneWSResponse> response) { | ||
if (response.isSuccess()) { | ||
requestResult.complete(response.get().status()); | ||
} else { | ||
requestResult.complete(response.failed().get()); | ||
} | ||
return null; | ||
} | ||
}, | ||
ExecutionContext.global()); | ||
} | ||
|
||
private static Future<StandaloneWSResponse> internalSendRequest(StandaloneWSRequest request) { | ||
Future<StandaloneWSResponse> futureResponse = request.stream(); | ||
// The status can be ready before the body so explicitly call wait for body to be ready | ||
Future<String> bodyResponse = | ||
futureResponse.flatMap( | ||
new Function1<StandaloneWSResponse, Future<String>>() { | ||
@Override | ||
public Future<String> apply(StandaloneWSResponse wsResponse) { | ||
return wsResponse.bodyAsSource().runFold("", (acc, out) -> "", materializer); | ||
} | ||
}, | ||
ExecutionContext.global()); | ||
return bodyResponse.flatMap( | ||
new Function1<String, Future<StandaloneWSResponse>>() { | ||
@Override | ||
public Future<StandaloneWSResponse> apply(String v1) { | ||
return futureResponse; | ||
} | ||
}, | ||
ExecutionContext.global()); | ||
} | ||
|
||
private static StandaloneWSClient getClient(URI uri) { | ||
if (uri.toString().contains("/read-timeout")) { | ||
return wsClientWithReadTimeout; | ||
} | ||
return wsClient; | ||
} | ||
} |
Oops, something went wrong.