Search in sources :

Example 1 with ActionHandler

use of org.opensearch.plugins.ActionPlugin.ActionHandler in project OpenSearch by opensearch-project.

the class ActionModuleTests method testPluginCantOverwriteBuiltinAction.

public void testPluginCantOverwriteBuiltinAction() {
    ActionPlugin dupsMainAction = new ActionPlugin() {

        @Override
        public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
            return singletonList(new ActionHandler<>(MainAction.INSTANCE, TransportMainAction.class));
        }
    };
    Exception e = expectThrows(IllegalArgumentException.class, () -> ActionModule.setupActions(singletonList(dupsMainAction)));
    assertEquals("action for name [" + MainAction.NAME + "] already registered", e.getMessage());
}
Also used : ActionPlugin(org.opensearch.plugins.ActionPlugin) TransportMainAction(org.opensearch.action.main.TransportMainAction) ActionHandler(org.opensearch.plugins.ActionPlugin.ActionHandler) IOException(java.io.IOException)

Example 2 with ActionHandler

use of org.opensearch.plugins.ActionPlugin.ActionHandler in project OpenSearch by opensearch-project.

the class ActionModuleTests method testPluginCanRegisterAction.

public void testPluginCanRegisterAction() {
    class FakeRequest extends ActionRequest {

        @Override
        public ActionRequestValidationException validate() {
            return null;
        }
    }
    class FakeTransportAction extends TransportAction<FakeRequest, ActionResponse> {

        protected FakeTransportAction(String actionName, ActionFilters actionFilters, TaskManager taskManager) {
            super(actionName, actionFilters, taskManager);
        }

        @Override
        protected void doExecute(Task task, FakeRequest request, ActionListener<ActionResponse> listener) {
        }
    }
    class FakeAction extends ActionType<ActionResponse> {

        protected FakeAction() {
            super("fake", null);
        }
    }
    FakeAction action = new FakeAction();
    ActionPlugin registersFakeAction = new ActionPlugin() {

        @Override
        public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
            return singletonList(new ActionHandler<>(action, FakeTransportAction.class));
        }
    };
    assertThat(ActionModule.setupActions(singletonList(registersFakeAction)), hasEntry("fake", new ActionHandler<>(action, FakeTransportAction.class)));
}
Also used : Task(org.opensearch.tasks.Task) ActionPlugin(org.opensearch.plugins.ActionPlugin) ActionFilters(org.opensearch.action.support.ActionFilters) TransportAction(org.opensearch.action.support.TransportAction) TaskManager(org.opensearch.tasks.TaskManager) ActionHandler(org.opensearch.plugins.ActionPlugin.ActionHandler)

Aggregations

ActionPlugin (org.opensearch.plugins.ActionPlugin)2 ActionHandler (org.opensearch.plugins.ActionPlugin.ActionHandler)2 IOException (java.io.IOException)1 TransportMainAction (org.opensearch.action.main.TransportMainAction)1 ActionFilters (org.opensearch.action.support.ActionFilters)1 TransportAction (org.opensearch.action.support.TransportAction)1 Task (org.opensearch.tasks.Task)1 TaskManager (org.opensearch.tasks.TaskManager)1