Search in sources :

Example 1 with ActionHandler

use of org.elasticsearch.plugins.ActionPlugin.ActionHandler in project elasticsearch by elastic.

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.elasticsearch.plugins.ActionPlugin) TransportMainAction(org.elasticsearch.action.main.TransportMainAction) ActionHandler(org.elasticsearch.plugins.ActionPlugin.ActionHandler) IOException(java.io.IOException)

Example 2 with ActionHandler

use of org.elasticsearch.plugins.ActionPlugin.ActionHandler in project elasticsearch by elastic.

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(Settings settings, String actionName, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, TaskManager taskManager) {
            super(settings, actionName, threadPool, actionFilters, indexNameExpressionResolver, taskManager);
        }

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

        protected FakeAction() {
            super("fake");
        }

        @Override
        public ActionResponse newResponse() {
            return 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 : ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) ActionPlugin(org.elasticsearch.plugins.ActionPlugin) ActionFilters(org.elasticsearch.action.support.ActionFilters) TransportAction(org.elasticsearch.action.support.TransportAction) TaskManager(org.elasticsearch.tasks.TaskManager) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ActionHandler(org.elasticsearch.plugins.ActionPlugin.ActionHandler) Settings(org.elasticsearch.common.settings.Settings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Aggregations

ActionPlugin (org.elasticsearch.plugins.ActionPlugin)2 ActionHandler (org.elasticsearch.plugins.ActionPlugin.ActionHandler)2 IOException (java.io.IOException)1 TransportMainAction (org.elasticsearch.action.main.TransportMainAction)1 ActionFilters (org.elasticsearch.action.support.ActionFilters)1 TransportAction (org.elasticsearch.action.support.TransportAction)1 IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)1 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)1 IndexScopedSettings (org.elasticsearch.common.settings.IndexScopedSettings)1 Settings (org.elasticsearch.common.settings.Settings)1 TaskManager (org.elasticsearch.tasks.TaskManager)1 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)1 ThreadPool (org.elasticsearch.threadpool.ThreadPool)1