Skip to content

Commit 40210ed

Browse files
committed
Update
1 parent 5be895f commit 40210ed

File tree

8 files changed

+256
-439
lines changed

8 files changed

+256
-439
lines changed

instrumentation/play/play-mvc/play-mvc-2.6/javaagent/src/latestDepTest/groovy/server/PlayAsyncServerTest.groovy

Lines changed: 0 additions & 99 deletions
This file was deleted.

instrumentation/play/play-mvc/play-mvc-2.6/javaagent/src/latestDepTest/groovy/server/PlayServerTest.groovy

Lines changed: 0 additions & 118 deletions
This file was deleted.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package server;
7+
8+
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS;
9+
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR;
10+
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
11+
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD;
12+
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM;
13+
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT;
14+
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS;
15+
16+
import java.util.concurrent.CompletableFuture;
17+
import java.util.concurrent.ExecutorService;
18+
import java.util.concurrent.Executors;
19+
import play.Mode;
20+
import play.libs.concurrent.HttpExecution;
21+
import play.mvc.Result;
22+
import play.mvc.Results;
23+
import play.routing.RoutingDsl;
24+
import play.server.Server;
25+
import scala.concurrent.ExecutionContextExecutor;
26+
27+
class PlayAsyncServerTest extends PlayServerTest {
28+
29+
private static final ExecutorService executor = Executors.newCachedThreadPool();
30+
31+
@Override
32+
protected Server setupServer(int port) {
33+
ExecutionContextExecutor executionContextExecutor = HttpExecution.fromThread(executor);
34+
return Server.forRouter(
35+
Mode.TEST,
36+
port,
37+
components ->
38+
RoutingDsl.fromComponents(components)
39+
.GET(SUCCESS.getPath())
40+
.routingAsync(
41+
request ->
42+
CompletableFuture.supplyAsync(
43+
() ->
44+
controller(
45+
SUCCESS,
46+
() -> Results.status(SUCCESS.getStatus(), SUCCESS.getBody())),
47+
executionContextExecutor))
48+
.GET(QUERY_PARAM.getPath())
49+
.routingAsync(
50+
request ->
51+
CompletableFuture.supplyAsync(
52+
() ->
53+
controller(
54+
QUERY_PARAM,
55+
() ->
56+
Results.status(
57+
QUERY_PARAM.getStatus(), QUERY_PARAM.getBody())),
58+
executionContextExecutor))
59+
.GET(REDIRECT.getPath())
60+
.routingAsync(
61+
request ->
62+
CompletableFuture.supplyAsync(
63+
() -> controller(REDIRECT, () -> Results.found(REDIRECT.getBody())),
64+
executionContextExecutor))
65+
.GET(ERROR.getPath())
66+
.routingAsync(
67+
request ->
68+
CompletableFuture.supplyAsync(
69+
() ->
70+
controller(
71+
ERROR,
72+
() -> Results.status(ERROR.getStatus(), ERROR.getBody())),
73+
executionContextExecutor))
74+
.GET(EXCEPTION.getPath())
75+
.routingAsync(
76+
request ->
77+
CompletableFuture.supplyAsync(
78+
() -> {
79+
controller(
80+
EXCEPTION,
81+
() -> {
82+
throw new IllegalArgumentException(EXCEPTION.getBody());
83+
});
84+
return null;
85+
},
86+
executionContextExecutor))
87+
.GET(CAPTURE_HEADERS.getPath())
88+
.routingAsync(
89+
request ->
90+
CompletableFuture.supplyAsync(
91+
() ->
92+
controller(
93+
CAPTURE_HEADERS,
94+
() -> {
95+
Result result =
96+
Results.status(
97+
CAPTURE_HEADERS.getStatus(),
98+
CAPTURE_HEADERS.getBody());
99+
request
100+
.header("X-Test-Request")
101+
.ifPresent(
102+
value -> result.withHeader("X-Test-Response", value));
103+
return result;
104+
}),
105+
executionContextExecutor))
106+
.GET(INDEXED_CHILD.getPath())
107+
.routingAsync(
108+
request -> {
109+
String id = request.queryString("id").orElse(null);
110+
return CompletableFuture.supplyAsync(
111+
() ->
112+
controller(
113+
INDEXED_CHILD,
114+
() -> {
115+
INDEXED_CHILD.collectSpanAttributes(
116+
name -> "id".equals(name) ? id : null);
117+
return Results.status(
118+
INDEXED_CHILD.getStatus(), INDEXED_CHILD.getBody());
119+
}),
120+
executionContextExecutor);
121+
})
122+
.build());
123+
}
124+
125+
@Override
126+
protected void stopServer(Server server) {
127+
server.stop();
128+
executor.shutdown();
129+
}
130+
}

0 commit comments

Comments
 (0)