This is an automated email from the ASF dual-hosted git repository.

michaelsmith pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git


The following commit(s) were added to refs/heads/master by this push:
     new ed0dfc665 IMPALA-14363: Always close WebClient
ed0dfc665 is described below

commit ed0dfc665ee5f988561a77ee17cf1b7a607c9cf9
Author: Michael Smith <michael.sm...@cloudera.com>
AuthorDate: Wed Aug 27 16:09:48 2025 -0700

    IMPALA-14363: Always close WebClient
    
    Make WebClient autocloseable and always close it, either in test cleanup
    or using the Java try-with-resources statement.
    
    Change-Id: Ib6e03558ce31ee527e87bf6632d39d1d94076472
    Reviewed-on: http://gerrit.cloudera.org:8080/23355
    Reviewed-by: Impala Public Jenkins <impala-public-jenk...@cloudera.com>
    Tested-by: Michael Smith <michael.sm...@cloudera.com>
---
 .../apache/impala/customcluster/JwtHttpTest.java   |   2 +-
 .../impala/customcluster/JwtWebserverTest.java     |   2 +-
 .../apache/impala/customcluster/LdapHS2Test.java   |   6 +
 .../impala/customcluster/LdapImpalaShellTest.java  |   6 +
 .../impala/customcluster/LdapImpylaHttpTest.java   |   1 +
 .../apache/impala/customcluster/LdapJdbcTest.java  |   6 +
 .../impala/customcluster/LdapWebserverTest.java    | 278 +++++++++++----------
 .../impala/customcluster/SpnegoAuthTest.java       |   6 +
 .../java/org/apache/impala/testutil/WebClient.java |   4 +-
 9 files changed, 179 insertions(+), 132 deletions(-)

diff --git a/fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java 
b/fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
index b3b016b1c..0ddb9e7fe 100644
--- a/fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
+++ b/fe/src/test/java/org/apache/impala/customcluster/JwtHttpTest.java
@@ -144,7 +144,7 @@ public class JwtHttpTest {
     // JWKS file.
     CustomClusterRunner.StartImpalaCluster();
     if (createJWKSForWebServer_) deleteTempJWKSFromWebServerRootDir();
-    client_.Close();
+    client_.close();
   }
 
   private void createTempJWKSInWebServerRootDir(String srcFilename) {
diff --git 
a/fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java 
b/fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
index 366e95a20..ed8f3b1af 100644
--- a/fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
+++ b/fe/src/test/java/org/apache/impala/customcluster/JwtWebserverTest.java
@@ -53,7 +53,7 @@ public class JwtWebserverTest {
   public void cleanUp() throws Exception {
     // Leave a cluster running with the default configuration.
     CustomClusterRunner.StartImpalaCluster();
-    client_.Close();
+    client_.close();
   }
 
   private void verifyAuthMetrics(
diff --git a/fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java 
b/fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
index fbb980715..b7619f24b 100644
--- a/fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
+++ b/fe/src/test/java/org/apache/impala/customcluster/LdapHS2Test.java
@@ -38,6 +38,7 @@ import org.apache.hive.service.rpc.thrift.*;
 import org.apache.impala.testutil.WebClient;
 import org.apache.thrift.transport.THttpClient;
 import org.apache.thrift.protocol.TBinaryProtocol;
+import org.junit.After;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -71,6 +72,11 @@ public class LdapHS2Test {
     assertEquals(ret, 0);
   }
 
+  @After
+  public void cleanUp() throws Exception {
+    client_.close();
+  }
+
   static void verifySuccess(TStatus status) throws Exception {
     if (status.getStatusCode() == TStatusCode.SUCCESS_STATUS
         || status.getStatusCode() == TStatusCode.SUCCESS_WITH_INFO_STATUS) {
diff --git 
a/fe/src/test/java/org/apache/impala/customcluster/LdapImpalaShellTest.java 
b/fe/src/test/java/org/apache/impala/customcluster/LdapImpalaShellTest.java
index bc301010d..d1e96b270 100644
--- a/fe/src/test/java/org/apache/impala/customcluster/LdapImpalaShellTest.java
+++ b/fe/src/test/java/org/apache/impala/customcluster/LdapImpalaShellTest.java
@@ -34,6 +34,7 @@ import 
org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.annotations.ApplyLdifFiles;
 import org.apache.directory.server.core.integ.CreateLdapServerRule;
 import org.apache.impala.testutil.WebClient;
+import org.junit.After;
 import org.junit.Assume;
 import org.junit.ClassRule;
 
@@ -65,6 +66,11 @@ public class LdapImpalaShellTest {
     verifyMetrics(zero, zero, zero, zero);
   }
 
+  @After
+  public void cleanUp() throws Exception {
+    client_.close();
+  }
+
   protected int startImpalaCluster(String args) throws IOException, 
InterruptedException {
     return CustomClusterRunner.StartImpalaCluster(args);
   }
diff --git 
a/fe/src/test/java/org/apache/impala/customcluster/LdapImpylaHttpTest.java 
b/fe/src/test/java/org/apache/impala/customcluster/LdapImpylaHttpTest.java
index a5c5a0de4..ff1ea9a02 100644
--- a/fe/src/test/java/org/apache/impala/customcluster/LdapImpylaHttpTest.java
+++ b/fe/src/test/java/org/apache/impala/customcluster/LdapImpylaHttpTest.java
@@ -89,6 +89,7 @@ public class LdapImpylaHttpTest {
   @After
   public void cleanUp() throws Exception {
     CustomClusterRunner.StartImpalaCluster();
+    client_.close();
   }
 
   private void verifyMetrics(Range<Long> expectedBasicSuccess,
diff --git a/fe/src/test/java/org/apache/impala/customcluster/LdapJdbcTest.java 
b/fe/src/test/java/org/apache/impala/customcluster/LdapJdbcTest.java
index d2cb25bf0..3b69e71e2 100644
--- a/fe/src/test/java/org/apache/impala/customcluster/LdapJdbcTest.java
+++ b/fe/src/test/java/org/apache/impala/customcluster/LdapJdbcTest.java
@@ -35,6 +35,7 @@ import 
org.apache.directory.server.core.annotations.ApplyLdifFiles;
 import org.apache.directory.server.core.integ.CreateLdapServerRule;
 import org.apache.impala.testutil.ImpalaJdbcClient;
 import org.apache.impala.testutil.WebClient;
+import org.junit.After;
 import org.junit.ClassRule;
 import org.junit.Test;
 
@@ -82,6 +83,11 @@ public class LdapJdbcTest extends JdbcTestBase {
     }
   }
 
+  @After
+  public void cleanUp() throws Exception {
+    client_.close();
+  }
+
   private void verifyMetrics(Range<Long> expectedBasicSuccess,
       Range<Long> expectedBasicFailure, Range<Long> expectedCookieSuccess,
       Range<Long> expectedCookieFailure) throws Exception {
diff --git 
a/fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java 
b/fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
index abbaceb18..7850c254e 100644
--- a/fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
+++ b/fe/src/test/java/org/apache/impala/customcluster/LdapWebserverTest.java
@@ -90,7 +90,7 @@ public class LdapWebserverTest {
 
   @After
   public void cleanUp() throws IOException {
-    client_.Close();
+    client_.close();
   }
 
   private void verifyMetrics(Range<Long> expectedBasicSuccess,
@@ -150,18 +150,20 @@ public class LdapWebserverTest {
     verifyMetrics(Range.atLeast(1L), zero, Range.atLeast(1L), zero);
 
     // Attempt to access the webserver without a username/password.
-    WebClient noUsername = new WebClient();
-    String result = noUsername.readContent("/");
-    assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
-    // Check that there is one unsuccessful auth attempt.
-    verifyMetrics(Range.atLeast(1L), Range.closed(1L, 1L), Range.atLeast(1L), 
zero);
+    try (WebClient noUsername = new WebClient()) {
+      String result = noUsername.readContent("/");
+      assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
+      // Check that there is one unsuccessful auth attempt.
+      verifyMetrics(Range.atLeast(1L), Range.closed(1L, 1L), 
Range.atLeast(1L), zero);
+    }
 
     // Attempt to access the webserver with invalid username/password.
-    WebClient invalidUserPass = new WebClient("invalid", "invalid");
-    result = invalidUserPass.readContent("/");
-    assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
-    // Check that there is now two unsuccessful auth attempts.
-    verifyMetrics(Range.atLeast(1L), Range.closed(2L, 2L), Range.atLeast(1L), 
zero);
+    try (WebClient invalidUserPass = new WebClient("invalid", "invalid")) {
+      String result = invalidUserPass.readContent("/");
+      assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
+      // Check that there is now two unsuccessful auth attempts.
+      verifyMetrics(Range.atLeast(1L), Range.closed(2L, 2L), 
Range.atLeast(1L), zero);
+    }
   }
 
   /**
@@ -185,26 +187,29 @@ public class LdapWebserverTest {
 
     // Access the webserver with a user that passes the group filter but not 
the user
     // filter, should fail.
-    WebClient user2 = new WebClient(TEST_USER_2, TEST_PASSWORD_2);
-    String result = user2.readContent("/");
-    assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
-    // Check that there is one unsuccessful auth attempt.
-    verifyMetrics(Range.atLeast(1L), Range.closed(1L, 1L), Range.atLeast(1L), 
zero);
+    try (WebClient user2 = new WebClient(TEST_USER_2, TEST_PASSWORD_2)) {
+      String result = user2.readContent("/");
+      assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
+      // Check that there is one unsuccessful auth attempt.
+      verifyMetrics(Range.atLeast(1L), Range.closed(1L, 1L), 
Range.atLeast(1L), zero);
+    }
 
     // Access the webserver with a user that passes the user filter but not 
the group
     // filter, should fail.
-    WebClient user3 = new WebClient(TEST_USER_3, TEST_PASSWORD_3);
-    result = user3.readContent("/");
-    assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
-    // Check that there is now two unsuccessful auth attempts.
-    verifyMetrics(Range.atLeast(1L), Range.closed(2L, 2L), Range.atLeast(1L), 
zero);
+    try (WebClient user3 = new WebClient(TEST_USER_3, TEST_PASSWORD_3)) {
+      String result = user3.readContent("/");
+      assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
+      // Check that there is now two unsuccessful auth attempts.
+      verifyMetrics(Range.atLeast(1L), Range.closed(2L, 2L), 
Range.atLeast(1L), zero);
+    }
 
     // Access the webserver with a user that doesn't pass either filter, 
should fail.
-    WebClient user4 = new WebClient(TEST_USER_4, TEST_PASSWORD_4);
-    result = user4.readContent("/");
-    assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
-    // Check that there is now three unsuccessful auth attempts.
-    verifyMetrics(Range.atLeast(1L), Range.closed(3L, 3L), Range.atLeast(1L), 
zero);
+    try (WebClient user4 = new WebClient(TEST_USER_4, TEST_PASSWORD_4)) {
+      String result = user4.readContent("/");
+      assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
+      // Check that there is now three unsuccessful auth attempts.
+      verifyMetrics(Range.atLeast(1L), Range.closed(3L, 3L), 
Range.atLeast(1L), zero);
+    }
   }
 
   /**
@@ -219,40 +224,43 @@ public class LdapWebserverTest {
            "--metrics_webserver_port=25011 ",
            "--metrics_webserver_port=25031 ");
     // Attempt to access the regular webserver without a username/password, 
should fail.
-    WebClient noUsername = new WebClient();
-    String result = noUsername.readContent("/");
-    assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
+    try (WebClient noUsername = new WebClient()) {
+      String result = noUsername.readContent("/");
+      assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
+    }
 
     // Attempt to access the regular webserver with invalid username/password.
-    WebClient invalidUserPass = new WebClient("invalid", "invalid");
-    result = invalidUserPass.readContent("/");
-    assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
+    try (WebClient invalidUserPass = new WebClient("invalid", "invalid")) {
+      String result = invalidUserPass.readContent("/");
+      assertTrue(result, result.contains("Must authenticate with Basic 
authentication."));
+    }
 
     // Attempt to access the metrics webserver without a username/password.
-    WebClient noUsernameMetrics = new WebClient(25040);
-    WebClient catalogdMetrics = new WebClient(25021);
-    WebClient statestoredMetrics = new WebClient(25011);
-    WebClient admissiondMetrics = new WebClient(25031);
-    // Should succeed for the metrics endpoints.
-    for (String endpoint :
-        new String[] {"/metrics", "/jsonmetrics", "/metrics_prometheus", 
"/healthz"}) {
-      result = noUsernameMetrics.readContent(endpoint);
-      assertFalse(
-          result, result.contains("Must authenticate with Basic 
authentication."));
-      result = catalogdMetrics.readContent(endpoint);
-      assertFalse(
-          result, result.contains("Must authenticate with Basic 
authentication."));
-      result = statestoredMetrics.readContent(endpoint);
-      assertFalse(
-          result, result.contains("Must authenticate with Basic 
authentication."));
-      result = admissiondMetrics.readContent(endpoint);
-      assertFalse(
-          result, result.contains("Must authenticate with Basic 
authentication."));
-    }
-
-    for (String endpoint : new String[] {"/varz", "/backends"}) {
-      result = noUsernameMetrics.readContent(endpoint);
-      assertTrue(result, result.contains("No URI handler for"));
+    try (WebClient noUsernameMetrics = new WebClient(25040);
+         WebClient catalogdMetrics = new WebClient(25021);
+         WebClient statestoredMetrics = new WebClient(25011);
+         WebClient admissiondMetrics = new WebClient(25031)) {
+      // Should succeed for the metrics endpoints.
+      for (String endpoint :
+          new String[] {"/metrics", "/jsonmetrics", "/metrics_prometheus", 
"/healthz"}) {
+        String result = noUsernameMetrics.readContent(endpoint);
+        assertFalse(
+            result, result.contains("Must authenticate with Basic 
authentication."));
+        result = catalogdMetrics.readContent(endpoint);
+        assertFalse(
+            result, result.contains("Must authenticate with Basic 
authentication."));
+        result = statestoredMetrics.readContent(endpoint);
+        assertFalse(
+            result, result.contains("Must authenticate with Basic 
authentication."));
+        result = admissiondMetrics.readContent(endpoint);
+        assertFalse(
+            result, result.contains("Must authenticate with Basic 
authentication."));
+      }
+
+      for (String endpoint : new String[] {"/varz", "/backends"}) {
+        String result = noUsernameMetrics.readContent(endpoint);
+        assertTrue(result, result.contains("No URI handler for"));
+      }
     }
   }
 
@@ -496,53 +504,60 @@ public class LdapWebserverTest {
     params.add(new BasicNameValuePair("glog", "0"));
 
     // Test POST set_glog_level fails
-    WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    String body = client.post("/set_glog_level?json", null, params, 403);
-    assertEquals("rejected POST missing X-Requested-By header", body);
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      String body = client.post("/set_glog_level?json", null, params, 403);
+      assertEquals("rejected POST missing X-Requested-By header", body);
+    }
 
     // Test POST reset_glog_level fails
-    client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    body = client.post("/reset_glog_level?json", null, null, 403);
-    assertEquals("rejected POST missing X-Requested-By header", body);
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      String body = client.post("/reset_glog_level?json", null, null, 403);
+      assertEquals("rejected POST missing X-Requested-By header", body);
+    }
 
     // Test POST set_glog_level with X-Requested-By succeeds
-    client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    json = client.jsonPost("/set_glog_level?json", headers, params);
-    assertEquals("0", json.get("glog_level"));
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      json = client.jsonPost("/set_glog_level?json", headers, params);
+      assertEquals("0", json.get("glog_level"));
+    }
 
     // Test POST reset_glog_level with X-Requested-By succeeds
-    client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    json = client.jsonPost("/reset_glog_level?json", headers, null);
-    assertEquals("1", json.get("glog_level"));
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      json = client.jsonPost("/reset_glog_level?json", headers, null);
+      assertEquals("1", json.get("glog_level"));
+    }
 
     // Test POST set_glog_level with cookie gives 403
-    client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    json = client.jsonGet("/log_level?json");
-    assertEquals("1", json.get("glog_level"));
-    body = client.post("/set_glog_level?json", null, params, 403);
-    assertEquals("", body);
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      json = client.jsonGet("/log_level?json");
+      assertEquals("1", json.get("glog_level"));
+      String body = client.post("/set_glog_level?json", null, params, 403);
+      assertEquals("", body);
+    }
 
     // Test POST reset_glog_level with cookie gives 403
-    client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    json = client.jsonGet("/log_level?json");
-    assertEquals("1", json.get("glog_level"));
-    body = client.post("/reset_glog_level?json", null, null, 403);
-    assertEquals("", body);
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      json = client.jsonGet("/log_level?json");
+      assertEquals("1", json.get("glog_level"));
+      String body = client.post("/reset_glog_level?json", null, null, 403);
+      assertEquals("", body);
+    }
 
     // Create a new client, get a cookie, and add csrf_token based on the 
cookie
-    client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    json = client.jsonGet("/log_level?json");
-    assertEquals("1", json.get("glog_level"));
-    String rand = getRandToken(client.getCookies());
-    params.add(new BasicNameValuePair("csrf_token", rand));
-
-    // Test POST set_glog_level with cookie and csrf_token succeeds
-    json = client.jsonPost("/set_glog_level?json", null, params);
-    assertEquals("0", json.get("glog_level"));
-
-    // Test POST reset_glog_level with cookie and csrf_token succeeds
-    json = client.jsonPost("/reset_glog_level?json", null, params);
-    assertEquals("1", json.get("glog_level"));
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      json = client.jsonGet("/log_level?json");
+      assertEquals("1", json.get("glog_level"));
+      String rand = getRandToken(client.getCookies());
+      params.add(new BasicNameValuePair("csrf_token", rand));
+
+      // Test POST set_glog_level with cookie and csrf_token succeeds
+      json = client.jsonPost("/set_glog_level?json", null, params);
+      assertEquals("0", json.get("glog_level"));
+
+      // Test POST reset_glog_level with cookie and csrf_token succeeds
+      json = client.jsonPost("/reset_glog_level?json", null, params);
+      assertEquals("1", json.get("glog_level"));
+    }
   }
 
   /*
@@ -572,55 +587,62 @@ public class LdapWebserverTest {
     params.add(new BasicNameValuePair("level", "WARN"));
 
     // Test POST set_java_loglevel fails
-    WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    String body = client.post("/set_java_loglevel?json", null, params, 403);
-    assertEquals("rejected POST missing X-Requested-By header", body);
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      String body = client.post("/set_java_loglevel?json", null, params, 403);
+      assertEquals("rejected POST missing X-Requested-By header", body);
+    }
 
     // Test POST reset_java_loglevel fails
-    client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    body = client.post("/reset_java_loglevel?json", null, null, 403);
-    assertEquals("rejected POST missing X-Requested-By header", body);
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      String body = client.post("/reset_java_loglevel?json", null, null, 403);
+      assertEquals("rejected POST missing X-Requested-By header", body);
+    }
 
     // Test POST set_glog_level with X-Requested-By succeeds
-    client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    json = client.jsonPost("/set_java_loglevel?json", headers, params);
-    assertEquals("org.apache : WARN\norg.apache.impala : DEBUG\n",
-        json.get("get_java_loglevel_result"));
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      json = client.jsonPost("/set_java_loglevel?json", headers, params);
+      assertEquals("org.apache : WARN\norg.apache.impala : DEBUG\n",
+          json.get("get_java_loglevel_result"));
+    }
 
     // Test POST reset_glog_level with X-Requested-By succeeds
-    client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    json = client.jsonPost("/reset_java_loglevel?json", headers, null);
-    assertEquals("org.apache.impala : DEBUG\n", 
json.get("get_java_loglevel_result"));
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      json = client.jsonPost("/reset_java_loglevel?json", headers, null);
+      assertEquals("org.apache.impala : DEBUG\n", 
json.get("get_java_loglevel_result"));
+    }
 
     // Test POST set_java_loglevel with cookie gives 403
-    client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    json = client.jsonGet("/log_level?json");
-    assertEquals("org.apache.impala : DEBUG\n", 
json.get("get_java_loglevel_result"));
-    body = client.post("/set_java_loglevel?json", null, params, 403);
-    assertEquals("", body);
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      json = client.jsonGet("/log_level?json");
+      assertEquals("org.apache.impala : DEBUG\n", 
json.get("get_java_loglevel_result"));
+      String body = client.post("/set_java_loglevel?json", null, params, 403);
+      assertEquals("", body);
+    }
 
     // Test POST reset_java_loglevel with cookie gives 403
-    client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    json = client.jsonGet("/log_level?json");
-    assertEquals("org.apache.impala : DEBUG\n", 
json.get("get_java_loglevel_result"));
-    body = client.post("/reset_java_loglevel?json", null, null, 403);
-    assertEquals("", body);
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      json = client.jsonGet("/log_level?json");
+      assertEquals("org.apache.impala : DEBUG\n", 
json.get("get_java_loglevel_result"));
+      String body = client.post("/reset_java_loglevel?json", null, null, 403);
+      assertEquals("", body);
+    }
 
     // Create a new client, get a cookie, and add csrf_token based on the 
cookie
-    client = new WebClient(TEST_USER_1, TEST_PASSWORD_1);
-    json = client.jsonGet("/log_level?json");
-    assertEquals("org.apache.impala : DEBUG\n", 
json.get("get_java_loglevel_result"));
-    String rand = getRandToken(client.getCookies());
-    params.add(new BasicNameValuePair("csrf_token", rand));
-
-    // Test POST set_java_loglevel with cookie and csrf_token succeeds
-    json = client.jsonPost("/set_java_loglevel?json", null, params);
-    assertEquals("org.apache : WARN\norg.apache.impala : DEBUG\n",
-        json.get("get_java_loglevel_result"));
-
-    // Test POST reset_java_loglevel with cookie and csrf_token succeeds
-    json = client.jsonPost("/reset_java_loglevel?json", null, params);
-    assertEquals("org.apache.impala : DEBUG\n", 
json.get("get_java_loglevel_result"));
+    try (WebClient client = new WebClient(TEST_USER_1, TEST_PASSWORD_1)) {
+      json = client.jsonGet("/log_level?json");
+      assertEquals("org.apache.impala : DEBUG\n", 
json.get("get_java_loglevel_result"));
+      String rand = getRandToken(client.getCookies());
+      params.add(new BasicNameValuePair("csrf_token", rand));
+
+      // Test POST set_java_loglevel with cookie and csrf_token succeeds
+      json = client.jsonPost("/set_java_loglevel?json", null, params);
+      assertEquals("org.apache : WARN\norg.apache.impala : DEBUG\n",
+          json.get("get_java_loglevel_result"));
+
+      // Test POST reset_java_loglevel with cookie and csrf_token succeeds
+      json = client.jsonPost("/reset_java_loglevel?json", null, params);
+      assertEquals("org.apache.impala : DEBUG\n", 
json.get("get_java_loglevel_result"));
+    }
   }
 
   private String getRandToken(List<Cookie> cookies) {
diff --git 
a/fe/src/test/java/org/apache/impala/customcluster/SpnegoAuthTest.java 
b/fe/src/test/java/org/apache/impala/customcluster/SpnegoAuthTest.java
index 09aec13db..5d4da88e9 100644
--- a/fe/src/test/java/org/apache/impala/customcluster/SpnegoAuthTest.java
+++ b/fe/src/test/java/org/apache/impala/customcluster/SpnegoAuthTest.java
@@ -64,6 +64,7 @@ import org.apache.impala.testutil.WebClient;
 import org.apache.thrift.transport.THttpClient;
 import org.apache.thrift.protocol.TBinaryProtocol;
 import org.ietf.jgss.*;
+import org.junit.After;
 import org.junit.ClassRule;
 import org.junit.rules.TemporaryFolder;
 import org.junit.Test;
@@ -104,6 +105,11 @@ public class SpnegoAuthTest {
         .build();
   }
 
+  @After
+  public void cleanUp() throws IOException {
+    client_.close();
+  }
+
   protected int startImpalaCluster(String args) throws IOException, 
InterruptedException {
     return kerberosKdcEnvironment.startImpalaClusterWithArgs(args);
   }
diff --git a/fe/src/test/java/org/apache/impala/testutil/WebClient.java 
b/fe/src/test/java/org/apache/impala/testutil/WebClient.java
index 0b2a23620..8f71acae4 100644
--- a/fe/src/test/java/org/apache/impala/testutil/WebClient.java
+++ b/fe/src/test/java/org/apache/impala/testutil/WebClient.java
@@ -47,7 +47,7 @@ import org.json.simple.parser.ParseException;
 /**
  * Utility class for interacting with the Impala webserver.
  */
-public class WebClient {
+public class WebClient implements AutoCloseable {
   private final static String WEBSERVER_HOST = "localhost";
   private final static int DEFAULT_WEBSERVER_PORT = 25000;
   private final static String JSON_METRICS = "/jsonmetrics?json";
@@ -74,7 +74,7 @@ public class WebClient {
     cookieStore_ = new BasicCookieStore();
   }
 
-  public void Close() throws IOException { httpClient_.close(); }
+  public void close() throws IOException { httpClient_.close(); }
 
   public List<Cookie> getCookies() { return cookieStore_.getCookies(); }
 

Reply via email to