forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Setting to Toggle Data Source Management Code Paths (opensearch…
…-project#2723) Signed-off-by: Frank Dattalo <[email protected]>
- Loading branch information
Showing
17 changed files
with
809 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...query/src/test/java/org/opensearch/sql/spark/rest/RestAsyncQueryManagementActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.opensearch.sql.spark.rest; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonObject; | ||
import lombok.SneakyThrows; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.ArgumentMatchers; | ||
import org.mockito.Mockito; | ||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.rest.RestChannel; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.rest.RestResponse; | ||
import org.opensearch.sql.common.setting.Settings; | ||
import org.opensearch.sql.opensearch.setting.OpenSearchSettings; | ||
import org.opensearch.threadpool.ThreadPool; | ||
|
||
public class RestAsyncQueryManagementActionTest { | ||
|
||
private OpenSearchSettings settings; | ||
private RestRequest request; | ||
private RestChannel channel; | ||
private NodeClient nodeClient; | ||
private ThreadPool threadPool; | ||
private RestAsyncQueryManagementAction unit; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
settings = Mockito.mock(OpenSearchSettings.class); | ||
request = Mockito.mock(RestRequest.class); | ||
channel = Mockito.mock(RestChannel.class); | ||
nodeClient = Mockito.mock(NodeClient.class); | ||
threadPool = Mockito.mock(ThreadPool.class); | ||
|
||
Mockito.when(nodeClient.threadPool()).thenReturn(threadPool); | ||
|
||
unit = new RestAsyncQueryManagementAction(settings); | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
public void testWhenDataSourcesAreDisabled() { | ||
setDataSourcesEnabled(false); | ||
unit.handleRequest(request, channel, nodeClient); | ||
Mockito.verifyNoInteractions(nodeClient); | ||
ArgumentCaptor<RestResponse> response = ArgumentCaptor.forClass(RestResponse.class); | ||
Mockito.verify(channel, Mockito.times(1)).sendResponse(response.capture()); | ||
Assertions.assertEquals(400, response.getValue().status().getStatus()); | ||
JsonObject actualResponseJson = | ||
new Gson().fromJson(response.getValue().content().utf8ToString(), JsonObject.class); | ||
JsonObject expectedResponseJson = new JsonObject(); | ||
expectedResponseJson.addProperty("status", 400); | ||
expectedResponseJson.add("error", new JsonObject()); | ||
expectedResponseJson.getAsJsonObject("error").addProperty("type", "IllegalAccessException"); | ||
expectedResponseJson.getAsJsonObject("error").addProperty("reason", "Invalid Request"); | ||
expectedResponseJson | ||
.getAsJsonObject("error") | ||
.addProperty("details", "plugins.query.datasources.enabled setting is false"); | ||
Assertions.assertEquals(expectedResponseJson, actualResponseJson); | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
public void testWhenDataSourcesAreEnabled() { | ||
setDataSourcesEnabled(true); | ||
Mockito.when(request.method()).thenReturn(RestRequest.Method.GET); | ||
unit.handleRequest(request, channel, nodeClient); | ||
Mockito.verify(threadPool, Mockito.times(1)) | ||
.schedule(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any()); | ||
Mockito.verifyNoInteractions(channel); | ||
} | ||
|
||
@Test | ||
public void testGetName() { | ||
Assertions.assertEquals("async_query_actions", unit.getName()); | ||
} | ||
|
||
private void setDataSourcesEnabled(boolean value) { | ||
Mockito.when(settings.getSettingValue(Settings.Key.DATASOURCES_ENABLED)).thenReturn(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.