Skip to content
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

Add body to http server concurrency test response #13540

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object AkkaHttpTestAsyncWebServer {
override def getParameter(name: String): String =
uri.query().get(name).orNull
})
resp.withEntity("")
resp.withEntity(endpoint.getBody)
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
case REDIRECT =>
resp.withHeaders(headers.Location(endpoint.getBody))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object AkkaHttpTestSyncWebServer {
override def getParameter(name: String): String =
uri.query().get(name).orNull
})
resp.withEntity("")
resp.withEntity(endpoint.getBody)
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
case REDIRECT =>
resp.withHeaders(headers.Location(endpoint.getBody))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object AkkaHttpTestWebServer {
override def getParameter(name: String): String =
map.get(name).orNull
})
""
INDEXED_CHILD.getBody
}
}
complete(AbstractHttpServerTest.controller(INDEXED_CHILD, supplier))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Future<Response> apply(Request request) {
name ->
new QueryStringDecoder(uri)
.parameters().get(name).stream().findFirst().orElse(""));
response.content(Buf.Empty());
response.content(Buf.Utf8$.MODULE$.apply(endpoint.getBody()));
} else if (QUERY_PARAM.equals(endpoint)) {
response.content(Buf.Utf8$.MODULE$.apply(uri.getQuery()));
} else if (REDIRECT.equals(endpoint)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.glassfish.grizzly.http.server.HttpHandler;
Expand Down Expand Up @@ -52,33 +51,18 @@ public void service(Request request, Response response) throws Exception {
endpoint,
() -> {
if (endpoint.equals(SUCCESS)) {
try {
response.getWriter().write(endpoint.getBody());
} catch (IOException e) {
throw new RuntimeException(e);
}
response.getWriter().write(endpoint.getBody());
} else if (endpoint.equals(INDEXED_CHILD)) {
response.setStatus(endpoint.getStatus());
endpoint.collectSpanAttributes(request::getParameter);
response.setStatus(endpoint.getStatus());
response.getWriter().write(endpoint.getBody());
} else if (endpoint.equals(QUERY_PARAM)) {
response.setStatus(endpoint.getStatus());
try {
response.getWriter().write(request.getQueryString());
} catch (IOException e) {
throw new RuntimeException(e);
}
response.getWriter().write(request.getQueryString());
} else if (endpoint.equals(REDIRECT)) {
try {
response.sendRedirect(endpoint.getBody());
} catch (IOException e) {
throw new RuntimeException(e);
}
response.sendRedirect(endpoint.getBody());
} else if (endpoint.equals(ERROR)) {
try {
response.sendError(endpoint.getStatus(), endpoint.getBody());
} catch (IOException e) {
throw new RuntimeException(e);
}
response.sendError(endpoint.getStatus(), endpoint.getBody());
} else if (endpoint.equals(NOT_FOUND)) {
response.setStatus(endpoint.getStatus());
} else if (endpoint.equals(EXCEPTION)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void indexed_child(@Context UriInfo uriInfo, @Suspended AsyncResponse res
INDEXED_CHILD,
() -> {
INDEXED_CHILD.collectSpanAttributes(parameters::getFirst);
response.resume("");
response.resume(INDEXED_CHILD.getBody());
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void indexed_child(@Context UriInfo uriInfo, @Suspended AsyncResponse res
INDEXED_CHILD,
() -> {
INDEXED_CHILD.collectSpanAttributes(parameters::getFirst);
response.resume("");
response.resume(INDEXED_CHILD.getBody());
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent msg) {
HTTP_1_1, HttpResponseStatus.valueOf(endpoint.getStatus()));
response.setContent(responseContent);
} else if (INDEXED_CHILD.equals(endpoint)) {
responseContent = ChannelBuffers.EMPTY_BUFFER;
responseContent =
ChannelBuffers.copiedBuffer(endpoint.getBody(), CharsetUtil.UTF_8);
endpoint.collectSpanAttributes(
name ->
new QueryStringDecoder(uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg)
HttpResponseStatus.valueOf(endpoint.getStatus()),
content);
} else if (endpoint.equals(INDEXED_CHILD)) {
content = Unpooled.EMPTY_BUFFER;
content =
Unpooled.copiedBuffer(
endpoint.getBody(), CharsetUtil.UTF_8);
endpoint.collectSpanAttributes(
it ->
new QueryStringDecoder(uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static Object handle(HttpRequest request, URI uri, ServerEndpoint endpoi
new DefaultFullHttpResponse(
HTTP_1_1, HttpResponseStatus.valueOf(endpoint.getStatus()), content);
} else if (INDEXED_CHILD.equals(endpoint)) {
content = Unpooled.EMPTY_BUFFER;
content = Unpooled.copiedBuffer(endpoint.getBody(), CharsetUtil.UTF_8);
endpoint.collectSpanAttributes(
name ->
new QueryStringDecoder(uri).parameters().get(name).stream().findFirst().orElse(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object PekkoHttpTestAsyncWebServer {
override def getParameter(name: String): String =
uri.query().get(name).orNull
})
resp.withEntity("")
resp.withEntity(endpoint.getBody)
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
case REDIRECT =>
resp.withHeaders(headers.Location(endpoint.getBody))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object PekkoHttpTestServerSourceWebServer {
override def getParameter(name: String): String =
map.get(name).orNull
})
""
INDEXED_CHILD.getBody
}
}
complete(AbstractHttpServerTest.controller(INDEXED_CHILD, supplier))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object PekkoHttpTestSyncWebServer {
override def getParameter(name: String): String =
uri.query().get(name).orNull
})
resp.withEntity("")
resp.withEntity(endpoint.getBody)
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
case REDIRECT =>
resp.withHeaders(headers.Location(endpoint.getBody))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object PekkoHttpTestWebServer {
override def getParameter(name: String): String =
map.get(name).orNull
})
""
INDEXED_CHILD.getBody
}
}
complete(AbstractHttpServerTest.controller(INDEXED_CHILD, supplier))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ protected Server setupServer() {
it ->
play.mvc.Http.Context.Implicit.request()
.getQueryString(it));
return Results.status(INDEXED_CHILD.getStatus());
return Results.status(
INDEXED_CHILD.getStatus(), INDEXED_CHILD.getBody());
})))
.GET(QUERY_PARAM.getPath())
.routeAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected Server setupServer() {
() -> {
INDEXED_CHILD.collectSpanAttributes(
it -> play.mvc.Http.Context.Implicit.request().getQueryString(it));
return Results.status(INDEXED_CHILD.getStatus());
return Results.status(INDEXED_CHILD.getStatus(), INDEXED_CHILD.getBody());
}))
.GET(QUERY_PARAM.getPath())
.routeTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected Server setupServer() {
() -> {
INDEXED_CHILD.collectSpanAttributes(
it -> play.mvc.Http.Context.Implicit.request().getQueryString(it));
return Results.status(INDEXED_CHILD.getStatus());
return Results.status(INDEXED_CHILD.getStatus(), INDEXED_CHILD.getBody());
}))
.GET(QUERY_PARAM.getPath())
.routeTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected RatpackServer setupServer() throws Exception {
context
.getResponse()
.status(endpoint.getStatus())
.send();
.send(endpoint.getBody());
}))));

handlerChain.prefix(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public void handle(Request request, Response response) {
() -> {
INDEXED_CHILD.collectSpanAttributes(
name -> request.getOriginalRef().getQueryAsForm().getFirst(name).getValue());
response.setEntity(INDEXED_CHILD.getBody(), MediaType.TEXT_PLAIN);
response.setStatus(Status.valueOf(INDEXED_CHILD.getStatus()));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ public void handle(Request request, Response response) {
() -> {
INDEXED_CHILD.collectSpanAttributes(
name -> request.getOriginalRef().getQueryAsForm().getFirstValue(name));
response.setStatus(Status.valueOf(INDEXED_CHILD.getStatus()));
response.setEntity(INDEXED_CHILD.getBody(), MediaType.TEXT_PLAIN);
response.setStatus(
Status.valueOf(INDEXED_CHILD.getStatus()), INDEXED_CHILD.getBody());
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ public String represent() {
() -> {
INDEXED_CHILD.collectSpanAttributes(
name -> getRequest().getOriginalRef().getQueryAsForm().getFirstValue(name));
// INDEXED_CHILD.getBody() returns an empty string, in which case Restlet sets status to
// 204
return "child";
return INDEXED_CHILD.getBody();
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws
} else if (INDEXED_CHILD.equals(endpoint)) {
endpoint.collectSpanAttributes(req::getParameter);
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(endpoint.getBody());
} else if (QUERY_PARAM.equals(endpoint)) {
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(req.getQueryString());
Expand Down Expand Up @@ -118,6 +119,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) {
} else if (INDEXED_CHILD.equals(endpoint)) {
endpoint.collectSpanAttributes(req::getParameter);
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(endpoint.getBody());
context.complete();
} else if (QUERY_PARAM.equals(endpoint)) {
resp.setStatus(endpoint.getStatus());
Expand Down Expand Up @@ -206,6 +208,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws
} else if (INDEXED_CHILD.equals(endpoint)) {
endpoint.collectSpanAttributes(req::getParameter);
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(endpoint.getBody());
} else if (QUERY_PARAM.equals(endpoint)) {
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(req.getQueryString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws
} else if (INDEXED_CHILD.equals(endpoint)) {
endpoint.collectSpanAttributes(req::getParameter);
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(endpoint.getBody());
} else if (QUERY_PARAM.equals(endpoint)) {
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(req.getQueryString());
Expand Down Expand Up @@ -118,6 +119,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) {
} else if (INDEXED_CHILD.equals(endpoint)) {
endpoint.collectSpanAttributes(req::getParameter);
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(endpoint.getBody());
context.complete();
} else if (QUERY_PARAM.equals(endpoint)) {
resp.setStatus(endpoint.getStatus());
Expand Down Expand Up @@ -206,6 +208,7 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws
} else if (INDEXED_CHILD.equals(endpoint)) {
endpoint.collectSpanAttributes(req::getParameter);
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(endpoint.getBody());
} else if (QUERY_PARAM.equals(endpoint)) {
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(req.getQueryString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Mono<String> indexed_child(ServerHttpRequest request, ServerHttpResponse respons
() -> {
endpoint.collectSpanAttributes(it -> request.getQueryParams().getFirst(it));
setStatus(response, endpoint);
return "";
return endpoint.getBody();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) {
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(endpoint.getBody());
} else if (endpoint.equals(INDEXED_CHILD)) {
endpoint.collectSpanAttributes(x -> req.getParameter(x));
endpoint.collectSpanAttributes(req::getParameter);
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(endpoint.getBody());
} else if (endpoint.equals(QUERY_PARAM)) {
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(req.getQueryString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) {
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(endpoint.getBody());
} else if (endpoint.equals(INDEXED_CHILD)) {
endpoint.collectSpanAttributes(x -> req.getParameter(x));
endpoint.collectSpanAttributes(req::getParameter);
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(endpoint.getBody());
} else if (endpoint.equals(QUERY_PARAM)) {
resp.setStatus(endpoint.getStatus());
resp.getWriter().print(req.getQueryString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void configure(Router router) {
() -> {
INDEXED_CHILD.collectSpanAttributes(
parameter -> ctx.request().params().get(parameter));
ctx.response().setStatusCode(INDEXED_CHILD.getStatus()).end();
ctx.response().setStatusCode(INDEXED_CHILD.getStatus()).end(INDEXED_CHILD.getBody());
}));

router
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ void configure(Router router) {
() -> {
INDEXED_CHILD.collectSpanAttributes(
parameter -> ctx.request().params().get(parameter));
ctx.response().setStatusCode(INDEXED_CHILD.getStatus()).end();
ctx.response()
.setStatusCode(INDEXED_CHILD.getStatus())
.end(INDEXED_CHILD.getBody());
}));

router
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void handle(RoutingContext ctx) {
INDEXED_CHILD,
() -> {
INDEXED_CHILD.collectSpanAttributes(it -> ctx.request().getParam(it));
end(ctx.response().setStatusCode(INDEXED_CHILD.getStatus()));
end(ctx.response().setStatusCode(INDEXED_CHILD.getStatus()), INDEXED_CHILD.getBody());
return null;
}));
router
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ void highConcurrency() throws InterruptedException {
TextMapPropagator propagator = GlobalOpenTelemetry.getPropagators().getTextMapPropagator();
TextMapSetter<HttpRequestBuilder> setter = HttpRequestBuilder::header;

List<String> responses = new ArrayList<>();
for (int i = 0; i < count; i++) {
int index = i;
HttpRequestBuilder request =
Expand All @@ -419,10 +420,22 @@ void highConcurrency() throws InterruptedException {
client
.execute(request.build())
.aggregate()
.whenComplete((result, throwable) -> latch.countDown());
.whenComplete(
(result, throwable) -> {
if (throwable != null) {
responses.add(throwable.toString());
} else {
responses.add(result.status().code() + " " + result.contentUtf8());
}
latch.countDown();
});
});
}
latch.await();
assertThat(responses)
.allSatisfy(
response ->
assertThat(response).isEqualTo(endpoint.getStatus() + " " + endpoint.getBody()));

assertHighConcurrency(count);
}
Expand Down
Loading
Loading