-
Notifications
You must be signed in to change notification settings - Fork 881
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert play-mvc-2.6 groovy to java (#12340)
- Loading branch information
Showing
9 changed files
with
513 additions
and
444 deletions.
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
99 changes: 0 additions & 99 deletions
99
...lay-mvc/play-mvc-2.6/javaagent/src/latestDepTest/groovy/server/PlayAsyncServerTest.groovy
This file was deleted.
Oops, something went wrong.
118 changes: 0 additions & 118 deletions
118
...lay/play-mvc/play-mvc-2.6/javaagent/src/latestDepTest/groovy/server/PlayServerTest.groovy
This file was deleted.
Oops, something went wrong.
127 changes: 127 additions & 0 deletions
127
...epTest/java/io/opentelemetry/javaagent/instrumentation/play/v2_6/PlayAsyncServerTest.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,127 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.play.v2_6; | ||
|
||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS; | ||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR; | ||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; | ||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD; | ||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM; | ||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; | ||
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import play.Mode; | ||
import play.libs.concurrent.HttpExecution; | ||
import play.mvc.Result; | ||
import play.mvc.Results; | ||
import play.routing.RoutingDsl; | ||
import play.server.Server; | ||
import scala.concurrent.ExecutionContextExecutor; | ||
|
||
class PlayAsyncServerTest extends PlayServerTest { | ||
|
||
private static final ExecutorService executor = Executors.newCachedThreadPool(); | ||
|
||
@Override | ||
protected Server setupServer() { | ||
ExecutionContextExecutor executionContextExecutor = HttpExecution.fromThread(executor); | ||
return Server.forRouter( | ||
Mode.TEST, | ||
port, | ||
components -> | ||
RoutingDsl.fromComponents(components) | ||
.GET(SUCCESS.getPath()) | ||
.routingAsync( | ||
request -> | ||
CompletableFuture.supplyAsync( | ||
() -> | ||
controller( | ||
SUCCESS, | ||
() -> Results.status(SUCCESS.getStatus(), SUCCESS.getBody())), | ||
executionContextExecutor)) | ||
.GET(QUERY_PARAM.getPath()) | ||
.routingAsync( | ||
request -> | ||
CompletableFuture.supplyAsync( | ||
() -> | ||
controller( | ||
QUERY_PARAM, | ||
() -> | ||
Results.status( | ||
QUERY_PARAM.getStatus(), QUERY_PARAM.getBody())), | ||
executionContextExecutor)) | ||
.GET(REDIRECT.getPath()) | ||
.routingAsync( | ||
request -> | ||
CompletableFuture.supplyAsync( | ||
() -> controller(REDIRECT, () -> Results.found(REDIRECT.getBody())), | ||
executionContextExecutor)) | ||
.GET(ERROR.getPath()) | ||
.routingAsync( | ||
request -> | ||
CompletableFuture.supplyAsync( | ||
() -> | ||
controller( | ||
ERROR, | ||
() -> Results.status(ERROR.getStatus(), ERROR.getBody())), | ||
executionContextExecutor)) | ||
.GET(EXCEPTION.getPath()) | ||
.routingAsync( | ||
request -> | ||
CompletableFuture.supplyAsync( | ||
() -> | ||
controller( | ||
EXCEPTION, | ||
() -> { | ||
throw new IllegalArgumentException(EXCEPTION.getBody()); | ||
}), | ||
executionContextExecutor)) | ||
.GET(CAPTURE_HEADERS.getPath()) | ||
.routingAsync( | ||
request -> | ||
CompletableFuture.supplyAsync( | ||
() -> | ||
controller( | ||
CAPTURE_HEADERS, | ||
() -> { | ||
Result result = | ||
Results.status( | ||
CAPTURE_HEADERS.getStatus(), | ||
CAPTURE_HEADERS.getBody()); | ||
return request | ||
.header("X-Test-Request") | ||
.map(value -> result.withHeader("X-Test-Response", value)) | ||
.orElse(result); | ||
}), | ||
executionContextExecutor)) | ||
.GET(INDEXED_CHILD.getPath()) | ||
.routingAsync( | ||
request -> { | ||
String id = request.queryString("id").orElse(null); | ||
return CompletableFuture.supplyAsync( | ||
() -> | ||
controller( | ||
INDEXED_CHILD, | ||
() -> { | ||
INDEXED_CHILD.collectSpanAttributes( | ||
name -> "id".equals(name) ? id : null); | ||
return Results.status( | ||
INDEXED_CHILD.getStatus(), INDEXED_CHILD.getBody()); | ||
}), | ||
executionContextExecutor); | ||
}) | ||
.build()); | ||
} | ||
|
||
@Override | ||
protected void stopServer(Server server) { | ||
server.stop(); | ||
executor.shutdown(); | ||
} | ||
} |
Oops, something went wrong.