Skip to content

Commit 5be895f

Browse files
committed
Update
1 parent 6c6be3d commit 5be895f

File tree

3 files changed

+130
-105
lines changed

3 files changed

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

6-
package io.opentelemetry.javaagent.instrumentation.play.v2_6.server;
6+
package io.opentelemetry.javaagent.instrumentation.play.v2_6;
77

88
import static io.opentelemetry.api.trace.SpanKind.INTERNAL;
99
import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS;
@@ -132,6 +132,4 @@ public SpanDataAssert assertHandlerSpan(
132132
}
133133
return span;
134134
}
135-
136-
public abstract Server setupServer(int port);
137135
}

instrumentation/play/play-mvc/play-mvc-2.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/play/v2_6/server/PlayAsyncServerTest.java

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

0 commit comments

Comments
 (0)