test: store triggered watch events belonging to multipel watches, so that during startup the triggered watch executions can be paralyzed.

Also increased the maximum time to wait

Original commit: elastic/x-pack-elasticsearch@142ed0a810
This commit is contained in:
Martijn van Groningen 2015-07-07 12:54:13 +02:00
parent 12de46e2d4
commit 01fd8496c6
1 changed files with 16 additions and 10 deletions

View File

@ -28,6 +28,8 @@ import org.elasticsearch.watcher.watch.WatchStore;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Test; import org.junit.Test;
import java.util.concurrent.TimeUnit;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery;
@ -246,19 +248,23 @@ public class BootStrapTests extends AbstractWatcherIntegrationTests {
assertThat(response.getWatcherState(), equalTo(WatcherState.STARTED)); assertThat(response.getWatcherState(), equalTo(WatcherState.STARTED));
assertThat(response.getWatchesCount(), equalTo(0L)); assertThat(response.getWatchesCount(), equalTo(0L));
String watchId = "_id";
SearchRequest searchRequest = newInputSearchRequest("my-index").source(searchSource().query(termQuery("field", "value"))); SearchRequest searchRequest = newInputSearchRequest("my-index").source(searchSource().query(termQuery("field", "value")));
watcherClient().preparePutWatch(watchId).setSource(watchBuilder() int numWatches = 8;
.trigger(schedule(cron("0/5 * * * * ? 2050"))) for (int i = 0; i < numWatches; i++) {
.input(searchInput(searchRequest)) String watchId = "_id" + i;
.condition(alwaysCondition()) watcherClient().preparePutWatch(watchId).setSource(watchBuilder()
.addAction("_id", indexAction("output", "test")) .trigger(schedule(cron("0/5 * * * * ? 2050")))
.defaultThrottlePeriod(TimeValue.timeValueMillis(0)) .input(searchInput(searchRequest))
).get(); .condition(alwaysCondition())
.addAction("_id", indexAction("output", "test"))
.defaultThrottlePeriod(TimeValue.timeValueMillis(0))
).get();
}
DateTime now = DateTime.now(UTC); DateTime now = DateTime.now(UTC);
final int numRecords = scaledRandomIntBetween(2, 128); final int numRecords = scaledRandomIntBetween(numWatches, 128);
for (int i = 0; i < numRecords; i++) { for (int i = 0; i < numRecords; i++) {
String watchId = "_id" + (i % numWatches);
now = now.plusMinutes(1); now = now.plusMinutes(1);
ScheduleTriggerEvent event = new ScheduleTriggerEvent(watchId, now, now); ScheduleTriggerEvent event = new ScheduleTriggerEvent(watchId, now, now);
Wid wid = new Wid(watchId, randomLong(), now); Wid wid = new Wid(watchId, randomLong(), now);
@ -288,7 +294,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTests {
SearchResponse searchResponse = client().prepareSearch("output").get(); SearchResponse searchResponse = client().prepareSearch("output").get();
assertHitCount(searchResponse, numRecords); assertHitCount(searchResponse, numRecords);
} }
}); }, 30, TimeUnit.SECONDS);
} }
@Test @Test