Skip to content

Commit

Permalink
Address code review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Jan 28, 2023
1 parent 49ab274 commit 6819b69
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/main/java/org/opensearch/sdk/SDKClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,29 +196,29 @@ 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}.
*
* @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());
}

/**
Expand All @@ -231,7 +231,7 @@ public SDKIndicesClient indices() {
* @see Requests#indexRequest(String)
*/
public void index(IndexRequest request, ActionListener<IndexResponse> listener) {
rhlc.indexAsync(request, RequestOptions.DEFAULT, listener);
restHighLevelClient.indexAsync(request, RequestOptions.DEFAULT, listener);
}

/**
Expand All @@ -242,7 +242,7 @@ public void index(IndexRequest request, ActionListener<IndexResponse> listener)
* @see Requests#getRequest(String)
*/
public void get(GetRequest request, ActionListener<GetResponse> listener) {
rhlc.getAsync(request, RequestOptions.DEFAULT, listener);
restHighLevelClient.getAsync(request, RequestOptions.DEFAULT, listener);
}

/**
Expand All @@ -253,7 +253,7 @@ public void get(GetRequest request, ActionListener<GetResponse> listener) {
* @see Requests#deleteRequest(String)
*/
public void delete(DeleteRequest request, ActionListener<DeleteResponse> listener) {
rhlc.deleteAsync(request, RequestOptions.DEFAULT, listener);
restHighLevelClient.deleteAsync(request, RequestOptions.DEFAULT, listener);
}

/**
Expand All @@ -264,12 +264,12 @@ public void delete(DeleteRequest request, ActionListener<DeleteResponse> listene
* @see Requests#searchRequest(String...)
*/
public void search(SearchRequest request, ActionListener<SearchResponse> listener) {
rhlc.searchAsync(request, RequestOptions.DEFAULT, listener);
restHighLevelClient.searchAsync(request, RequestOptions.DEFAULT, listener);
}

@Override
public void close() throws IOException {
rhlc.close();
restHighLevelClient.close();
}
}

Expand Down
23 changes: 20 additions & 3 deletions src/test/java/org/opensearch/sdk/TestSDKClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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();
}

}

0 comments on commit 6819b69

Please sign in to comment.