|
43 | 43 | import org.elasticsearch.test.ESTestCase;
|
44 | 44 | import org.elasticsearch.threadpool.ThreadPool;
|
45 | 45 | import org.elasticsearch.xpack.core.XPackSettings;
|
| 46 | +import org.elasticsearch.xpack.core.watcher.trigger.Trigger; |
46 | 47 | import org.elasticsearch.xpack.core.watcher.watch.Watch;
|
47 | 48 | import org.elasticsearch.xpack.core.watcher.watch.WatchStatus;
|
| 49 | +import org.elasticsearch.xpack.watcher.condition.InternalAlwaysCondition; |
48 | 50 | import org.elasticsearch.xpack.watcher.execution.ExecutionService;
|
49 | 51 | import org.elasticsearch.xpack.watcher.execution.TriggeredWatchStore;
|
| 52 | +import org.elasticsearch.xpack.watcher.input.none.ExecutableNoneInput; |
| 53 | +import org.elasticsearch.xpack.watcher.trigger.TriggerEngine; |
50 | 54 | import org.elasticsearch.xpack.watcher.trigger.TriggerService;
|
51 | 55 | import org.elasticsearch.xpack.watcher.watch.WatchParser;
|
52 | 56 | import org.joda.time.DateTime;
|
@@ -204,6 +208,36 @@ void stopExecutor() {
|
204 | 208 | assertThat(watches, hasSize(activeWatchCount));
|
205 | 209 | }
|
206 | 210 |
|
| 211 | + public void testPausingWatcherServiceAlsoPausesTriggerService() { |
| 212 | + String engineType = "foo"; |
| 213 | + TriggerEngine triggerEngine = mock(TriggerEngine.class); |
| 214 | + when(triggerEngine.type()).thenReturn(engineType); |
| 215 | + TriggerService triggerService = new TriggerService(Settings.EMPTY, Collections.singleton(triggerEngine)); |
| 216 | + |
| 217 | + Trigger trigger = mock(Trigger.class); |
| 218 | + when(trigger.type()).thenReturn(engineType); |
| 219 | + |
| 220 | + Watch watch = mock(Watch.class); |
| 221 | + when(watch.trigger()).thenReturn(trigger); |
| 222 | + when(watch.condition()).thenReturn(InternalAlwaysCondition.INSTANCE); |
| 223 | + ExecutableNoneInput noneInput = new ExecutableNoneInput(logger); |
| 224 | + when(watch.input()).thenReturn(noneInput); |
| 225 | + |
| 226 | + triggerService.add(watch); |
| 227 | + assertThat(triggerService.count(), is(1L)); |
| 228 | + |
| 229 | + WatcherService service = new WatcherService(Settings.EMPTY, triggerService, mock(TriggeredWatchStore.class), |
| 230 | + mock(ExecutionService.class), mock(WatchParser.class), mock(Client.class), executorService) { |
| 231 | + @Override |
| 232 | + void stopExecutor() { |
| 233 | + } |
| 234 | + }; |
| 235 | + |
| 236 | + service.pauseExecution("pausing"); |
| 237 | + assertThat(triggerService.count(), is(0L)); |
| 238 | + verify(triggerEngine).pauseExecution(); |
| 239 | + } |
| 240 | + |
207 | 241 | private static DiscoveryNode newNode() {
|
208 | 242 | return new DiscoveryNode("node", ESTestCase.buildNewFakeTransportAddress(), Collections.emptyMap(),
|
209 | 243 | new HashSet<>(asList(DiscoveryNode.Role.values())), Version.CURRENT);
|
|
0 commit comments