Skip to content

Commit

Permalink
Addressed PR Comments
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <[email protected]>
  • Loading branch information
owaiskazi19 committed Jul 12, 2022
1 parent 3a1caa8 commit 20d0d58
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/opensearch/sdk/ActionListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import java.net.Socket;
import java.net.UnknownHostException;

/**
* The class for Action Listener to run SDK
*/
public class ActionListener {

@SuppressForbidden(reason = "need local ephemeral port")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import java.io.IOException;

/**
* Transport Response Handler class for Cluster Settings API
*/
public class ClusterSettingsResponseHandler implements TransportResponseHandler<ClusterSettingsResponse> {
private static final Logger logger = LogManager.getLogger(ClusterSettingsResponseHandler.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import java.io.IOException;

/**
* Transport Response Handler class for Cluster State API
*/
public class ClusterStateResponseHandler implements TransportResponseHandler<ClusterStateResponse> {
private static final Logger logger = LogManager.getLogger(ClusterStateResponseHandler.class);

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/opensearch/sdk/ExtensionSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

package org.opensearch.sdk;

/**
* The class to read extension properties
*/
public class ExtensionSettings {

private String extensionname;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/opensearch/sdk/ExtensionsRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
import static java.util.Collections.emptySet;
import static org.opensearch.common.UUIDs.randomBase64UUID;

/**
* The main class for OpenSearch SDK
*/
public class ExtensionsRunner {
private ExtensionSettings extensionSettings = readExtensionSettings();
private DiscoveryNode opensearchNode;
Expand Down Expand Up @@ -144,7 +147,7 @@ public Netty4Transport getNetty4Transport(Settings settings, ThreadPool threadPo
return transport;
}

public TransportService createTransportService(Settings settings) throws IOException {
public TransportService createTransportService(Settings settings){

ThreadPool threadPool = new ThreadPool(settings);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import java.io.IOException;

/**
* Transport Response Handler class for Local Node API
*/
public class LocalNodeResponseHandler implements TransportResponseHandler<LocalNodeResponse> {
private static final Logger logger = LogManager.getLogger(LocalNodeResponseHandler.class);

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/opensearch/sdk/TestExtensionSettings.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.opensearch.sdk;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.opensearch.test.OpenSearchTestCase;

public class TestExtensionSettings extends OpenSearchTestCase {

private ExtensionSettings extensionSettings;
private static ExtensionSettings extensionSettings;

@BeforeEach
public void setUp() {
@BeforeAll
public static void setup() {
extensionSettings = new ExtensionSettings();
}

Expand Down
17 changes: 9 additions & 8 deletions src/test/java/org/opensearch/sdk/TestExtensionsRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.mockito.Mockito.mock;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;

import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -61,13 +62,13 @@ public void setUp() throws Exception {

// test ExtensionsRunner getTransportService return type is transport service
@Test
public void testGetTransportService() throws Exception {
public void testGetTransportService() {
assert (extensionsRunner.createTransportService(settings) instanceof TransportService);
}

// test manager method invokes start on transport service
@Test
public void testTransportServiceStarted() throws Exception {
public void testTransportServiceStarted() {

// verify mocked object interaction in manager method
extensionsRunner.startTransportService(transportService);
Expand All @@ -76,22 +77,22 @@ public void testTransportServiceStarted() throws Exception {

// test manager method invokes accept incoming requests on transport service
@Test
public void testTransportServiceAcceptedIncomingRequests() throws Exception {
public void testTransportServiceAcceptedIncomingRequests() {

// verify mocked object interaction in manager method
extensionsRunner.startTransportService(transportService);
verify(transportService, times(1)).acceptIncomingRequests();
}

@Test
public void testRegisterRequestHandler() throws Exception {
public void testRegisterRequestHandler() {

extensionsRunner.startTransportService(transportService);
verify(transportService, times(3)).registerRequestHandler(anyString(), anyString(), anyBoolean(), anyBoolean(), any(), any());
}

@Test
public void testHandlePluginsRequest() throws Exception {
public void testHandlePluginsRequest() throws UnknownHostException {
DiscoveryNode sourceNode = new DiscoveryNode(
"test_node",
new TransportAddress(InetAddress.getByName("localhost"), 9876),
Expand All @@ -108,23 +109,23 @@ public void testHandlePluginsRequest() throws Exception {
}

@Test
public void testClusterStateRequest() throws Exception {
public void testClusterStateRequest() {

extensionsRunner.sendClusterStateRequest(transportService);

verify(transportService, times(1)).sendRequest(any(), anyString(), any(), any());
}

@Test
public void testClusterSettingRequest() throws Exception {
public void testClusterSettingRequest() {

extensionsRunner.sendClusterSettingRequest(transportService);

verify(transportService, times(1)).sendRequest(any(), anyString(), any(), any());
}

@Test
public void testLocalNodeRequest() throws Exception {
public void testLocalNodeRequest() {

extensionsRunner.sendLocalNodeRequest(transportService);

Expand Down

0 comments on commit 20d0d58

Please sign in to comment.