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();
}
}
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();
}
}
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());
}
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);
}
}
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);
}
}
Aggregations