forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to verify that ExecutionContext is being populated during Re…
…stHandling Signed-off-by: Craig Perkins <[email protected]>
- Loading branch information
Showing
9 changed files
with
159 additions
and
172 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
qa/smoke-test-http/src/test/java/org/opensearch/http/ExecutionContextPluginGetIT.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,51 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.http; | ||
|
||
import org.opensearch.client.Request; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.client.ResponseException; | ||
import org.opensearch.plugins.Plugin; | ||
import org.opensearch.test.OpenSearchIntegTestCase.ClusterScope; | ||
import org.opensearch.test.OpenSearchIntegTestCase.Scope; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
/** | ||
* Test a rest action that sets special response headers | ||
*/ | ||
@ClusterScope(scope = Scope.SUITE, supportsDedicatedMasters = false, numDataNodes = 1) | ||
public class ExecutionContextPluginGetIT extends HttpSmokeTestCase { | ||
|
||
@Override | ||
protected boolean addMockHttpTransport() { | ||
return false; // enable http | ||
} | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
ArrayList<Class<? extends Plugin>> plugins = new ArrayList<>(super.nodePlugins()); | ||
plugins.add(TestExecutionContextPlugin.class); | ||
return plugins; | ||
} | ||
|
||
public void testGetExecutionContext() throws IOException { | ||
ensureGreen(); | ||
Response response = getRestClient().performRequest(new Request("GET", "/_get_execution_context")); | ||
String responseBody = new String(response.getEntity().getContent().readAllBytes(), StandardCharsets.UTF_8); | ||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); | ||
assertThat(responseBody, containsString(TestExecutionContextPlugin.class.getName())); | ||
} | ||
} |
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
72 changes: 0 additions & 72 deletions
72
qa/smoke-test-http/src/test/java/org/opensearch/http/TestExecutionContextRestAction.java
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
qa/smoke-test-http/src/test/java/org/opensearch/http/TestGetExecutionContextRestAction.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,49 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.http; | ||
|
||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.core.rest.RestStatus; | ||
import org.opensearch.rest.BaseRestHandler; | ||
import org.opensearch.rest.BytesRestResponse; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.rest.RestResponse; | ||
import org.opensearch.threadpool.ThreadPool; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.opensearch.rest.RestRequest.Method.GET; | ||
import static org.opensearch.rest.RestRequest.Method.POST; | ||
|
||
public class TestGetExecutionContextRestAction extends BaseRestHandler { | ||
|
||
private final ThreadPool threadPool; | ||
|
||
public TestGetExecutionContextRestAction(ThreadPool threadPool) { | ||
this.threadPool = threadPool; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return singletonList(new Route(GET, "/_get_execution_context")); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "test_get_execution_context_action"; | ||
} | ||
|
||
@Override | ||
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { | ||
String pluginMainClass = threadPool.getThreadContext().getExecutionContext(); | ||
RestResponse response = new BytesRestResponse(RestStatus.OK, pluginMainClass); | ||
return channel -> channel.sendResponse(response); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
qa/smoke-test-http/src/test/java/org/opensearch/http/TestSetExecutionContextRestAction.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,48 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.http; | ||
|
||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.core.rest.RestStatus; | ||
import org.opensearch.rest.BaseRestHandler; | ||
import org.opensearch.rest.BytesRestResponse; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.rest.RestResponse; | ||
import org.opensearch.threadpool.ThreadPool; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.opensearch.rest.RestRequest.Method.POST; | ||
|
||
public class TestSetExecutionContextRestAction extends BaseRestHandler { | ||
|
||
private final ThreadPool threadPool; | ||
|
||
public TestSetExecutionContextRestAction(ThreadPool threadPool) { | ||
this.threadPool = threadPool; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return singletonList(new Route(POST, "/_set_execution_context")); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "test_set_execution_context_action"; | ||
} | ||
|
||
@Override | ||
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { | ||
threadPool.getThreadContext().setExecutionContext("should-not-allow-plugin-to-set-execution-context"); | ||
RestResponse response = new BytesRestResponse(RestStatus.OK, "Should not happen"); | ||
return channel -> channel.sendResponse(response); | ||
} | ||
} |
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
49 changes: 0 additions & 49 deletions
49
server/src/main/java/org/opensearch/plugins/ActionPluginProxy.java
This file was deleted.
Oops, something went wrong.
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