-
Notifications
You must be signed in to change notification settings - Fork 866
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert play-ws groovy to java (#12377)
Co-authored-by: Lauri Tulmin <[email protected]>
- Loading branch information
Showing
29 changed files
with
1,169 additions
and
410 deletions.
There are no files selected for viewing
12 changes: 0 additions & 12 deletions
12
instrumentation/play/play-ws/play-ws-1.0/javaagent/src/test/groovy/PlayWsClientTest.groovy
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
.../io/opentelemetry/javaagent/instrumentation/playws/v1_0/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,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 {} |
10 changes: 10 additions & 0 deletions
10
...est/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/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,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 {} |
10 changes: 10 additions & 0 deletions
10
...io/opentelemetry/javaagent/instrumentation/playws/v1_0/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,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 {} |
10 changes: 10 additions & 0 deletions
10
...st/java/io/opentelemetry/javaagent/instrumentation/playws/v1_0/PlayScalaWsClientTest.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,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 {} |
12 changes: 0 additions & 12 deletions
12
instrumentation/play/play-ws/play-ws-2.0/javaagent/src/test/groovy/PlayWsClientTest.groovy
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
.../io/opentelemetry/javaagent/instrumentation/playws/v2_0/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,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 {} |
10 changes: 10 additions & 0 deletions
10
...est/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/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,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 {} |
10 changes: 10 additions & 0 deletions
10
...io/opentelemetry/javaagent/instrumentation/playws/v2_0/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,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 {} |
10 changes: 10 additions & 0 deletions
10
...st/java/io/opentelemetry/javaagent/instrumentation/playws/v2_0/PlayScalaWsClientTest.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,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 {} |
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
88 changes: 88 additions & 0 deletions
88
.../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,88 @@ | ||
/* | ||
* 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.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import play.libs.ws.StandaloneWSClient; | ||
import play.libs.ws.StandaloneWSRequest; | ||
import play.libs.ws.StandaloneWSResponse; | ||
import play.libs.ws.ahc.StandaloneAhcWSClient; | ||
|
||
class PlayJavaStreamedWsClientTest extends PlayWsClientBaseTest<StandaloneWSRequest> { | ||
|
||
private static StandaloneWSClient wsClient; | ||
private static StandaloneWSClient wsClientWithReadTimeout; | ||
|
||
@BeforeAll | ||
static void setup() { | ||
wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer); | ||
wsClientWithReadTimeout = | ||
new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer); | ||
} | ||
|
||
@AfterAll | ||
static void cleanup() throws IOException { | ||
wsClient.close(); | ||
wsClientWithReadTimeout.close(); | ||
} | ||
|
||
@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; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...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,76 @@ | ||
/* | ||
* 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.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import play.libs.ws.StandaloneWSClient; | ||
import play.libs.ws.StandaloneWSRequest; | ||
import play.libs.ws.ahc.StandaloneAhcWSClient; | ||
|
||
class PlayJavaWsClientTest extends PlayWsClientBaseTest<StandaloneWSRequest> { | ||
|
||
private static StandaloneWSClient wsClient; | ||
private static StandaloneWSClient wsClientWithReadTimeout; | ||
|
||
@BeforeAll | ||
static void setup() { | ||
wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer); | ||
wsClientWithReadTimeout = | ||
new StandaloneAhcWSClient(asyncHttpClientWithReadTimeout, materializer); | ||
} | ||
|
||
@AfterAll | ||
static void cleanup() throws IOException { | ||
wsClient.close(); | ||
wsClientWithReadTimeout.close(); | ||
} | ||
|
||
@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; | ||
} | ||
} |
Oops, something went wrong.