From 7bde2f5c1b94edec415a658046bc1c55855df373 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Wed, 28 Sep 2022 00:05:08 +0900 Subject: [PATCH] Polish "HTTP server instrumentation TCK" See gh-3379 --- ...imingInstrumentationVerificationTests.java | 2 +- ...imingInstrumentationVerificationTests.java | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/micrometer-test/src/main/java/io/micrometer/core/instrument/HttpServerTimingInstrumentationVerificationTests.java b/micrometer-test/src/main/java/io/micrometer/core/instrument/HttpServerTimingInstrumentationVerificationTests.java index 4c33f2b1fd..92ca9fd37f 100644 --- a/micrometer-test/src/main/java/io/micrometer/core/instrument/HttpServerTimingInstrumentationVerificationTests.java +++ b/micrometer-test/src/main/java/io/micrometer/core/instrument/HttpServerTimingInstrumentationVerificationTests.java @@ -45,7 +45,7 @@ public abstract class HttpServerTimingInstrumentationVerificationTests extends I * A default is provided that should be preferred by new instrumentations. Existing * instrumentations that use a different value to maintain backwards compatibility may * override this method to run tests with a different name used in assertions. - * @return name of the meter timing http client requests + * @return name of the meter timing http server requests */ protected String timerName() { return "http.server.requests"; diff --git a/micrometer-test/src/test/java/io/micrometer/core/instrument/JettyServerTimingInstrumentationVerificationTests.java b/micrometer-test/src/test/java/io/micrometer/core/instrument/JettyServerTimingInstrumentationVerificationTests.java index c1ed3ef092..fe7aad26e0 100644 --- a/micrometer-test/src/test/java/io/micrometer/core/instrument/JettyServerTimingInstrumentationVerificationTests.java +++ b/micrometer-test/src/test/java/io/micrometer/core/instrument/JettyServerTimingInstrumentationVerificationTests.java @@ -21,7 +21,6 @@ import org.eclipse.jetty.servlet.ServletHandler; import org.junit.jupiter.api.Disabled; -import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -60,26 +59,31 @@ protected void stopInstrumentedServer() throws Exception { public static class MyWebServlet extends HttpServlet { @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - if (req.getPathInfo().contentEquals("/")) { - resp.setStatus(200); + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + if (req.getPathInfo().contentEquals(InstrumentedRoutes.ROOT)) { + resp.setStatus(HttpServletResponse.SC_OK); resp.getWriter().print("hello"); } - else if (req.getPathInfo().startsWith("/home/")) { - resp.setStatus(200); + else if (req.getPathInfo().startsWith("/hello/")) { + resp.setStatus(HttpServletResponse.SC_OK); resp.getWriter().print("hello " + "world"); } - else if (req.getPathInfo().contentEquals("/foundRedirect")) { + else if (req.getPathInfo().contentEquals(InstrumentedRoutes.REDIRECT)) { resp.sendRedirect("/"); } else { - resp.sendError(400); + resp.sendError(HttpServletResponse.SC_NOT_FOUND); } } @Override - protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - super.doPost(req, resp); + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { + if (req.getPathInfo().contentEquals(InstrumentedRoutes.ERROR)) { + resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + else { + resp.sendError(HttpServletResponse.SC_NOT_FOUND); + } } }