|
5 | 5 | */ |
6 | 6 | package org.elasticsearch.xpack.watcher.test; |
7 | 7 |
|
| 8 | +import org.apache.logging.log4j.Logger; |
8 | 9 | import org.elasticsearch.action.admin.indices.alias.Alias; |
9 | 10 | import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; |
10 | 11 | import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse; |
|
70 | 71 | import java.util.Collections; |
71 | 72 | import java.util.HashSet; |
72 | 73 | import java.util.List; |
| 74 | +import java.util.Locale; |
73 | 75 | import java.util.Set; |
74 | 76 | import java.util.concurrent.atomic.AtomicReference; |
75 | 77 | import java.util.function.Consumer; |
76 | 78 | import java.util.stream.Collectors; |
| 79 | +import java.util.stream.StreamSupport; |
77 | 80 |
|
78 | 81 | import static org.elasticsearch.index.query.QueryBuilders.boolQuery; |
79 | 82 | import static org.elasticsearch.index.query.QueryBuilders.matchQuery; |
@@ -177,7 +180,7 @@ protected boolean timeWarped() { |
177 | 180 | public void _setup() throws Exception { |
178 | 181 | if (timeWarped()) { |
179 | 182 | timeWarp = new TimeWarp(internalCluster().getInstances(ScheduleTriggerEngineMock.class), |
180 | | - (ClockMock)getInstanceFromMaster(Clock.class)); |
| 183 | + (ClockMock)getInstanceFromMaster(Clock.class), logger); |
181 | 184 | } |
182 | 185 |
|
183 | 186 | if (internalCluster().size() > 0) { |
@@ -536,24 +539,28 @@ public EmailSent send(Email email, Authentication auth, Profile profile, String |
536 | 539 |
|
537 | 540 | protected static class TimeWarp { |
538 | 541 |
|
539 | | - protected final Iterable<ScheduleTriggerEngineMock> schedulers; |
540 | | - protected final ClockMock clock; |
| 542 | + private final List<ScheduleTriggerEngineMock> schedulers; |
| 543 | + private final ClockMock clock; |
| 544 | + private final Logger logger; |
541 | 545 |
|
542 | | - public TimeWarp(Iterable<ScheduleTriggerEngineMock> schedulers, ClockMock clock) { |
543 | | - this.schedulers = schedulers; |
| 546 | + TimeWarp(Iterable<ScheduleTriggerEngineMock> schedulers, ClockMock clock, Logger logger) { |
| 547 | + this.schedulers = StreamSupport.stream(schedulers.spliterator(), false).collect(Collectors.toList()); |
544 | 548 | this.clock = clock; |
| 549 | + this.logger = logger; |
545 | 550 | } |
546 | 551 |
|
547 | 552 | public void trigger(String jobName) { |
548 | | - schedulers.forEach(scheduler -> scheduler.trigger(jobName)); |
| 553 | + trigger(jobName, 1, null); |
549 | 554 | } |
550 | 555 |
|
551 | 556 | public ClockMock clock() { |
552 | 557 | return clock; |
553 | 558 | } |
554 | 559 |
|
555 | | - public void trigger(String id, int times, TimeValue timeValue) { |
556 | | - schedulers.forEach(scheduler -> scheduler.trigger(id, times, timeValue)); |
| 560 | + public void trigger(String watchId, int times, TimeValue timeValue) { |
| 561 | + boolean isTriggered = schedulers.stream().anyMatch(scheduler -> scheduler.trigger(watchId, times, timeValue)); |
| 562 | + String msg = String.format(Locale.ROOT, "could not find watch [%s] to trigger", watchId); |
| 563 | + assertThat(msg, isTriggered, is(true)); |
557 | 564 | } |
558 | 565 | } |
559 | 566 |
|
|
0 commit comments