Search in sources :

Example 36 with TestThreadPool

use of org.opensearch.threadpool.TestThreadPool in project OpenSearch by opensearch-project.

the class ActionModuleTests method testPluginCantOverwriteBuiltinRestHandler.

public void testPluginCantOverwriteBuiltinRestHandler() throws IOException {
    ActionPlugin dupsMainAction = new ActionPlugin() {

        @Override
        public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<DiscoveryNodes> nodesInCluster) {
            return singletonList(new RestMainAction() {

                @Override
                public String getName() {
                    return "duplicated_" + super.getName();
                }
            });
        }
    };
    SettingsModule settings = new SettingsModule(Settings.EMPTY);
    ThreadPool threadPool = new TestThreadPool(getTestName());
    try {
        UsageService usageService = new UsageService();
        ActionModule actionModule = new ActionModule(settings.getSettings(), new IndexNameExpressionResolver(threadPool.getThreadContext()), settings.getIndexScopedSettings(), settings.getClusterSettings(), settings.getSettingsFilter(), threadPool, singletonList(dupsMainAction), null, null, usageService, null);
        Exception e = expectThrows(IllegalArgumentException.class, () -> actionModule.initRestHandlers(null));
        assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/] for method: GET"));
    } finally {
        threadPool.shutdown();
    }
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) ActionPlugin(org.opensearch.plugins.ActionPlugin) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) RestController(org.opensearch.rest.RestController) TestThreadPool(org.opensearch.threadpool.TestThreadPool) IOException(java.io.IOException) SettingsFilter(org.opensearch.common.settings.SettingsFilter) RestMainAction(org.opensearch.rest.action.RestMainAction) RestHandler(org.opensearch.rest.RestHandler) UsageService(org.opensearch.usage.UsageService) SettingsModule(org.opensearch.common.settings.SettingsModule) Supplier(java.util.function.Supplier) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings)

Example 37 with TestThreadPool

use of org.opensearch.threadpool.TestThreadPool in project OpenSearch by opensearch-project.

the class ActionModuleTests method testPluginCanRegisterRestHandler.

public void testPluginCanRegisterRestHandler() {
    class FakeHandler implements RestHandler {

        @Override
        public List<Route> routes() {
            return singletonList(new Route(Method.GET, "/_dummy"));
        }

        @Override
        public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
        }
    }
    ActionPlugin registersFakeHandler = new ActionPlugin() {

        @Override
        public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<DiscoveryNodes> nodesInCluster) {
            return singletonList(new FakeHandler());
        }
    };
    SettingsModule settings = new SettingsModule(Settings.EMPTY);
    ThreadPool threadPool = new TestThreadPool(getTestName());
    try {
        UsageService usageService = new UsageService();
        ActionModule actionModule = new ActionModule(settings.getSettings(), new IndexNameExpressionResolver(threadPool.getThreadContext()), settings.getIndexScopedSettings(), settings.getClusterSettings(), settings.getSettingsFilter(), threadPool, singletonList(registersFakeHandler), null, null, usageService, null);
        actionModule.initRestHandlers(null);
        // At this point the easiest way to confirm that a handler is loaded is to try to register another one on top of it and to fail
        Exception e = expectThrows(IllegalArgumentException.class, () -> actionModule.getRestController().registerHandler(new RestHandler() {

            @Override
            public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
            }

            @Override
            public List<Route> routes() {
                return singletonList(new Route(Method.GET, "/_dummy"));
            }
        }));
        assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/_dummy] for method: GET"));
    } finally {
        threadPool.shutdown();
    }
}
Also used : NodeClient(org.opensearch.client.node.NodeClient) ClusterSettings(org.opensearch.common.settings.ClusterSettings) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) ActionPlugin(org.opensearch.plugins.ActionPlugin) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) RestChannel(org.opensearch.rest.RestChannel) RestController(org.opensearch.rest.RestController) TestThreadPool(org.opensearch.threadpool.TestThreadPool) IOException(java.io.IOException) SettingsFilter(org.opensearch.common.settings.SettingsFilter) RestRequest(org.opensearch.rest.RestRequest) RestHandler(org.opensearch.rest.RestHandler) UsageService(org.opensearch.usage.UsageService) SettingsModule(org.opensearch.common.settings.SettingsModule) Supplier(java.util.function.Supplier) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) IndexScopedSettings(org.opensearch.common.settings.IndexScopedSettings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings)

Example 38 with TestThreadPool

use of org.opensearch.threadpool.TestThreadPool in project OpenSearch by opensearch-project.

the class Netty4HttpServerPipeliningTests method setup.

@Before
public void setup() throws Exception {
    networkService = new NetworkService(Collections.emptyList());
    threadPool = new TestThreadPool("test");
    bigArrays = new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), new NoneCircuitBreakerService());
}
Also used : MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) NetworkService(org.opensearch.common.network.NetworkService) MockBigArrays(org.opensearch.common.util.MockBigArrays) TestThreadPool(org.opensearch.threadpool.TestThreadPool) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 39 with TestThreadPool

use of org.opensearch.threadpool.TestThreadPool in project OpenSearch by opensearch-project.

the class NettyTransportMultiPortTests method testThatProfileWithoutPortSettingsFails.

public void testThatProfileWithoutPortSettingsFails() throws Exception {
    Settings settings = Settings.builder().put("network.host", host).put(TransportSettings.PORT.getKey(), 0).put("transport.profiles.client1.whatever", "foo").build();
    ThreadPool threadPool = new TestThreadPool("tst");
    try {
        IllegalStateException ex = expectThrows(IllegalStateException.class, () -> startTransport(settings, threadPool));
        assertEquals("profile [client1] has no port configured", ex.getMessage());
    } finally {
        terminate(threadPool);
    }
}
Also used : ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Settings(org.opensearch.common.settings.Settings) TransportSettings(org.opensearch.transport.TransportSettings)

Example 40 with TestThreadPool

use of org.opensearch.threadpool.TestThreadPool in project OpenSearch by opensearch-project.

the class NettyTransportMultiPortTests method testThatNettyCanBindToMultiplePorts.

public void testThatNettyCanBindToMultiplePorts() throws Exception {
    Settings settings = Settings.builder().put("network.host", host).put(TransportSettings.PORT.getKey(), // will not actually bind to this
    22).put("transport.profiles.default.port", 0).put("transport.profiles.client1.port", 0).build();
    ThreadPool threadPool = new TestThreadPool("tst");
    try (TcpTransport transport = startTransport(settings, threadPool)) {
        assertEquals(1, transport.profileBoundAddresses().size());
        assertEquals(1, transport.boundAddress().boundAddresses().length);
    } finally {
        terminate(threadPool);
    }
}
Also used : ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) TcpTransport(org.opensearch.transport.TcpTransport) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Settings(org.opensearch.common.settings.Settings) TransportSettings(org.opensearch.transport.TransportSettings)

Aggregations

TestThreadPool (org.opensearch.threadpool.TestThreadPool)164 ThreadPool (org.opensearch.threadpool.ThreadPool)81 ClusterService (org.opensearch.cluster.service.ClusterService)56 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)53 CountDownLatch (java.util.concurrent.CountDownLatch)50 Before (org.junit.Before)50 Settings (org.opensearch.common.settings.Settings)43 TimeValue (org.opensearch.common.unit.TimeValue)43 SearchRequest (org.opensearch.action.search.SearchRequest)37 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)33 SubmitAsynchronousSearchRequest (org.opensearch.search.asynchronous.request.SubmitAsynchronousSearchRequest)32 AsynchronousSearchActiveStore (org.opensearch.search.asynchronous.context.active.AsynchronousSearchActiveStore)31 InternalAsynchronousSearchStats (org.opensearch.search.asynchronous.stats.InternalAsynchronousSearchStats)30 ArrayList (java.util.ArrayList)27 AsynchronousSearchContextId (org.opensearch.search.asynchronous.context.AsynchronousSearchContextId)24 AsynchronousSearchTask (org.opensearch.search.asynchronous.task.AsynchronousSearchTask)24 User (org.opensearch.commons.authuser.User)22 TimeUnit (java.util.concurrent.TimeUnit)21 AsynchronousSearchActiveContext (org.opensearch.search.asynchronous.context.active.AsynchronousSearchActiveContext)21 Collections (java.util.Collections)19