From 6819b69f19aceb7624ab1be6ef166b1d84fd40f6 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Sat, 28 Jan 2023 10:32:44 -0800 Subject: [PATCH] Address code review comments Signed-off-by: Daniel Widdis --- .../java/org/opensearch/sdk/SDKClient.java | 18 +++++++-------- .../org/opensearch/sdk/TestSDKClient.java | 23 ++++++++++++++++--- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/opensearch/sdk/SDKClient.java b/src/main/java/org/opensearch/sdk/SDKClient.java index b1274ed8e..6763cdf47 100644 --- a/src/main/java/org/opensearch/sdk/SDKClient.java +++ b/src/main/java/org/opensearch/sdk/SDKClient.java @@ -196,7 +196,7 @@ public void close() throws IOException { @Deprecated public static class SDKRestClient implements Closeable { - private final RestHighLevelClient rhlc; + private final RestHighLevelClient restHighLevelClient; /** * Instantiate this class wrapping a {@link RestHighLevelClient}. @@ -204,21 +204,21 @@ public static class SDKRestClient implements Closeable { * @param restHighLevelClient The client to wrap. */ public SDKRestClient(RestHighLevelClient restHighLevelClient) { - this.rhlc = restHighLevelClient; + this.restHighLevelClient = restHighLevelClient; } /** * A client allowing to perform actions/operations against the cluster. */ public SDKClusterAdminClient cluster() { - return new SDKClusterAdminClient(rhlc.cluster()); + return new SDKClusterAdminClient(restHighLevelClient.cluster()); } /** * A client allowing to perform actions/operations against the indices. */ public SDKIndicesClient indices() { - return new SDKIndicesClient(rhlc.indices()); + return new SDKIndicesClient(restHighLevelClient.indices()); } /** @@ -231,7 +231,7 @@ public SDKIndicesClient indices() { * @see Requests#indexRequest(String) */ public void index(IndexRequest request, ActionListener listener) { - rhlc.indexAsync(request, RequestOptions.DEFAULT, listener); + restHighLevelClient.indexAsync(request, RequestOptions.DEFAULT, listener); } /** @@ -242,7 +242,7 @@ public void index(IndexRequest request, ActionListener listener) * @see Requests#getRequest(String) */ public void get(GetRequest request, ActionListener listener) { - rhlc.getAsync(request, RequestOptions.DEFAULT, listener); + restHighLevelClient.getAsync(request, RequestOptions.DEFAULT, listener); } /** @@ -253,7 +253,7 @@ public void get(GetRequest request, ActionListener listener) { * @see Requests#deleteRequest(String) */ public void delete(DeleteRequest request, ActionListener listener) { - rhlc.deleteAsync(request, RequestOptions.DEFAULT, listener); + restHighLevelClient.deleteAsync(request, RequestOptions.DEFAULT, listener); } /** @@ -264,12 +264,12 @@ public void delete(DeleteRequest request, ActionListener listene * @see Requests#searchRequest(String...) */ public void search(SearchRequest request, ActionListener listener) { - rhlc.searchAsync(request, RequestOptions.DEFAULT, listener); + restHighLevelClient.searchAsync(request, RequestOptions.DEFAULT, listener); } @Override public void close() throws IOException { - rhlc.close(); + restHighLevelClient.close(); } } diff --git a/src/test/java/org/opensearch/sdk/TestSDKClient.java b/src/test/java/org/opensearch/sdk/TestSDKClient.java index dacacdfaf..8bff0489a 100644 --- a/src/test/java/org/opensearch/sdk/TestSDKClient.java +++ b/src/test/java/org/opensearch/sdk/TestSDKClient.java @@ -33,9 +33,19 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; + @SuppressWarnings("deprecation") public class TestSDKClient extends OpenSearchTestCase { - SDKClient sdkClient = new SDKClient(); + private SDKClient sdkClient; + + @Override + @BeforeAll + public void setUp() throws Exception { + super.setUp(); + this.sdkClient = new SDKClient(); + } @Test public void testCreateJavaClient() throws Exception { @@ -65,7 +75,7 @@ public void testSDKRestClient() throws Exception { assertDoesNotThrow(() -> restClient.delete(new DeleteRequest(), ActionListener.wrap(r -> {}, e -> {}))); assertDoesNotThrow(() -> restClient.search(new SearchRequest(), ActionListener.wrap(r -> {}, e -> {}))); - restClient.close(); + sdkClient.doCloseHighLevelClient(); } @Test @@ -84,7 +94,14 @@ public void testSDKIndicesClient() throws Exception { ); assertInstanceOf(Cancellable.class, indicesClient.getAliases(new GetAliasesRequest(), ActionListener.wrap(r -> {}, e -> {}))); - restClient.close(); + sdkClient.doCloseHighLevelClient(); + } + + @Override + @AfterAll + public void tearDown() throws Exception { + super.tearDown(); + this.sdkClient.close(); } }