From 57f57227acafd00a63fb7241945801424bb7e80b Mon Sep 17 00:00:00 2001 From: Jay Modi Date: Fri, 15 Nov 2019 13:02:21 -0700 Subject: [PATCH] Clean up static web server in sql-client tests (#49187) (#49197) The JdbcHttpClientRequestTests and HttpClientRequestTests classes both hold a static reference to a mock web server that internally uses the JDKs built-in HttpServer, which resides in a sun package that the RamUsageEstimator does not have access to. This causes builds that use a runtime of Java 8 to fail since the StaticFieldsInvariantRule is run when Java 8 is used. Relates #41526 Relates #49105 --- .../xpack/sql/jdbc/JdbcHttpClientRequestTests.java | 7 +++++-- .../xpack/sql/client/HttpClientRequestTests.java | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/JdbcHttpClientRequestTests.java b/x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/JdbcHttpClientRequestTests.java index 008bfced8fd6a..bc86c778f718b 100644 --- a/x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/JdbcHttpClientRequestTests.java +++ b/x-pack/plugin/sql/jdbc/src/test/java/org/elasticsearch/xpack/sql/jdbc/JdbcHttpClientRequestTests.java @@ -53,8 +53,11 @@ public static void init() throws Exception { @AfterClass public static void cleanup() { - webServer.close(); - webServer = null; + try { + webServer.close(); + } finally { + webServer = null; + } } public void testBinaryRequestEnabled() throws Exception { diff --git a/x-pack/plugin/sql/sql-client/src/test/java/org/elasticsearch/xpack/sql/client/HttpClientRequestTests.java b/x-pack/plugin/sql/sql-client/src/test/java/org/elasticsearch/xpack/sql/client/HttpClientRequestTests.java index 8f5837c95b3d4..01ca2bd0dade1 100644 --- a/x-pack/plugin/sql/sql-client/src/test/java/org/elasticsearch/xpack/sql/client/HttpClientRequestTests.java +++ b/x-pack/plugin/sql/sql-client/src/test/java/org/elasticsearch/xpack/sql/client/HttpClientRequestTests.java @@ -59,8 +59,11 @@ public static void init() throws Exception { @AfterClass public static void cleanup() { - webServer.close(); - webServer = null; + try { + webServer.close(); + } finally { + webServer = null; + } } public void testBinaryRequestForCLIEnabled() throws URISyntaxException { @@ -146,7 +149,7 @@ private void assertBinaryRequestForDrivers(boolean isBinary, XContentType xConte HttpClient httpClient = new HttpClient(conCfg); Mode mode = randomFrom(Mode.JDBC, Mode.ODBC); - SqlQueryRequest request = new SqlQueryRequest(query, + SqlQueryRequest request = new SqlQueryRequest(query, null, ZoneId.of("Z"), randomIntBetween(1, 100),