-
Notifications
You must be signed in to change notification settings - Fork 867
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
trask
merged 25 commits into
open-telemetry:main
from
heyams:heya/convert-play-ws-groovy-to-java
Oct 30, 2024
Merged
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
834bbf3
Convert play-ws groovy to java
heyams 452f827
Fix errorprone
heyams 372057c
Fix
heyams 7110f11
Fix
heyams 700e2db
Update
heyams 584db50
More update
heyams 69272df
Update
heyams 1977a57
Fix sytle one top level class
heyams 0de5c47
Fix
heyams f6792ac
Fix
heyams 8e4c0f6
Fix NoSuchMethodError: 'scala.collection.Seq scala.collection.mutable…
heyams faf245c
Create latestDepTest module as the latest jar uses diff packages
heyams 279347c
Fix compilation error
heyams b890771
Fix spotless
heyams 8f4c604
Fix
heyams 4ce3d86
Fix spotless
heyams 0326bc4
Merge remote-tracking branch 'upstream/main' into heya/convert-play-w…
heyams 8b32915
Comments
heyams 570f8d1
Comments
heyams b0cf989
Fix compilation errors
heyams b64cdc4
Fix spotless
heyams 3fa85f6
Merge branch 'main' into heya/convert-play-ws-groovy-to-java
laurit 49a4c5f
reuse http client
laurit 8f32199
Merge branch 'main' into heya/convert-play-ws-groovy-to-java
laurit dfadde4
remove spock dependency
laurit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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> { | ||
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; | ||
} | ||
} |
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; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?