From 7309f11f51086cff6de3b612ef1136db0ee9392c Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 17 Nov 2016 09:19:15 -0500 Subject: [PATCH] Respond to exposing of executor service This commit responds to a chance in core which modified the interface for ThreadPool#executor and ThreadPool#generic to return an executor service rather than an executor. Relates elastic/elasticsearch#4107 Original commit: elastic/x-pack-elasticsearch@7c7c6a3b90309390598e331b6b1c9d51a3d8368c --- .../xpack/watcher/WatcherLifeCycleServiceTests.java | 6 +++++- .../xpack/watcher/execution/ExecutionServiceTests.java | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleServiceTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleServiceTests.java index 0185b44a5f4..94ce3a0f6a9 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleServiceTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/WatcherLifeCycleServiceTests.java @@ -17,6 +17,7 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; @@ -25,6 +26,8 @@ import org.junit.Before; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import java.util.concurrent.ExecutorService; + import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doAnswer; @@ -42,7 +45,8 @@ public class WatcherLifeCycleServiceTests extends ESTestCase { @Before public void prepareServices() { ThreadPool threadPool = mock(ThreadPool.class); - when(threadPool.executor(anyString())).thenReturn(Runnable::run); + final ExecutorService executorService = EsExecutors.newDirectExecutorService(); + when(threadPool.executor(anyString())).thenReturn(executorService); clusterService = mock(ClusterService.class); Answer answer = new Answer() { @Override diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java index 5aa04d31a50..831d9cee8ba 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java @@ -10,6 +10,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; @@ -20,8 +21,8 @@ import org.elasticsearch.xpack.watcher.actions.ActionWrapper; import org.elasticsearch.xpack.watcher.actions.ExecutableAction; import org.elasticsearch.xpack.watcher.actions.throttler.ActionThrottler; import org.elasticsearch.xpack.watcher.actions.throttler.Throttler; -import org.elasticsearch.xpack.watcher.condition.Condition; import org.elasticsearch.xpack.watcher.condition.AlwaysCondition; +import org.elasticsearch.xpack.watcher.condition.Condition; import org.elasticsearch.xpack.watcher.condition.NeverCondition; import org.elasticsearch.xpack.watcher.history.HistoryStore; import org.elasticsearch.xpack.watcher.history.WatchRecord; @@ -45,7 +46,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; import static java.util.Collections.singletonMap; import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; @@ -780,7 +781,7 @@ public class ExecutionServiceTests extends ESTestCase { Wid wid = new Wid(watch.id(), watch.nonce(), now()); - Executor currentThreadExecutor = command -> command.run(); + final ExecutorService currentThreadExecutor = EsExecutors.newDirectExecutorService(); when(threadPool.generic()).thenReturn(currentThreadExecutor); TriggeredWatch triggeredWatch = new TriggeredWatch(wid, new ScheduleTriggerEvent(now() ,now()));