Skip to content

Commit

Permalink
Add unit test for ingest and script APIs of parsing cluster_manager_t…
Browse files Browse the repository at this point in the history
…imeout parameter

Signed-off-by: Tianli Feng <ftianli@amazon.com>
  • Loading branch information
Tianli Feng committed Apr 2, 2022
1 parent 70d613a commit 59260e9
Showing 1 changed file with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
import org.opensearch.OpenSearchParseException;
import org.opensearch.action.support.master.MasterNodeRequest;
import org.opensearch.client.node.NodeClient;
import org.opensearch.common.bytes.BytesArray;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.NamedXContentRegistry;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.action.admin.cluster.RestDeleteStoredScriptAction;
import org.opensearch.rest.action.admin.cluster.RestGetStoredScriptAction;
import org.opensearch.rest.action.admin.cluster.RestPutStoredScriptAction;
import org.opensearch.rest.action.cat.RestAllocationAction;
import org.opensearch.rest.action.cat.RestRepositoriesAction;
import org.opensearch.rest.action.cat.RestThreadPoolAction;
Expand All @@ -28,6 +34,9 @@
import org.opensearch.rest.action.cat.RestPendingClusterTasksAction;
import org.opensearch.rest.action.cat.RestSegmentsAction;
import org.opensearch.rest.action.cat.RestSnapshotAction;
import org.opensearch.rest.action.ingest.RestDeletePipelineAction;
import org.opensearch.rest.action.ingest.RestGetPipelineAction;
import org.opensearch.rest.action.ingest.RestPutPipelineAction;
import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.test.rest.FakeRestRequest;
import org.opensearch.threadpool.TestThreadPool;
Expand Down Expand Up @@ -179,6 +188,59 @@ public void testCatSegments() {
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE);
}

public void testDeletePipeline() {
FakeRestRequest request = new FakeRestRequest();
request.params().put("cluster_manager_timeout", "1h");
request.params().put("master_timeout", "3s");
request.params().put("id", "test");
RestDeletePipelineAction action = new RestDeletePipelineAction();
Exception e = assertThrows(OpenSearchParseException.class, () -> action.prepareRequest(request, client));
assertThat(e.getMessage(), containsString(DUPLICATE_PARAMETER_ERROR_MESSAGE));
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE);
}

public void testGetPipeline() {
RestGetPipelineAction action = new RestGetPipelineAction();
Exception e = assertThrows(OpenSearchParseException.class, () -> action.prepareRequest(getRestRequestWithBothParams(), client));
assertThat(e.getMessage(), containsString(DUPLICATE_PARAMETER_ERROR_MESSAGE));
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE);
}

public void testPutPipeline() {
FakeRestRequest request = getFakeRestRequestWithBody();
request.params().put("cluster_manager_timeout", "2m");
request.params().put("master_timeout", "3s");
request.params().put("id", "test");
RestPutPipelineAction action = new RestPutPipelineAction();
Exception e = assertThrows(OpenSearchParseException.class, () -> action.prepareRequest(request, client));
assertThat(e.getMessage(), containsString(DUPLICATE_PARAMETER_ERROR_MESSAGE));
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE);
}

public void testDeleteStoredScript() {
RestDeleteStoredScriptAction action = new RestDeleteStoredScriptAction();
Exception e = assertThrows(OpenSearchParseException.class, () -> action.prepareRequest(getRestRequestWithBothParams(), client));
assertThat(e.getMessage(), containsString(DUPLICATE_PARAMETER_ERROR_MESSAGE));
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE);
}

public void testGetStoredScript() {
RestGetStoredScriptAction action = new RestGetStoredScriptAction();
Exception e = assertThrows(OpenSearchParseException.class, () -> action.prepareRequest(getRestRequestWithBothParams(), client));
assertThat(e.getMessage(), containsString(DUPLICATE_PARAMETER_ERROR_MESSAGE));
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE);
}

public void testPutStoredScript() {
RestPutStoredScriptAction action = new RestPutStoredScriptAction();
Exception e = assertThrows(
OpenSearchParseException.class,
() -> action.prepareRequest(getRestRequestWithBodyWithBothParams(), client)
);
assertThat(e.getMessage(), containsString(DUPLICATE_PARAMETER_ERROR_MESSAGE));
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE, "empty templates should no longer be used");
}

private MasterNodeRequest getMasterNodeRequest() {
return new MasterNodeRequest() {
@Override
Expand Down Expand Up @@ -206,4 +268,15 @@ private FakeRestRequest getRestRequestWithNewParam() {
request.params().put("cluster_manager_timeout", "2m");
return request;
}

private FakeRestRequest getRestRequestWithBodyWithBothParams() {
FakeRestRequest request = getFakeRestRequestWithBody();
request.params().put("cluster_manager_timeout", "2m");
request.params().put("master_timeout", "3s");
return request;
}

private FakeRestRequest getFakeRestRequestWithBody() {
return new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY).withContent(new BytesArray("{}"), XContentType.JSON).build();
}
}

0 comments on commit 59260e9

Please sign in to comment.