-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Watcher: Ensure trigger service pauses execution #30363
Changes from 1 commit
2523c73
07f346b
e338444
5d01323
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,10 +43,14 @@ | |
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.xpack.core.XPackSettings; | ||
import org.elasticsearch.xpack.core.watcher.trigger.Trigger; | ||
import org.elasticsearch.xpack.core.watcher.watch.Watch; | ||
import org.elasticsearch.xpack.core.watcher.watch.WatchStatus; | ||
import org.elasticsearch.xpack.watcher.condition.InternalAlwaysCondition; | ||
import org.elasticsearch.xpack.watcher.execution.ExecutionService; | ||
import org.elasticsearch.xpack.watcher.execution.TriggeredWatchStore; | ||
import org.elasticsearch.xpack.watcher.input.none.ExecutableNoneInput; | ||
import org.elasticsearch.xpack.watcher.trigger.TriggerEngine; | ||
import org.elasticsearch.xpack.watcher.trigger.TriggerService; | ||
import org.elasticsearch.xpack.watcher.watch.WatchParser; | ||
import org.joda.time.DateTime; | ||
|
@@ -204,6 +208,36 @@ void stopExecutor() { | |
assertThat(watches, hasSize(activeWatchCount)); | ||
} | ||
|
||
public void testPausingWatcherServiceAlsoPausesTriggerService() { | ||
String engineType = "foo"; | ||
TriggerEngine triggerEngine = mock(TriggerEngine.class); | ||
when(triggerEngine.type()).thenReturn(engineType); | ||
TriggerService triggerService = new TriggerService(Settings.EMPTY, Collections.singleton(triggerEngine)); | ||
|
||
Trigger trigger = mock(Trigger.class); | ||
when(trigger.type()).thenReturn(engineType); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only a nit: It does not influence the test in any way but at first I was confused that you return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is intentional, as otherwise the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, thanks for the explanation. |
||
|
||
Watch watch = mock(Watch.class); | ||
when(watch.trigger()).thenReturn(trigger); | ||
when(watch.condition()).thenReturn(InternalAlwaysCondition.INSTANCE); | ||
ExecutableNoneInput noneInput = new ExecutableNoneInput(logger); | ||
when(watch.input()).thenReturn(noneInput); | ||
|
||
triggerService.add(watch); | ||
assertThat(triggerService.count(), is(1L)); | ||
|
||
WatcherService service = new WatcherService(Settings.EMPTY, triggerService, mock(TriggeredWatchStore.class), | ||
mock(ExecutionService.class), mock(WatchParser.class), mock(Client.class), executorService) { | ||
@Override | ||
void stopExecutor() { | ||
} | ||
}; | ||
|
||
service.pauseExecution("pausing"); | ||
assertThat(triggerService.count(), is(0L)); | ||
verify(triggerEngine).pauseExecution(); | ||
} | ||
|
||
private static DiscoveryNode newNode() { | ||
return new DiscoveryNode("node", ESTestCase.buildNewFakeTransportAddress(), Collections.emptyMap(), | ||
new HashSet<>(asList(DiscoveryNode.Role.values())), Version.CURRENT); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it maybe make sense to pause the trigger service before pausing the execution service?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. changed