From e9e8a48777d9443f54dc25253514991fbe5ba807 Mon Sep 17 00:00:00 2001 From: jaymode Date: Fri, 15 Nov 2019 10:35:29 -0700 Subject: [PATCH] Clean up static web server in sql-client tests 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 | 6 +++++- .../xpack/sql/client/HttpClientRequestTests.java | 8 ++++++-- 2 files changed, 11 insertions(+), 3 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 cd8ff60d71c3a..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,7 +53,11 @@ public static void init() throws Exception { @AfterClass public static void cleanup() { - webServer.close(); + 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 7df82ebe1d446..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,7 +59,11 @@ public static void init() throws Exception { @AfterClass public static void cleanup() { - webServer.close(); + try { + webServer.close(); + } finally { + webServer = null; + } } public void testBinaryRequestForCLIEnabled() throws URISyntaxException { @@ -145,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),