Fix line length for aliases and remove suppression (#37455)

Relates #34884
This commit is contained in:
Dimitrios Liappis 2019-01-16 13:06:29 +02:00 committed by GitHub
parent 6d99e790b3
commit 347cbaf0ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 23 deletions

View File

@ -46,10 +46,6 @@
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]client[/\\]documentation[/\\]WatcherDocumentationIT.java" id="SnippetLength" />
<suppress files="modules[/\\]reindex[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]client[/\\]documentation[/\\]ReindexDocumentationIT.java" id="SnippetLength" />
<!-- Hopefully temporary suppression of LineLength on files that don't pass it. We should remove these when we the
files start to pass. -->
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]aliases[/\\]IndexAliasesIT.java" checks="LineLength" />
<!-- Gradle requires inputs to be seriablizable -->
<suppress files="buildSrc[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]gradle[/\\]precommit[/\\]TestingConventionRule.java" checks="RegexpSinglelineJava" />
</suppressions>

View File

@ -187,7 +187,8 @@ public class IndexAliasesIT extends ESIntegTestCase {
logger.info("--> making sure that filter was stored with alias [alias1] and filter [user:kimchy]");
ClusterState clusterState = admin().cluster().prepareState().get().getState();
IndexMetaData indexMd = clusterState.metaData().index("test");
assertThat(indexMd.getAliases().get("alias1").filter().string(), equalTo("{\"term\":{\"user\":{\"value\":\"kimchy\",\"boost\":1.0}}}"));
assertThat(indexMd.getAliases().get("alias1").filter().string(),
equalTo("{\"term\":{\"user\":{\"value\":\"kimchy\",\"boost\":1.0}}}"));
}
@ -321,32 +322,38 @@ public class IndexAliasesIT extends ESIntegTestCase {
logger.info("--> checking filtering alias for two indices");
SearchResponse searchResponse = client().prepareSearch("foos").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "5");
assertThat(client().prepareSearch("foos").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("foos")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(2L));
logger.info("--> checking filtering alias for one index");
searchResponse = client().prepareSearch("bars").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "2");
assertThat(client().prepareSearch("bars").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("bars")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(1L));
logger.info("--> checking filtering alias for two indices and one complete index");
searchResponse = client().prepareSearch("foos", "test1").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "2", "3", "4", "5");
assertThat(client().prepareSearch("foos", "test1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L));
assertThat(client().prepareSearch("foos", "test1")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L));
logger.info("--> checking filtering alias for two indices and non-filtering alias for one index");
searchResponse = client().prepareSearch("foos", "aliasToTest1").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "1", "2", "3", "4", "5");
assertThat(client().prepareSearch("foos", "aliasToTest1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L));
assertThat(client().prepareSearch("foos", "aliasToTest1")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L));
logger.info("--> checking filtering alias for two indices and non-filtering alias for both indices");
searchResponse = client().prepareSearch("foos", "aliasToTests").setQuery(QueryBuilders.matchAllQuery()).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(8L));
assertThat(client().prepareSearch("foos", "aliasToTests").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(8L));
assertThat(client().prepareSearch("foos", "aliasToTests")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(8L));
logger.info("--> checking filtering alias for two indices and non-filtering alias for both indices");
searchResponse = client().prepareSearch("foos", "aliasToTests").setQuery(QueryBuilders.termQuery("name", "something")).get();
assertHits(searchResponse.getHits(), "4", "8");
assertThat(client().prepareSearch("foos", "aliasToTests").setSize(0).setQuery(QueryBuilders.termQuery("name", "something")).get().getHits().getTotalHits().value, equalTo(2L));
assertThat(client().prepareSearch("foos", "aliasToTests")
.setSize(0).setQuery(QueryBuilders.termQuery("name", "something")).get().getHits().getTotalHits().value, equalTo(2L));
}
public void testSearchingFilteringAliasesMultipleIndices() throws Exception {
@ -390,27 +397,33 @@ public class IndexAliasesIT extends ESIntegTestCase {
logger.info("--> checking filtering alias for multiple indices");
SearchResponse searchResponse = client().prepareSearch("filter23", "filter13").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "21", "31", "13", "33");
assertThat(client().prepareSearch("filter23", "filter13").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(4L));
assertThat(client().prepareSearch("filter23", "filter13")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(4L));
searchResponse = client().prepareSearch("filter23", "filter1").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "21", "31", "11", "12", "13");
assertThat(client().prepareSearch("filter23", "filter1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L));
assertThat(client().prepareSearch("filter23", "filter1")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(5L));
searchResponse = client().prepareSearch("filter13", "filter1").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "11", "12", "13", "33");
assertThat(client().prepareSearch("filter13", "filter1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(4L));
assertThat(client().prepareSearch("filter13", "filter1")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(4L));
searchResponse = client().prepareSearch("filter13", "filter1", "filter23").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "11", "12", "13", "21", "31", "33");
assertThat(client().prepareSearch("filter13", "filter1", "filter23").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(6L));
assertThat(client().prepareSearch("filter13", "filter1", "filter23")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(6L));
searchResponse = client().prepareSearch("filter23", "filter13", "test2").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "21", "22", "23", "31", "13", "33");
assertThat(client().prepareSearch("filter23", "filter13", "test2").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(6L));
assertThat(client().prepareSearch("filter23", "filter13", "test2")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(6L));
searchResponse = client().prepareSearch("filter23", "filter13", "test1", "test2").setQuery(QueryBuilders.matchAllQuery()).get();
assertHits(searchResponse.getHits(), "11", "12", "13", "21", "22", "23", "31", "33");
assertThat(client().prepareSearch("filter23", "filter13", "test1", "test2").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(8L));
assertThat(client().prepareSearch("filter23", "filter13", "test1", "test2")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(8L));
}
public void testDeletingByQueryFilteringAliases() throws Exception {
@ -447,7 +460,8 @@ public class IndexAliasesIT extends ESIntegTestCase {
refresh();
logger.info("--> checking counts before delete");
assertThat(client().prepareSearch("bars").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(1L));
assertThat(client().prepareSearch("bars")
.setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().getTotalHits().value, equalTo(1L));
}
public void testDeleteAliases() throws Exception {
@ -511,13 +525,17 @@ public class IndexAliasesIT extends ESIntegTestCase {
public void testWaitForAliasCreationSingleShard() throws Exception {
logger.info("--> creating index [test]");
assertAcked(admin().indices().create(createIndexRequest("test").settings(Settings.builder().put("index.number_of_replicas", 0).put("index.number_of_shards", 1))).get());
assertAcked(admin().indices().create(createIndexRequest("test").settings(Settings.builder()
.put("index.number_of_replicas", 0)
.put("index.number_of_shards", 1)))
.get());
ensureGreen();
for (int i = 0; i < 10; i++) {
assertAcked(admin().indices().prepareAliases().addAlias("test", "alias" + i));
client().index(indexRequest("alias" + i).type("type1").id("1").source(source("1", "test"), XContentType.JSON)).get();
client().index(indexRequest("alias" + i).type("type1").id("1").source(source("1", "test"),
XContentType.JSON)).get();
}
}
@ -579,7 +597,8 @@ public class IndexAliasesIT extends ESIntegTestCase {
assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));
logger.info("--> verify that filter was updated");
AliasMetaData aliasMetaData = ((AliasOrIndex.Alias) internalCluster().clusterService().state().metaData().getAliasAndIndexLookup().get("alias1")).getFirstAliasMetaData();
AliasMetaData aliasMetaData = ((AliasOrIndex.Alias) internalCluster()
.clusterService().state().metaData().getAliasAndIndexLookup().get("alias1")).getFirstAliasMetaData();
assertThat(aliasMetaData.getFilter().toString(), equalTo("{\"term\":{\"name\":{\"value\":\"bar\",\"boost\":1.0}}}"));
logger.info("--> deleting alias1");
@ -905,8 +924,10 @@ public class IndexAliasesIT extends ESIntegTestCase {
public void testAliasFilterWithNowInRangeFilterAndQuery() throws Exception {
assertAcked(prepareCreate("my-index").addMapping("my-type", "timestamp", "type=date"));
assertAcked(admin().indices().prepareAliases().addAlias("my-index", "filter1", rangeQuery("timestamp").from("2016-12-01").to("2016-12-31")));
assertAcked(admin().indices().prepareAliases().addAlias("my-index", "filter2", rangeQuery("timestamp").from("2016-01-01").to("2016-12-31")));
assertAcked(admin().indices().prepareAliases()
.addAlias("my-index", "filter1", rangeQuery("timestamp").from("2016-12-01").to("2016-12-31")));
assertAcked(admin().indices().prepareAliases()
.addAlias("my-index", "filter2", rangeQuery("timestamp").from("2016-01-01").to("2016-12-31")));
final int numDocs = scaledRandomIntBetween(5, 52);
for (int i = 1; i <= numDocs; i++) {