Search in sources :

Example 1 with TransportAction

use of org.opensearch.action.support.TransportAction in project OpenSearch by opensearch-project.

the class RestValidateQueryActionTests method stubValidateQueryAction.

/**
 * Configures {@link NodeClient} to stub {@link ValidateQueryAction} transport action.
 * <p>
 * This lower level of validation is out of the scope of this test.
 */
@BeforeClass
public static void stubValidateQueryAction() {
    final TaskManager taskManager = new TaskManager(Settings.EMPTY, threadPool, Collections.emptySet());
    final TransportAction transportAction = new TransportAction(ValidateQueryAction.NAME, new ActionFilters(Collections.emptySet()), taskManager) {

        @Override
        protected void doExecute(Task task, ActionRequest request, ActionListener listener) {
        }
    };
    final Map<ActionType, TransportAction> actions = new HashMap<>();
    actions.put(ValidateQueryAction.INSTANCE, transportAction);
    client.initialize(actions, () -> "local", null, new NamedWriteableRegistry(Collections.emptyList()));
    controller.registerHandler(action);
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) Task(org.opensearch.tasks.Task) TaskManager(org.opensearch.tasks.TaskManager) ActionType(org.opensearch.action.ActionType) ActionListener(org.opensearch.action.ActionListener) ActionRequest(org.opensearch.action.ActionRequest) HashMap(java.util.HashMap) TransportAction(org.opensearch.action.support.TransportAction) ActionFilters(org.opensearch.action.support.ActionFilters) BeforeClass(org.junit.BeforeClass)

Example 2 with TransportAction

use of org.opensearch.action.support.TransportAction 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

ActionFilters (org.opensearch.action.support.ActionFilters)2 TransportAction (org.opensearch.action.support.TransportAction)2 Task (org.opensearch.tasks.Task)2 TaskManager (org.opensearch.tasks.TaskManager)2 HashMap (java.util.HashMap)1 BeforeClass (org.junit.BeforeClass)1 ActionListener (org.opensearch.action.ActionListener)1 ActionRequest (org.opensearch.action.ActionRequest)1 ActionType (org.opensearch.action.ActionType)1 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)1 ActionPlugin (org.opensearch.plugins.ActionPlugin)1 ActionHandler (org.opensearch.plugins.ActionPlugin.ActionHandler)1