From 32d81d886d9aefa93be4a82e59986f36200c8ad3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 4 Apr 2023 11:34:48 +0000 Subject: [PATCH] Fix compilation issues (after changes in main) (#423) Signed-off-by: Andriy Redko (cherry picked from commit 76916f4fc20044e771b3e7123989e6b39acf5ce9) Signed-off-by: github-actions[bot] --- .../opensearch/client/opensearch/IOUtils.java | 24 +++++++++++++++++++ .../OpenSearchJavaClientTestCase.java | 6 ++--- .../opensearch/json/JsonpMapperTest.java | 5 ++-- 3 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 java-client/src/test/java/org/opensearch/client/opensearch/IOUtils.java diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/IOUtils.java b/java-client/src/test/java/org/opensearch/client/opensearch/IOUtils.java new file mode 100644 index 0000000000..b88bb3abbe --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/IOUtils.java @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch; + +import java.io.Closeable; +import java.io.IOException; + +public final class IOUtils { + public static void closeQueitly(final Closeable closeable) { + try { + if (closeable != null) { + closeable.close(); + } + } catch (final IOException | RuntimeException e) { + // Do nothing + } + } +} diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java index 7a02d980d5..6dacb20f41 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java @@ -11,6 +11,7 @@ import org.opensearch.Version; import org.opensearch.client.RestClient; import org.opensearch.client.RestClientBuilder; +import org.opensearch.client.opensearch.IOUtils; import org.opensearch.client.opensearch.OpenSearchClient; import org.opensearch.client.opensearch._types.ExpandWildcard; import org.opensearch.client.opensearch.cat.IndicesResponse; @@ -28,7 +29,6 @@ import org.junit.AfterClass; import org.junit.Before; import org.opensearch.common.settings.Settings; -import org.opensearch.core.internal.io.IOUtils; import org.opensearch.test.rest.OpenSearchRestTestCase; import java.io.IOException; @@ -147,11 +147,11 @@ protected void wipeAllOSIndices() throws IOException { public static void cleanupJavaClient() throws IOException { try { if (javaClient != null) { - IOUtils.close(javaClient._transport()); + IOUtils.closeQueitly(javaClient._transport()); } if (adminJavaClient != null) { - IOUtils.close(adminJavaClient._transport()); + IOUtils.closeQueitly(adminJavaClient._transport()); } } finally { clusterHosts = null; diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/json/JsonpMapperTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/json/JsonpMapperTest.java index c365ff2632..f7b69e4082 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/json/JsonpMapperTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/json/JsonpMapperTest.java @@ -36,6 +36,8 @@ import org.opensearch.client.json.JsonpMapper; import org.opensearch.client.json.jackson.JacksonJsonpMapper; import org.opensearch.client.json.jsonb.JsonbJsonpMapper; +import org.opensearch.client.opensearch.IOUtils; + import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.MappingJsonFactory; @@ -49,7 +51,6 @@ import jakarta.json.stream.JsonParser; import org.junit.Assert; import org.junit.Test; -import org.opensearch.core.internal.io.IOUtils; import java.io.StringReader; import java.io.StringWriter; @@ -116,7 +117,7 @@ public void testJacksonCustomJsonFactory() { } testDeserialize(mapper, writer.toString()); - IOUtils.closeWhileHandlingException(writer); + IOUtils.closeQueitly(writer); } @Test