use of org.elasticsearch.threadpool.ThreadPool in project crate by crate.
the class TestingHelpers method newMockedThreadPool.
public static ThreadPool newMockedThreadPool() {
ThreadPool threadPool = Mockito.mock(ThreadPool.class);
final ExecutorService executorService = Executors.newSingleThreadExecutor();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
executorService.shutdown();
return null;
}
}).when(threadPool).shutdown();
when(threadPool.executor(anyString())).thenReturn(executorService);
try {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
executorService.awaitTermination(1, TimeUnit.SECONDS);
return null;
}
}).when(threadPool).awaitTermination(anyLong(), any(TimeUnit.class));
} catch (InterruptedException e) {
throw Throwables.propagate(e);
}
return threadPool;
}
use of org.elasticsearch.threadpool.ThreadPool in project crate by crate.
the class DecommissioningServiceTest method setUp.
@Before
public void setUp() throws Exception {
NodeSettingsService settingsService = new NodeSettingsService(Settings.EMPTY);
threadPool = mock(ThreadPool.class, Answers.RETURNS_MOCKS.get());
jobsLogs = new JobsLogs(() -> true);
sqlOperations = mock(SQLOperations.class, Answers.RETURNS_MOCKS.get());
decommissioningService = new TestableDecommissioningService(Settings.EMPTY, new NoopClusterService(), jobsLogs, threadPool, settingsService, sqlOperations, mock(TransportClusterHealthAction.class), mock(TransportClusterUpdateSettingsAction.class));
}
use of org.elasticsearch.threadpool.ThreadPool in project elasticsearch by elastic.
the class NetworkModuleTests method testOverrideDefault.
public void testOverrideDefault() {
Settings settings = Settings.builder().put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom").put(NetworkModule.HTTP_DEFAULT_TYPE_SETTING.getKey(), "default_custom").put(NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING.getKey(), "local").put(NetworkModule.TRANSPORT_TYPE_KEY, "default_custom").build();
// content doesn't matter we check reference equality
Supplier<Transport> customTransport = () -> null;
Supplier<HttpServerTransport> custom = FakeHttpTransport::new;
Supplier<HttpServerTransport> def = FakeHttpTransport::new;
NetworkModule module = newNetworkModule(settings, false, new NetworkPlugin() {
@Override
public Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NetworkService networkService) {
return Collections.singletonMap("default_custom", customTransport);
}
@Override
public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher requestDispatcher) {
Map<String, Supplier<HttpServerTransport>> supplierMap = new HashMap<>();
supplierMap.put("custom", custom);
supplierMap.put("default_custom", def);
return supplierMap;
}
});
assertSame(custom, module.getHttpServerTransportSupplier());
assertSame(customTransport, module.getTransportSupplier());
}
use of org.elasticsearch.threadpool.ThreadPool in project elasticsearch by elastic.
the class NetworkModuleTests method testRegisterTransport.
public void testRegisterTransport() {
Settings settings = Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "custom").put(NetworkModule.HTTP_ENABLED.getKey(), false).build();
// content doesn't matter we check reference equality
Supplier<Transport> custom = () -> null;
NetworkPlugin plugin = new NetworkPlugin() {
@Override
public Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NetworkService networkService) {
return Collections.singletonMap("custom", custom);
}
};
NetworkModule module = newNetworkModule(settings, false, plugin);
assertFalse(module.isTransportClient());
assertFalse(module.isHttpEnabled());
assertSame(custom, module.getTransportSupplier());
// check it works with transport only as well
module = newNetworkModule(settings, true, plugin);
assertSame(custom, module.getTransportSupplier());
assertTrue(module.isTransportClient());
assertFalse(module.isHttpEnabled());
}
use of org.elasticsearch.threadpool.ThreadPool in project elasticsearch by elastic.
the class PrioritizedExecutorsTests method testTimeoutCleanup.
public void testTimeoutCleanup() throws Exception {
ThreadPool threadPool = new TestThreadPool("test");
final ScheduledThreadPoolExecutor timer = (ScheduledThreadPoolExecutor) threadPool.scheduler();
final AtomicBoolean timeoutCalled = new AtomicBoolean();
PrioritizedEsThreadPoolExecutor executor = EsExecutors.newSinglePrioritizing(getTestName(), EsExecutors.daemonThreadFactory(getTestName()), holder);
final CountDownLatch invoked = new CountDownLatch(1);
executor.execute(new Runnable() {
@Override
public void run() {
invoked.countDown();
}
}, timer, TimeValue.timeValueHours(1), new Runnable() {
@Override
public void run() {
// We should never get here
timeoutCalled.set(true);
}
});
invoked.await();
// the timeout handler is added post execution (and quickly cancelled). We have allow for this
// and use assert busy
assertBusy(new Runnable() {
@Override
public void run() {
assertThat(timer.getQueue().size(), equalTo(0));
}
}, 5, TimeUnit.SECONDS);
assertThat(timeoutCalled.get(), equalTo(false));
assertTrue(terminate(executor));
assertTrue(terminate(threadPool));
}
Aggregations