C0urante commented on code in PR #12434:
URL: https://github.com/apache/kafka/pull/12434#discussion_r933297318


##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/RestServerTest.java:
##########
@@ -166,19 +173,21 @@ public void testOptionsDoesNotIncludeWadlOutput() throws 
IOException {
 
         HttpOptions request = new HttpOptions("/connectors");
         request.addHeader("Content-Type", MediaType.WILDCARD);
-        CloseableHttpClient httpClient = HttpClients.createMinimal();
-        HttpHost httpHost = new HttpHost(
-            server.advertisedUrl().getHost(),
-            server.advertisedUrl().getPort()
-        );
-        CloseableHttpResponse response = httpClient.execute(httpHost, request);
-        Assert.assertEquals(MediaType.TEXT_PLAIN, 
response.getEntity().getContentType().getValue());
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        response.getEntity().writeTo(baos);
-        Assert.assertArrayEquals(
-            request.getAllowedMethods(response).toArray(),
-            new String(baos.toByteArray(), StandardCharsets.UTF_8).split(", ")
-        );
+        try (CloseableHttpClient httpClient = HttpClients.createMinimal()) {

Review Comment:
   I can understand why we went back to try-with-resources for responses, since 
we create more than one of them in some tests. But we only ever create one 
client in our tests, and it's always `HttpClients.createMinimal()`. I think 
it'd be cleaner if we went back to a single class-level `httpClient` field that 
gets closed automatically during `tearDown`. We could even unconditionally 
initialize it in `setUp` to save the trouble of repeating that line for every 
test case that uses a client.



##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/RestServerTest.java:
##########
@@ -113,6 +115,7 @@ public void testAdvertisedUri() {
 
         server = new RestServer(config);
         Assert.assertEquals("http://localhost:8080/";, 
server.advertisedUrl().toString());
+        server.stop();

Review Comment:
   Good catch!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to