-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Previously, Watcher only attached its listener to indices that started with the prefix `.watches`, which causes Watcher to silently fail to schedule newly created Watches if the `.watches` alias is redirected to an index that does not start with `.watches`. Watcher now attaches the listener to all indices, so that Watcher can respond to changes in which index has the `.watches` alias. Also adjusts the tests to randomly use non-prefixed concrete indices for .watches and .triggered_watches.
- Loading branch information
Showing
3 changed files
with
111 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherConcreteIndexTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.watcher; | ||
|
||
import org.elasticsearch.action.search.SearchResponse; | ||
import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; | ||
import org.elasticsearch.xpack.core.watcher.watch.Watch; | ||
import org.elasticsearch.xpack.watcher.condition.InternalAlwaysCondition; | ||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; | ||
|
||
import java.util.Locale; | ||
|
||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction; | ||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder; | ||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.noneInput; | ||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule; | ||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
|
||
public class WatcherConcreteIndexTests extends AbstractWatcherIntegrationTestCase { | ||
|
||
@Override | ||
protected boolean timeWarped() { | ||
return false; | ||
} | ||
|
||
public void testCanUseAnyConcreteIndexName() throws Exception { | ||
String newWatcherIndexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); | ||
String watchResultsIndex = randomAlphaOfLength(11).toLowerCase(Locale.ROOT); | ||
createIndex(watchResultsIndex); | ||
|
||
stopWatcher(); | ||
replaceWatcherIndexWithRandomlyNamedIndex(Watch.INDEX, newWatcherIndexName, Watch.DOC_TYPE); | ||
startWatcher(); | ||
|
||
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("mywatch").setSource(watchBuilder() | ||
.trigger(schedule(interval("3s"))) | ||
.input(noneInput()) | ||
.condition(InternalAlwaysCondition.INSTANCE) | ||
.addAction("indexer", indexAction(watchResultsIndex, "_doc"))) | ||
.get(); | ||
|
||
assertTrue(putWatchResponse.isCreated()); | ||
|
||
assertBusy(() -> { | ||
SearchResponse searchResult = client().prepareSearch(watchResultsIndex).setTrackTotalHits(true).get(); | ||
assertThat((int) searchResult.getHits().getTotalHits().value, greaterThan(0)); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters