mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-27 02:18:42 +00:00
Stop exposing ExecutorService from DeterministicTaskQueue (#56001)
There are no real users of `DeterministicTaskQueue#getExecutorService()` so we can remove those public methods and expose the `ExecutorService` only through the corresponding `ThreadPool`.
This commit is contained in:
parent
c2afbf20de
commit
445cf32591
@ -199,17 +199,25 @@ public class DeterministicTaskQueue {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A <code>ExecutorService</code> that uses this task queue.
|
||||
* @return A <code>ThreadPool</code> that uses this task queue.
|
||||
*/
|
||||
public ExecutorService getExecutorService() {
|
||||
return getExecutorService(Function.identity());
|
||||
public ThreadPool getThreadPool() {
|
||||
return getThreadPool(Function.identity());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A <code>ExecutorService</code> that uses this task queue and wraps <code>Runnable</code>s in the given wrapper.
|
||||
* @return A <code>ThreadPool</code> that uses this task queue and wraps <code>Runnable</code>s in the given wrapper.
|
||||
*/
|
||||
public ExecutorService getExecutorService(Function<Runnable, Runnable> runnableWrapper) {
|
||||
return new ExecutorService() {
|
||||
public ThreadPool getThreadPool(Function<Runnable, Runnable> runnableWrapper) {
|
||||
return new ThreadPool(settings) {
|
||||
|
||||
{
|
||||
stopCachedTimeThread();
|
||||
}
|
||||
|
||||
private final Map<String, ThreadPool.Info> infos = new HashMap<>();
|
||||
|
||||
private final ExecutorService forkingExecutor = new ExecutorService() {
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
@ -242,7 +250,7 @@ public class DeterministicTaskQueue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> submit(Runnable task, T result) {
|
||||
public <T> Future<T> submit(Runnable task, T result1) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -276,27 +284,6 @@ public class DeterministicTaskQueue {
|
||||
scheduleNow(runnableWrapper.apply(command));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A <code>ThreadPool</code> that uses this task queue.
|
||||
*/
|
||||
public ThreadPool getThreadPool() {
|
||||
return getThreadPool(Function.identity());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A <code>ThreadPool</code> that uses this task queue and wraps <code>Runnable</code>s in the given wrapper.
|
||||
*/
|
||||
public ThreadPool getThreadPool(Function<Runnable, Runnable> runnableWrapper) {
|
||||
final ExecutorService forkingExecutor = getExecutorService(runnableWrapper);
|
||||
return new ThreadPool(settings) {
|
||||
|
||||
private final Map<String, ThreadPool.Info> infos = new HashMap<>();
|
||||
|
||||
{
|
||||
stopCachedTimeThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long relativeTimeInMillis() {
|
||||
|
@ -28,7 +28,6 @@ import org.elasticsearch.threadpool.ThreadPool;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@ -245,25 +244,6 @@ public class DeterministicTaskQueueTests extends ESTestCase {
|
||||
assertThat(strings, contains("foo", "bar"));
|
||||
}
|
||||
|
||||
public void testExecutorServiceEnqueuesTasks() {
|
||||
final DeterministicTaskQueue taskQueue = newTaskQueue();
|
||||
final List<String> strings = new ArrayList<>(2);
|
||||
|
||||
final ExecutorService executorService = taskQueue.getExecutorService();
|
||||
assertFalse(taskQueue.hasRunnableTasks());
|
||||
executorService.execute(() -> strings.add("foo"));
|
||||
assertTrue(taskQueue.hasRunnableTasks());
|
||||
executorService.execute(() -> strings.add("bar"));
|
||||
|
||||
assertThat(strings, empty());
|
||||
|
||||
while (taskQueue.hasRunnableTasks()) {
|
||||
taskQueue.runRandomTask();
|
||||
}
|
||||
|
||||
assertThat(strings, containsInAnyOrder("foo", "bar"));
|
||||
}
|
||||
|
||||
public void testThreadPoolEnqueuesTasks() {
|
||||
final DeterministicTaskQueue taskQueue = newTaskQueue();
|
||||
final List<String> strings = new ArrayList<>(2);
|
||||
@ -297,20 +277,6 @@ public class DeterministicTaskQueueTests extends ESTestCase {
|
||||
assertTrue(called.get());
|
||||
}
|
||||
|
||||
public void testExecutorServiceWrapsRunnable() {
|
||||
final DeterministicTaskQueue taskQueue = newTaskQueue();
|
||||
final AtomicBoolean called = new AtomicBoolean();
|
||||
final ExecutorService executorService = taskQueue.getExecutorService(runnable -> () -> {
|
||||
assertFalse(called.get());
|
||||
called.set(true);
|
||||
runnable.run();
|
||||
});
|
||||
executorService.execute(() -> logger.info("runnable executed"));
|
||||
assertFalse(called.get());
|
||||
taskQueue.runAllRunnableTasks();
|
||||
assertTrue(called.get());
|
||||
}
|
||||
|
||||
public void testThreadPoolSchedulesFutureTasks() {
|
||||
final DeterministicTaskQueue taskQueue = newTaskQueue();
|
||||
advanceToRandomTime(taskQueue);
|
||||
|
Loading…
x
Reference in New Issue
Block a user